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