Gilles Peskine | 5794836 | 2021-02-13 00:14:28 +0100 | [diff] [blame] | 1 | /** Helper functions for tests that manipulate ASN.1 data. |
| 2 | */ |
| 3 | /* |
| 4 | * Copyright The Mbed TLS Contributors |
Dave Rodgman | 16799db | 2023-11-02 19:47:20 +0000 | [diff] [blame] | 5 | * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later |
Gilles Peskine | 5794836 | 2021-02-13 00:14:28 +0100 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #ifndef ASN1_HELPERS_H |
| 9 | #define ASN1_HELPERS_H |
| 10 | |
| 11 | #include "test/helpers.h" |
| 12 | |
Gilles Peskine | 8e94efe | 2021-02-13 00:25:53 +0100 | [diff] [blame] | 13 | /** 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 Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 34 | int 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 Peskine | 5794836 | 2021-02-13 00:14:28 +0100 | [diff] [blame] | 37 | |
| 38 | #endif /* ASN1_HELPERS_H */ |