mps_error.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /*
  2. * Copyright The Mbed TLS Contributors
  3. * SPDX-License-Identifier: Apache-2.0
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License"); you may
  6. * not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  13. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. *
  17. * This file is part of mbed TLS (https://tls.mbed.org)
  18. */
  19. /**
  20. * \file mps_error.h
  21. *
  22. * \brief Error codes used by MPS
  23. */
  24. #ifndef MBEDTLS_MPS_ERROR_H
  25. #define MBEDTLS_MPS_ERROR_H
  26. /* TODO: The error code allocation needs to be revisited:
  27. *
  28. * - Should we make (some of) the MPS Reader error codes public?
  29. * If so, we need to adjust MBEDTLS_MPS_READER_MAKE_ERROR() to hit
  30. * a gap in the Mbed TLS public error space.
  31. * If not, we have to make sure we don't forward those errors
  32. * at the level of the public API -- no risk at the moment as
  33. * long as MPS is an experimental component not accessible from
  34. * public API.
  35. */
  36. /**
  37. * \name SECTION: MPS general error codes
  38. *
  39. * \{
  40. */
  41. #ifndef MBEDTLS_MPS_ERR_BASE
  42. #define MBEDTLS_MPS_ERR_BASE ( 0 )
  43. #endif
  44. #define MBEDTLS_MPS_MAKE_ERROR(code) \
  45. ( -( MBEDTLS_MPS_ERR_BASE | (code) ) )
  46. #define MBEDTLS_ERR_MPS_OPERATION_UNEXPECTED MBEDTLS_MPS_MAKE_ERROR( 0x1 )
  47. #define MBEDTLS_ERR_MPS_INTERNAL_ERROR MBEDTLS_MPS_MAKE_ERROR( 0x2 )
  48. /* \} name SECTION: MPS general error codes */
  49. /**
  50. * \name SECTION: MPS Reader error codes
  51. *
  52. * \{
  53. */
  54. #ifndef MBEDTLS_MPS_READER_ERR_BASE
  55. #define MBEDTLS_MPS_READER_ERR_BASE ( 1 << 8 )
  56. #endif
  57. #define MBEDTLS_MPS_READER_MAKE_ERROR(code) \
  58. ( -( MBEDTLS_MPS_READER_ERR_BASE | (code) ) )
  59. /*! An attempt to reclaim the data buffer from a reader failed because
  60. * the user hasn't yet read and committed all of it. */
  61. #define MBEDTLS_ERR_MPS_READER_DATA_LEFT MBEDTLS_MPS_READER_MAKE_ERROR( 0x1 )
  62. /*! An invalid argument was passed to the reader. */
  63. #define MBEDTLS_ERR_MPS_READER_INVALID_ARG MBEDTLS_MPS_READER_MAKE_ERROR( 0x2 )
  64. /*! An attempt to move a reader to consuming mode through mbedtls_mps_reader_feed()
  65. * after pausing failed because the provided data is not sufficient to serve the
  66. * read requests that led to the pausing. */
  67. #define MBEDTLS_ERR_MPS_READER_NEED_MORE MBEDTLS_MPS_READER_MAKE_ERROR( 0x3 )
  68. /*! A get request failed because not enough data is available in the reader. */
  69. #define MBEDTLS_ERR_MPS_READER_OUT_OF_DATA MBEDTLS_MPS_READER_MAKE_ERROR( 0x4 )
  70. /*!< A get request after pausing and reactivating the reader failed because
  71. * the request is not in line with the request made prior to pausing. The user
  72. * must not change it's 'strategy' after pausing and reactivating a reader. */
  73. #define MBEDTLS_ERR_MPS_READER_INCONSISTENT_REQUESTS MBEDTLS_MPS_READER_MAKE_ERROR( 0x5 )
  74. /*! An attempt to reclaim the data buffer from a reader failed because the reader
  75. * has no accumulator it can use to backup the data that hasn't been processed. */
  76. #define MBEDTLS_ERR_MPS_READER_NEED_ACCUMULATOR MBEDTLS_MPS_READER_MAKE_ERROR( 0x6 )
  77. /*! An attempt to reclaim the data buffer from a reader failed because the
  78. * accumulator passed to the reader is not large enough to hold both the
  79. * data that hasn't been processed and the excess of the last read-request. */
  80. #define MBEDTLS_ERR_MPS_READER_ACCUMULATOR_TOO_SMALL MBEDTLS_MPS_READER_MAKE_ERROR( 0x7 )
  81. /* \} name SECTION: MPS Reader error codes */
  82. #endif /* MBEDTLS_MPS_ERROR_H */