blob: 016a84ce49e02be109444d7f0628160fc4472989 [file] [log] [blame]
Hanno Becker447e8a52021-01-12 07:27:12 +00001/*
2 * Copyright The Mbed TLS Contributors
Dave Rodgman16799db2023-11-02 19:47:20 +00003 * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
Hanno Becker447e8a52021-01-12 07:27:12 +00004 */
5
6/**
Hanno Becker61d7eed2021-03-05 05:09:37 +00007 * \file mps_error.h
Hanno Becker447e8a52021-01-12 07:27:12 +00008 *
9 * \brief Error codes used by MPS
10 */
11
12#ifndef MBEDTLS_MPS_ERROR_H
13#define MBEDTLS_MPS_ERROR_H
14
15
16/* TODO: The error code allocation needs to be revisited:
17 *
18 * - Should we make (some of) the MPS Reader error codes public?
Hanno Becker984fbde2021-01-28 09:02:18 +000019 * If so, we need to adjust MBEDTLS_MPS_READER_MAKE_ERROR() to hit
Hanno Becker447e8a52021-01-12 07:27:12 +000020 * a gap in the Mbed TLS public error space.
21 * If not, we have to make sure we don't forward those errors
22 * at the level of the public API -- no risk at the moment as
23 * long as MPS is an experimental component not accessible from
24 * public API.
25 */
26
Hanno Becker447e8a52021-01-12 07:27:12 +000027/**
Hanno Beckerac267f32021-01-12 07:25:41 +000028 * \name SECTION: MPS general error codes
29 *
30 * \{
31 */
32
33#ifndef MBEDTLS_MPS_ERR_BASE
Gilles Peskine449bd832023-01-11 14:50:10 +010034#define MBEDTLS_MPS_ERR_BASE (0)
Hanno Beckerac267f32021-01-12 07:25:41 +000035#endif
36
37#define MBEDTLS_MPS_MAKE_ERROR(code) \
Gilles Peskine449bd832023-01-11 14:50:10 +010038 (-(MBEDTLS_MPS_ERR_BASE | (code)))
Hanno Beckerac267f32021-01-12 07:25:41 +000039
Gilles Peskine449bd832023-01-11 14:50:10 +010040#define MBEDTLS_ERR_MPS_OPERATION_UNEXPECTED MBEDTLS_MPS_MAKE_ERROR(0x1)
41#define MBEDTLS_ERR_MPS_INTERNAL_ERROR MBEDTLS_MPS_MAKE_ERROR(0x2)
Hanno Beckerac267f32021-01-12 07:25:41 +000042
43/* \} name SECTION: MPS general error codes */
44
45/**
Hanno Becker447e8a52021-01-12 07:27:12 +000046 * \name SECTION: MPS Reader error codes
47 *
48 * \{
49 */
50
51#ifndef MBEDTLS_MPS_READER_ERR_BASE
Gilles Peskine449bd832023-01-11 14:50:10 +010052#define MBEDTLS_MPS_READER_ERR_BASE (1 << 8)
Hanno Becker447e8a52021-01-12 07:27:12 +000053#endif
54
55#define MBEDTLS_MPS_READER_MAKE_ERROR(code) \
Gilles Peskine449bd832023-01-11 14:50:10 +010056 (-(MBEDTLS_MPS_READER_ERR_BASE | (code)))
Hanno Becker447e8a52021-01-12 07:27:12 +000057
58/*! An attempt to reclaim the data buffer from a reader failed because
59 * the user hasn't yet read and committed all of it. */
Gilles Peskine449bd832023-01-11 14:50:10 +010060#define MBEDTLS_ERR_MPS_READER_DATA_LEFT MBEDTLS_MPS_READER_MAKE_ERROR(0x1)
Hanno Becker447e8a52021-01-12 07:27:12 +000061
62/*! An invalid argument was passed to the reader. */
Gilles Peskine449bd832023-01-11 14:50:10 +010063#define MBEDTLS_ERR_MPS_READER_INVALID_ARG MBEDTLS_MPS_READER_MAKE_ERROR(0x2)
Hanno Becker447e8a52021-01-12 07:27:12 +000064
Hanno Becker88993962021-01-28 09:45:47 +000065/*! An attempt to move a reader to consuming mode through mbedtls_mps_reader_feed()
Hanno Becker447e8a52021-01-12 07:27:12 +000066 * after pausing failed because the provided data is not sufficient to serve the
Hanno Beckerf1cfa312021-02-22 15:15:44 +000067 * read requests that led to the pausing. */
Gilles Peskine449bd832023-01-11 14:50:10 +010068#define MBEDTLS_ERR_MPS_READER_NEED_MORE MBEDTLS_MPS_READER_MAKE_ERROR(0x3)
Hanno Becker447e8a52021-01-12 07:27:12 +000069
Hanno Beckerf1cfa312021-02-22 15:15:44 +000070/*! A get request failed because not enough data is available in the reader. */
Gilles Peskine449bd832023-01-11 14:50:10 +010071#define MBEDTLS_ERR_MPS_READER_OUT_OF_DATA MBEDTLS_MPS_READER_MAKE_ERROR(0x4)
Hanno Becker447e8a52021-01-12 07:27:12 +000072
Hanno Beckerf1cfa312021-02-22 15:15:44 +000073/*!< A get request after pausing and reactivating the reader failed because
Hanno Becker447e8a52021-01-12 07:27:12 +000074 * the request is not in line with the request made prior to pausing. The user
75 * must not change it's 'strategy' after pausing and reactivating a reader. */
Gilles Peskine449bd832023-01-11 14:50:10 +010076#define MBEDTLS_ERR_MPS_READER_INCONSISTENT_REQUESTS MBEDTLS_MPS_READER_MAKE_ERROR(0x5)
Hanno Becker447e8a52021-01-12 07:27:12 +000077
Hanno Beckerf1cfa312021-02-22 15:15:44 +000078/*! An attempt to reclaim the data buffer from a reader failed because the reader
Hanno Becker447e8a52021-01-12 07:27:12 +000079 * has no accumulator it can use to backup the data that hasn't been processed. */
Gilles Peskine449bd832023-01-11 14:50:10 +010080#define MBEDTLS_ERR_MPS_READER_NEED_ACCUMULATOR MBEDTLS_MPS_READER_MAKE_ERROR(0x6)
Hanno Becker447e8a52021-01-12 07:27:12 +000081
Hanno Beckerf1cfa312021-02-22 15:15:44 +000082/*! An attempt to reclaim the data buffer from a reader failed because the
Hanno Becker447e8a52021-01-12 07:27:12 +000083 * accumulator passed to the reader is not large enough to hold both the
84 * data that hasn't been processed and the excess of the last read-request. */
Gilles Peskine449bd832023-01-11 14:50:10 +010085#define MBEDTLS_ERR_MPS_READER_ACCUMULATOR_TOO_SMALL MBEDTLS_MPS_READER_MAKE_ERROR(0x7)
Hanno Becker447e8a52021-01-12 07:27:12 +000086
87/* \} name SECTION: MPS Reader error codes */
88
89#endif /* MBEDTLS_MPS_ERROR_H */