mps_error.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /*
  2. * Copyright The Mbed TLS Contributors
  3. * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
  4. */
  5. /**
  6. * \file mps_error.h
  7. *
  8. * \brief Error codes used by MPS
  9. */
  10. #ifndef MBEDTLS_MPS_ERROR_H
  11. #define MBEDTLS_MPS_ERROR_H
  12. /* TODO: The error code allocation needs to be revisited:
  13. *
  14. * - Should we make (some of) the MPS Reader error codes public?
  15. * If so, we need to adjust MBEDTLS_MPS_READER_MAKE_ERROR() to hit
  16. * a gap in the Mbed TLS public error space.
  17. * If not, we have to make sure we don't forward those errors
  18. * at the level of the public API -- no risk at the moment as
  19. * long as MPS is an experimental component not accessible from
  20. * public API.
  21. */
  22. /**
  23. * \name SECTION: MPS general error codes
  24. *
  25. * \{
  26. */
  27. #ifndef MBEDTLS_MPS_ERR_BASE
  28. #define MBEDTLS_MPS_ERR_BASE (0)
  29. #endif
  30. #define MBEDTLS_MPS_MAKE_ERROR(code) \
  31. (-(MBEDTLS_MPS_ERR_BASE | (code)))
  32. #define MBEDTLS_ERR_MPS_OPERATION_UNEXPECTED MBEDTLS_MPS_MAKE_ERROR(0x1)
  33. #define MBEDTLS_ERR_MPS_INTERNAL_ERROR MBEDTLS_MPS_MAKE_ERROR(0x2)
  34. /* \} name SECTION: MPS general error codes */
  35. /**
  36. * \name SECTION: MPS Reader error codes
  37. *
  38. * \{
  39. */
  40. #ifndef MBEDTLS_MPS_READER_ERR_BASE
  41. #define MBEDTLS_MPS_READER_ERR_BASE (1 << 8)
  42. #endif
  43. #define MBEDTLS_MPS_READER_MAKE_ERROR(code) \
  44. (-(MBEDTLS_MPS_READER_ERR_BASE | (code)))
  45. /*! An attempt to reclaim the data buffer from a reader failed because
  46. * the user hasn't yet read and committed all of it. */
  47. #define MBEDTLS_ERR_MPS_READER_DATA_LEFT MBEDTLS_MPS_READER_MAKE_ERROR(0x1)
  48. /*! An invalid argument was passed to the reader. */
  49. #define MBEDTLS_ERR_MPS_READER_INVALID_ARG MBEDTLS_MPS_READER_MAKE_ERROR(0x2)
  50. /*! An attempt to move a reader to consuming mode through mbedtls_mps_reader_feed()
  51. * after pausing failed because the provided data is not sufficient to serve the
  52. * read requests that led to the pausing. */
  53. #define MBEDTLS_ERR_MPS_READER_NEED_MORE MBEDTLS_MPS_READER_MAKE_ERROR(0x3)
  54. /*! A get request failed because not enough data is available in the reader. */
  55. #define MBEDTLS_ERR_MPS_READER_OUT_OF_DATA MBEDTLS_MPS_READER_MAKE_ERROR(0x4)
  56. /*!< A get request after pausing and reactivating the reader failed because
  57. * the request is not in line with the request made prior to pausing. The user
  58. * must not change it's 'strategy' after pausing and reactivating a reader. */
  59. #define MBEDTLS_ERR_MPS_READER_INCONSISTENT_REQUESTS MBEDTLS_MPS_READER_MAKE_ERROR(0x5)
  60. /*! An attempt to reclaim the data buffer from a reader failed because the reader
  61. * has no accumulator it can use to backup the data that hasn't been processed. */
  62. #define MBEDTLS_ERR_MPS_READER_NEED_ACCUMULATOR MBEDTLS_MPS_READER_MAKE_ERROR(0x6)
  63. /*! An attempt to reclaim the data buffer from a reader failed because the
  64. * accumulator passed to the reader is not large enough to hold both the
  65. * data that hasn't been processed and the excess of the last read-request. */
  66. #define MBEDTLS_ERR_MPS_READER_ACCUMULATOR_TOO_SMALL MBEDTLS_MPS_READER_MAKE_ERROR(0x7)
  67. /* \} name SECTION: MPS Reader error codes */
  68. #endif /* MBEDTLS_MPS_ERROR_H */