blob: 6622078b0baa267fa77723a7bd81c2166ae4c3c5 [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/**
Hanno Becker61d7eed2021-03-05 05:09:37 +000021 * \file mps_error.h
Hanno Becker447e8a52021-01-12 07:27:12 +000022 *
23 * \brief Error codes used by MPS
24 */
25
26#ifndef MBEDTLS_MPS_ERROR_H
27#define MBEDTLS_MPS_ERROR_H
28
Hanno Becker447e8a52021-01-12 07:27:12 +000029/* TODO: The error code allocation needs to be revisited:
30 *
31 * - Should we make (some of) the MPS Reader error codes public?
Hanno Becker984fbde2021-01-28 09:02:18 +000032 * If so, we need to adjust MBEDTLS_MPS_READER_MAKE_ERROR() to hit
Hanno Becker447e8a52021-01-12 07:27:12 +000033 * a gap in the Mbed TLS public error space.
34 * If not, we have to make sure we don't forward those errors
35 * at the level of the public API -- no risk at the moment as
36 * long as MPS is an experimental component not accessible from
37 * public API.
38 */
39
Hanno Becker447e8a52021-01-12 07:27:12 +000040/**
Hanno Beckerac267f32021-01-12 07:25:41 +000041 * \name SECTION: MPS general error codes
42 *
43 * \{
44 */
45
46#ifndef MBEDTLS_MPS_ERR_BASE
Mateusz Starzykc0eabdc2021-08-03 14:09:02 +020047# define MBEDTLS_MPS_ERR_BASE (0)
Hanno Beckerac267f32021-01-12 07:25:41 +000048#endif
49
Mateusz Starzykc0eabdc2021-08-03 14:09:02 +020050#define MBEDTLS_MPS_MAKE_ERROR(code) (-(MBEDTLS_MPS_ERR_BASE | (code)))
Hanno Beckerac267f32021-01-12 07:25:41 +000051
Mateusz Starzykc0eabdc2021-08-03 14:09:02 +020052#define MBEDTLS_ERR_MPS_OPERATION_UNEXPECTED MBEDTLS_MPS_MAKE_ERROR(0x1)
53#define MBEDTLS_ERR_MPS_INTERNAL_ERROR MBEDTLS_MPS_MAKE_ERROR(0x2)
Hanno Beckerac267f32021-01-12 07:25:41 +000054
55/* \} name SECTION: MPS general error codes */
56
57/**
Hanno Becker447e8a52021-01-12 07:27:12 +000058 * \name SECTION: MPS Reader error codes
59 *
60 * \{
61 */
62
63#ifndef MBEDTLS_MPS_READER_ERR_BASE
Mateusz Starzykc0eabdc2021-08-03 14:09:02 +020064# define MBEDTLS_MPS_READER_ERR_BASE (1 << 8)
Hanno Becker447e8a52021-01-12 07:27:12 +000065#endif
66
67#define MBEDTLS_MPS_READER_MAKE_ERROR(code) \
Mateusz Starzykc0eabdc2021-08-03 14:09:02 +020068 (-(MBEDTLS_MPS_READER_ERR_BASE | (code)))
Hanno Becker447e8a52021-01-12 07:27:12 +000069
70/*! An attempt to reclaim the data buffer from a reader failed because
71 * the user hasn't yet read and committed all of it. */
Mateusz Starzykc0eabdc2021-08-03 14:09:02 +020072#define MBEDTLS_ERR_MPS_READER_DATA_LEFT MBEDTLS_MPS_READER_MAKE_ERROR(0x1)
Hanno Becker447e8a52021-01-12 07:27:12 +000073
74/*! An invalid argument was passed to the reader. */
Mateusz Starzykc0eabdc2021-08-03 14:09:02 +020075#define MBEDTLS_ERR_MPS_READER_INVALID_ARG MBEDTLS_MPS_READER_MAKE_ERROR(0x2)
Hanno Becker447e8a52021-01-12 07:27:12 +000076
Mateusz Starzykc0eabdc2021-08-03 14:09:02 +020077/*! An attempt to move a reader to consuming mode through
78 * mbedtls_mps_reader_feed() after pausing failed because the provided data is
79 * not sufficient to serve the read requests that led to the pausing. */
80#define MBEDTLS_ERR_MPS_READER_NEED_MORE MBEDTLS_MPS_READER_MAKE_ERROR(0x3)
Hanno Becker447e8a52021-01-12 07:27:12 +000081
Hanno Beckerf1cfa312021-02-22 15:15:44 +000082/*! A get request failed because not enough data is available in the reader. */
Mateusz Starzykc0eabdc2021-08-03 14:09:02 +020083#define MBEDTLS_ERR_MPS_READER_OUT_OF_DATA MBEDTLS_MPS_READER_MAKE_ERROR(0x4)
Hanno Becker447e8a52021-01-12 07:27:12 +000084
Hanno Beckerf1cfa312021-02-22 15:15:44 +000085/*!< A get request after pausing and reactivating the reader failed because
Hanno Becker447e8a52021-01-12 07:27:12 +000086 * the request is not in line with the request made prior to pausing. The user
87 * must not change it's 'strategy' after pausing and reactivating a reader. */
Mateusz Starzykc0eabdc2021-08-03 14:09:02 +020088#define MBEDTLS_ERR_MPS_READER_INCONSISTENT_REQUESTS \
89 MBEDTLS_MPS_READER_MAKE_ERROR(0x5)
Hanno Becker447e8a52021-01-12 07:27:12 +000090
Mateusz Starzykc0eabdc2021-08-03 14:09:02 +020091/*! An attempt to reclaim the data buffer from a reader failed because the
92 * reader has no accumulator it can use to backup the data that hasn't been
93 * processed. */
94#define MBEDTLS_ERR_MPS_READER_NEED_ACCUMULATOR \
95 MBEDTLS_MPS_READER_MAKE_ERROR(0x6)
Hanno Becker447e8a52021-01-12 07:27:12 +000096
Hanno Beckerf1cfa312021-02-22 15:15:44 +000097/*! An attempt to reclaim the data buffer from a reader failed because the
Hanno Becker447e8a52021-01-12 07:27:12 +000098 * accumulator passed to the reader is not large enough to hold both the
99 * data that hasn't been processed and the excess of the last read-request. */
Mateusz Starzykc0eabdc2021-08-03 14:09:02 +0200100#define MBEDTLS_ERR_MPS_READER_ACCUMULATOR_TOO_SMALL \
101 MBEDTLS_MPS_READER_MAKE_ERROR(0x7)
Hanno Becker447e8a52021-01-12 07:27:12 +0000102
103/* \} name SECTION: MPS Reader error codes */
104
105#endif /* MBEDTLS_MPS_ERROR_H */