1 /** Helper functions for tests that manipulate ASN.1 data.
2  */
3 /*
4  *  Copyright The Mbed TLS Contributors
5  *  SPDX-License-Identifier: Apache-2.0
6  *
7  *  Licensed under the Apache License, Version 2.0 (the "License"); you may
8  *  not use this file except in compliance with the License.
9  *  You may obtain a copy of the License at
10  *
11  *  http://www.apache.org/licenses/LICENSE-2.0
12  *
13  *  Unless required by applicable law or agreed to in writing, software
14  *  distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
15  *  WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  *  See the License for the specific language governing permissions and
17  *  limitations under the License.
18  */
19 
20 #ifndef ASN1_HELPERS_H
21 #define ASN1_HELPERS_H
22 
23 #include "test/helpers.h"
24 
25 /** Skip past an INTEGER in an ASN.1 buffer.
26  *
27  * Mark the current test case as failed in any of the following conditions:
28  * - The buffer does not start with an ASN.1 INTEGER.
29  * - The integer's size or parity does not match the constraints expressed
30  *   through \p min_bits, \p max_bits and \p must_be_odd.
31  *
32  * \param p             Upon entry, `*p` points to the first byte of the
33  *                      buffer to parse.
34  *                      On successful return, `*p` points to the first byte
35  *                      after the parsed INTEGER.
36  *                      On failure, `*p` is unspecified.
37  * \param end           The end of the ASN.1 buffer.
38  * \param min_bits      Fail the test case if the integer does not have at
39  *                      least this many significant bits.
40  * \param max_bits      Fail the test case if the integer has more than
41  *                      this many significant bits.
42  * \param must_be_odd   Fail the test case if the integer is even.
43  *
44  * \return              \c 0 if the test failed, otherwise 1.
45  */
46 int mbedtls_test_asn1_skip_integer(unsigned char **p, const unsigned char *end,
47                                    size_t min_bits, size_t max_bits,
48                                    int must_be_odd);
49 
50 #endif /* ASN1_HELPERS_H */
51