Hanno Becker | 447e8a5 | 2021-01-12 07:27:12 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright The Mbed TLS Contributors |
Dave Rodgman | 16799db | 2023-11-02 19:47:20 +0000 | [diff] [blame^] | 3 | * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later |
Hanno Becker | 447e8a5 | 2021-01-12 07:27:12 +0000 | [diff] [blame] | 4 | * |
Gilles Peskine | e820c0a | 2023-08-03 17:45:20 +0200 | [diff] [blame] | 5 | * This file is part of Mbed TLS (https://tls.mbed.org) |
Hanno Becker | 447e8a5 | 2021-01-12 07:27:12 +0000 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | /** |
Hanno Becker | 61d7eed | 2021-03-05 05:09:37 +0000 | [diff] [blame] | 9 | * \file mps_error.h |
Hanno Becker | 447e8a5 | 2021-01-12 07:27:12 +0000 | [diff] [blame] | 10 | * |
| 11 | * \brief Error codes used by MPS |
| 12 | */ |
| 13 | |
| 14 | #ifndef MBEDTLS_MPS_ERROR_H |
| 15 | #define MBEDTLS_MPS_ERROR_H |
| 16 | |
| 17 | |
| 18 | /* TODO: The error code allocation needs to be revisited: |
| 19 | * |
| 20 | * - Should we make (some of) the MPS Reader error codes public? |
Hanno Becker | 984fbde | 2021-01-28 09:02:18 +0000 | [diff] [blame] | 21 | * If so, we need to adjust MBEDTLS_MPS_READER_MAKE_ERROR() to hit |
Hanno Becker | 447e8a5 | 2021-01-12 07:27:12 +0000 | [diff] [blame] | 22 | * a gap in the Mbed TLS public error space. |
| 23 | * If not, we have to make sure we don't forward those errors |
| 24 | * at the level of the public API -- no risk at the moment as |
| 25 | * long as MPS is an experimental component not accessible from |
| 26 | * public API. |
| 27 | */ |
| 28 | |
Hanno Becker | 447e8a5 | 2021-01-12 07:27:12 +0000 | [diff] [blame] | 29 | /** |
Hanno Becker | ac267f3 | 2021-01-12 07:25:41 +0000 | [diff] [blame] | 30 | * \name SECTION: MPS general error codes |
| 31 | * |
| 32 | * \{ |
| 33 | */ |
| 34 | |
| 35 | #ifndef MBEDTLS_MPS_ERR_BASE |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 36 | #define MBEDTLS_MPS_ERR_BASE (0) |
Hanno Becker | ac267f3 | 2021-01-12 07:25:41 +0000 | [diff] [blame] | 37 | #endif |
| 38 | |
| 39 | #define MBEDTLS_MPS_MAKE_ERROR(code) \ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 40 | (-(MBEDTLS_MPS_ERR_BASE | (code))) |
Hanno Becker | ac267f3 | 2021-01-12 07:25:41 +0000 | [diff] [blame] | 41 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 42 | #define MBEDTLS_ERR_MPS_OPERATION_UNEXPECTED MBEDTLS_MPS_MAKE_ERROR(0x1) |
| 43 | #define MBEDTLS_ERR_MPS_INTERNAL_ERROR MBEDTLS_MPS_MAKE_ERROR(0x2) |
Hanno Becker | ac267f3 | 2021-01-12 07:25:41 +0000 | [diff] [blame] | 44 | |
| 45 | /* \} name SECTION: MPS general error codes */ |
| 46 | |
| 47 | /** |
Hanno Becker | 447e8a5 | 2021-01-12 07:27:12 +0000 | [diff] [blame] | 48 | * \name SECTION: MPS Reader error codes |
| 49 | * |
| 50 | * \{ |
| 51 | */ |
| 52 | |
| 53 | #ifndef MBEDTLS_MPS_READER_ERR_BASE |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 54 | #define MBEDTLS_MPS_READER_ERR_BASE (1 << 8) |
Hanno Becker | 447e8a5 | 2021-01-12 07:27:12 +0000 | [diff] [blame] | 55 | #endif |
| 56 | |
| 57 | #define MBEDTLS_MPS_READER_MAKE_ERROR(code) \ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 58 | (-(MBEDTLS_MPS_READER_ERR_BASE | (code))) |
Hanno Becker | 447e8a5 | 2021-01-12 07:27:12 +0000 | [diff] [blame] | 59 | |
| 60 | /*! An attempt to reclaim the data buffer from a reader failed because |
| 61 | * the user hasn't yet read and committed all of it. */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 62 | #define MBEDTLS_ERR_MPS_READER_DATA_LEFT MBEDTLS_MPS_READER_MAKE_ERROR(0x1) |
Hanno Becker | 447e8a5 | 2021-01-12 07:27:12 +0000 | [diff] [blame] | 63 | |
| 64 | /*! An invalid argument was passed to the reader. */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 65 | #define MBEDTLS_ERR_MPS_READER_INVALID_ARG MBEDTLS_MPS_READER_MAKE_ERROR(0x2) |
Hanno Becker | 447e8a5 | 2021-01-12 07:27:12 +0000 | [diff] [blame] | 66 | |
Hanno Becker | 8899396 | 2021-01-28 09:45:47 +0000 | [diff] [blame] | 67 | /*! An attempt to move a reader to consuming mode through mbedtls_mps_reader_feed() |
Hanno Becker | 447e8a5 | 2021-01-12 07:27:12 +0000 | [diff] [blame] | 68 | * after pausing failed because the provided data is not sufficient to serve the |
Hanno Becker | f1cfa31 | 2021-02-22 15:15:44 +0000 | [diff] [blame] | 69 | * read requests that led to the pausing. */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 70 | #define MBEDTLS_ERR_MPS_READER_NEED_MORE MBEDTLS_MPS_READER_MAKE_ERROR(0x3) |
Hanno Becker | 447e8a5 | 2021-01-12 07:27:12 +0000 | [diff] [blame] | 71 | |
Hanno Becker | f1cfa31 | 2021-02-22 15:15:44 +0000 | [diff] [blame] | 72 | /*! A get request failed because not enough data is available in the reader. */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 73 | #define MBEDTLS_ERR_MPS_READER_OUT_OF_DATA MBEDTLS_MPS_READER_MAKE_ERROR(0x4) |
Hanno Becker | 447e8a5 | 2021-01-12 07:27:12 +0000 | [diff] [blame] | 74 | |
Hanno Becker | f1cfa31 | 2021-02-22 15:15:44 +0000 | [diff] [blame] | 75 | /*!< A get request after pausing and reactivating the reader failed because |
Hanno Becker | 447e8a5 | 2021-01-12 07:27:12 +0000 | [diff] [blame] | 76 | * the request is not in line with the request made prior to pausing. The user |
| 77 | * must not change it's 'strategy' after pausing and reactivating a reader. */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 78 | #define MBEDTLS_ERR_MPS_READER_INCONSISTENT_REQUESTS MBEDTLS_MPS_READER_MAKE_ERROR(0x5) |
Hanno Becker | 447e8a5 | 2021-01-12 07:27:12 +0000 | [diff] [blame] | 79 | |
Hanno Becker | f1cfa31 | 2021-02-22 15:15:44 +0000 | [diff] [blame] | 80 | /*! An attempt to reclaim the data buffer from a reader failed because the reader |
Hanno Becker | 447e8a5 | 2021-01-12 07:27:12 +0000 | [diff] [blame] | 81 | * has no accumulator it can use to backup the data that hasn't been processed. */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 82 | #define MBEDTLS_ERR_MPS_READER_NEED_ACCUMULATOR MBEDTLS_MPS_READER_MAKE_ERROR(0x6) |
Hanno Becker | 447e8a5 | 2021-01-12 07:27:12 +0000 | [diff] [blame] | 83 | |
Hanno Becker | f1cfa31 | 2021-02-22 15:15:44 +0000 | [diff] [blame] | 84 | /*! An attempt to reclaim the data buffer from a reader failed because the |
Hanno Becker | 447e8a5 | 2021-01-12 07:27:12 +0000 | [diff] [blame] | 85 | * accumulator passed to the reader is not large enough to hold both the |
| 86 | * data that hasn't been processed and the excess of the last read-request. */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 87 | #define MBEDTLS_ERR_MPS_READER_ACCUMULATOR_TOO_SMALL MBEDTLS_MPS_READER_MAKE_ERROR(0x7) |
Hanno Becker | 447e8a5 | 2021-01-12 07:27:12 +0000 | [diff] [blame] | 88 | |
| 89 | /* \} name SECTION: MPS Reader error codes */ |
| 90 | |
| 91 | #endif /* MBEDTLS_MPS_ERROR_H */ |