blob: 2eb91712820c16338f41afdd1aadaacc5e765b70 [file] [log] [blame]
Gilles Peskine57948362021-02-13 00:14:28 +01001/** Helper functions for tests that manipulate ASN.1 data.
2 */
3/*
4 * Copyright The Mbed TLS Contributors
Dave Rodgman16799db2023-11-02 19:47:20 +00005 * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
Gilles Peskine57948362021-02-13 00:14:28 +01006 */
7
8#ifndef ASN1_HELPERS_H
9#define ASN1_HELPERS_H
10
11#include "test/helpers.h"
12
Gilles Peskine8e94efe2021-02-13 00:25:53 +010013/** Skip past an INTEGER in an ASN.1 buffer.
14 *
15 * Mark the current test case as failed in any of the following conditions:
16 * - The buffer does not start with an ASN.1 INTEGER.
17 * - The integer's size or parity does not match the constraints expressed
18 * through \p min_bits, \p max_bits and \p must_be_odd.
19 *
20 * \param p Upon entry, `*p` points to the first byte of the
21 * buffer to parse.
22 * On successful return, `*p` points to the first byte
23 * after the parsed INTEGER.
24 * On failure, `*p` is unspecified.
25 * \param end The end of the ASN.1 buffer.
26 * \param min_bits Fail the test case if the integer does not have at
27 * least this many significant bits.
28 * \param max_bits Fail the test case if the integer has more than
29 * this many significant bits.
30 * \param must_be_odd Fail the test case if the integer is even.
31 *
32 * \return \c 0 if the test failed, otherwise 1.
33 */
Gilles Peskine449bd832023-01-11 14:50:10 +010034int mbedtls_test_asn1_skip_integer(unsigned char **p, const unsigned char *end,
35 size_t min_bits, size_t max_bits,
36 int must_be_odd);
Gilles Peskine57948362021-02-13 00:14:28 +010037
38#endif /* ASN1_HELPERS_H */