asn1_helpers.h 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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. #ifndef ASN1_HELPERS_H
  20. #define ASN1_HELPERS_H
  21. #include "test/helpers.h"
  22. /** Skip past an INTEGER in an ASN.1 buffer.
  23. *
  24. * Mark the current test case as failed in any of the following conditions:
  25. * - The buffer does not start with an ASN.1 INTEGER.
  26. * - The integer's size or parity does not match the constraints expressed
  27. * through \p min_bits, \p max_bits and \p must_be_odd.
  28. *
  29. * \param p Upon entry, `*p` points to the first byte of the
  30. * buffer to parse.
  31. * On successful return, `*p` points to the first byte
  32. * after the parsed INTEGER.
  33. * On failure, `*p` is unspecified.
  34. * \param end The end of the ASN.1 buffer.
  35. * \param min_bits Fail the test case if the integer does not have at
  36. * least this many significant bits.
  37. * \param max_bits Fail the test case if the integer has more than
  38. * this many significant bits.
  39. * \param must_be_odd Fail the test case if the integer is even.
  40. *
  41. * \return \c 0 if the test failed, otherwise 1.
  42. */
  43. int mbedtls_test_asn1_skip_integer( unsigned char **p, const unsigned char *end,
  44. size_t min_bits, size_t max_bits,
  45. int must_be_odd );
  46. #endif /* ASN1_HELPERS_H */