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