blob: 807a72afed927ff31f0d052e950a491f9f62a7f4 [file] [log] [blame]
Hanno Becker447e8a52021-01-12 07:27:12 +00001/*
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/**
21 * \file error.h
22 *
23 * \brief Error codes used by MPS
24 */
25
26#ifndef MBEDTLS_MPS_ERROR_H
27#define MBEDTLS_MPS_ERROR_H
28
29
30/* TODO: The error code allocation needs to be revisited:
31 *
32 * - Should we make (some of) the MPS Reader error codes public?
Hanno Becker984fbde2021-01-28 09:02:18 +000033 * If so, we need to adjust MBEDTLS_MPS_READER_MAKE_ERROR() to hit
Hanno Becker447e8a52021-01-12 07:27:12 +000034 * a gap in the Mbed TLS public error space.
35 * If not, we have to make sure we don't forward those errors
36 * at the level of the public API -- no risk at the moment as
37 * long as MPS is an experimental component not accessible from
38 * public API.
39 */
40
41#ifndef MBEDTLS_MPS_ERR_BASE
42#define MBEDTLS_MPS_ERR_BASE ( 1 << 0 )
43#endif
44
45/**
Hanno Beckerac267f32021-01-12 07:25:41 +000046 * \name SECTION: MPS general error codes
47 *
48 * \{
49 */
50
51#ifndef MBEDTLS_MPS_ERR_BASE
52#define MBEDTLS_MPS_ERR_BASE ( 1 << 10 )
53#endif
54
55#define MBEDTLS_MPS_MAKE_ERROR(code) \
56 ( -( MBEDTLS_MPS_ERR_BASE | (code) ) )
57
58
59#define MBEDTLS_ERR_MPS_OPERATION_UNEXPECTED MBEDTLS_MPS_MAKE_ERROR( 0x1 )
Hanno Becker984fbde2021-01-28 09:02:18 +000060#define MBEDTLS_ERR_MPS_INTERNAL_ERROR MBEDTLS_MPS_MAKE_ERROR( 0x2 )
Hanno Beckerac267f32021-01-12 07:25:41 +000061
62/* \} name SECTION: MPS general error codes */
63
64/**
Hanno Becker447e8a52021-01-12 07:27:12 +000065 * \name SECTION: MPS Reader error codes
66 *
67 * \{
68 */
69
70#ifndef MBEDTLS_MPS_READER_ERR_BASE
71#define MBEDTLS_MPS_READER_ERR_BASE ( 1 << 7 )
72#endif
73
74#define MBEDTLS_MPS_READER_MAKE_ERROR(code) \
75 ( -( MBEDTLS_MPS_READER_ERR_BASE | (code) ) )
76
77/*! An attempt to reclaim the data buffer from a reader failed because
78 * the user hasn't yet read and committed all of it. */
79#define MBEDTLS_ERR_MPS_READER_DATA_LEFT MBEDTLS_MPS_READER_MAKE_ERROR( 0x1 )
80
81/*! An invalid argument was passed to the reader. */
82#define MBEDTLS_ERR_MPS_READER_INVALID_ARG MBEDTLS_MPS_READER_MAKE_ERROR( 0x2 )
83
Hanno Becker88993962021-01-28 09:45:47 +000084/*! An attempt to move a reader to consuming mode through mbedtls_mps_reader_feed()
Hanno Becker447e8a52021-01-12 07:27:12 +000085 * after pausing failed because the provided data is not sufficient to serve the
86 * the read requests that lead to the pausing. */
87#define MBEDTLS_ERR_MPS_READER_NEED_MORE MBEDTLS_MPS_READER_MAKE_ERROR( 0x3 )
88
89/*! A read request failed because not enough data is available in the reader. */
90#define MBEDTLS_ERR_MPS_READER_OUT_OF_DATA MBEDTLS_MPS_READER_MAKE_ERROR( 0x4 )
91
92/*!< A read request after pausing and reactivating the reader failed because
93 * the request is not in line with the request made prior to pausing. The user
94 * must not change it's 'strategy' after pausing and reactivating a reader. */
95#define MBEDTLS_ERR_MPS_READER_INCONSISTENT_REQUESTS MBEDTLS_MPS_READER_MAKE_ERROR( 0x5 )
96
97/*! An attempt to reclaim the data buffer from a reader fails because the reader
98 * has no accumulator it can use to backup the data that hasn't been processed. */
99#define MBEDTLS_ERR_MPS_READER_NEED_ACCUMULATOR MBEDTLS_MPS_READER_MAKE_ERROR( 0x6 )
100
101/*! An attempt to reclaim the data buffer from a reader fails beacuse the
102 * accumulator passed to the reader is not large enough to hold both the
103 * data that hasn't been processed and the excess of the last read-request. */
104#define MBEDTLS_ERR_MPS_READER_ACCUMULATOR_TOO_SMALL MBEDTLS_MPS_READER_MAKE_ERROR( 0x7 )
105
106/* \} name SECTION: MPS Reader error codes */
107
108#endif /* MBEDTLS_MPS_ERROR_H */