|
| 1 | +/* |
| 2 | + * Copyright (c) 2023 Nordic Semiconductor ASA |
| 3 | + * |
| 4 | + * SPDX-License-Identifier: LicenseRef-Nordic-5-Clause |
| 5 | + */ |
| 6 | + |
| 7 | +/** This file describes the PSA Internal Trusted Storage API |
| 8 | + */ |
| 9 | + |
| 10 | +#ifndef PSA_INTERNAL_TRUSTED_STORAGE_H |
| 11 | +#define PSA_INTERNAL_TRUSTED_STORAGE_H |
| 12 | + |
| 13 | +#include <stddef.h> |
| 14 | +#include <stdint.h> |
| 15 | + |
| 16 | +#include "psa/error.h" |
| 17 | +#include "psa/storage_common.h" |
| 18 | + |
| 19 | +#ifdef __cplusplus |
| 20 | +extern "C" { |
| 21 | +#endif |
| 22 | + |
| 23 | +/** |
| 24 | + * @defgroup internal_trusted_storage PSA Internal Trusted Storage |
| 25 | + * @{ |
| 26 | + */ |
| 27 | + |
| 28 | + |
| 29 | +#define PSA_ITS_API_VERSION_MAJOR \ |
| 30 | + 1 /* The major version number of the \ |
| 31 | + * PSA ITS API \ |
| 32 | + */ |
| 33 | +#define PSA_ITS_API_VERSION_MINOR \ |
| 34 | + 0 /* The minor version number of the \ |
| 35 | + * PSA ITS API \ |
| 36 | + */ |
| 37 | +/* This version of the header file is associated with 1.0 final release. */ |
| 38 | + |
| 39 | +/** |
| 40 | + * \brief Create a new, or modify an existing, uid/value pair |
| 41 | + * |
| 42 | + * Stores data in the internal storage. |
| 43 | + * |
| 44 | + * \param[in] uid The identifier for the data |
| 45 | + * \param[in] data_length The size in bytes of the data in `p_data` |
| 46 | + * \param[in] p_data A buffer containing the data |
| 47 | + * \param[in] create_flags The flags that the data will be stored with |
| 48 | + * |
| 49 | + * \return A status indicating the success/failure of the operation |
| 50 | + * |
| 51 | + * \retval PSA_SUCCESS The operation completed successfully |
| 52 | + * \retval PSA_ERROR_NOT_PERMITTED The operation failed because the |
| 53 | + * provided `uid` value was already |
| 54 | + * created with |
| 55 | + * PSA_STORAGE_FLAG_WRITE_ONCE |
| 56 | + * \retval PSA_ERROR_NOT_SUPPORTED The operation failed because one or |
| 57 | + * more of the flags provided in |
| 58 | + * `create_flags` is not supported or is |
| 59 | + * not valid |
| 60 | + * \retval PSA_ERROR_INSUFFICIENT_STORAGE The operation failed because there |
| 61 | + * was insufficient space on the |
| 62 | + * storage medium |
| 63 | + * \retval PSA_ERROR_STORAGE_FAILURE The operation failed because the |
| 64 | + * physical storage has failed (Fatal |
| 65 | + * error) |
| 66 | + * \retval PSA_ERROR_INVALID_ARGUMENT The operation failed because one |
| 67 | + * of the provided pointers(`p_data`) |
| 68 | + * is invalid, for example is `NULL` or |
| 69 | + * references memory the caller cannot |
| 70 | + * access |
| 71 | + */ |
| 72 | +psa_status_t psa_its_set(psa_storage_uid_t uid, size_t data_length, const void *p_data, |
| 73 | + psa_storage_create_flags_t create_flags); |
| 74 | + |
| 75 | +/** |
| 76 | + * \brief Retrieve data associated with a provided UID |
| 77 | + * |
| 78 | + * Retrieves up to `data_size` bytes of the data associated with `uid`, starting |
| 79 | + * at `data_offset` bytes from the beginning of the data. Upon successful |
| 80 | + * completion, the data will be placed in the `p_data` buffer, which must be at |
| 81 | + * least `data_size` bytes in size. The length of the data returned will be in |
| 82 | + * `p_data_length`. If `data_size` is 0, the contents of `p_data_length` will |
| 83 | + * be set to zero. |
| 84 | + * |
| 85 | + * \param[in] uid The uid value |
| 86 | + * \param[in] data_offset The starting offset of the data requested |
| 87 | + * \param[in] data_size The amount of data requested |
| 88 | + * \param[out] p_data On success, the buffer where the data will |
| 89 | + * be placed |
| 90 | + * \param[out] p_data_length On success, this will contain size of the data |
| 91 | + * placed in `p_data` |
| 92 | + * |
| 93 | + * \return A status indicating the success/failure of the operation |
| 94 | + * |
| 95 | + * \retval PSA_SUCCESS The operation completed successfully |
| 96 | + * \retval PSA_ERROR_DOES_NOT_EXIST The operation failed because the |
| 97 | + * provided `uid` value was not found in |
| 98 | + * the storage |
| 99 | + * \retval PSA_ERROR_STORAGE_FAILURE The operation failed because the |
| 100 | + * physical storage has failed (Fatal |
| 101 | + * error) |
| 102 | + * \retval PSA_ERROR_INVALID_ARGUMENT The operation failed because one of the |
| 103 | + * provided arguments (`p_data`, |
| 104 | + * `p_data_length`) is invalid, for example |
| 105 | + * is `NULL` or references memory the |
| 106 | + * caller cannot access. In addition, this |
| 107 | + * can also happen if `data_offset` is |
| 108 | + * larger than the size of the data |
| 109 | + * associated with `uid` |
| 110 | + */ |
| 111 | +psa_status_t psa_its_get(psa_storage_uid_t uid, size_t data_offset, size_t data_size, void *p_data, |
| 112 | + size_t *p_data_length); |
| 113 | + |
| 114 | +/** |
| 115 | + * \brief Retrieve the metadata about the provided uid |
| 116 | + * |
| 117 | + * Retrieves the metadata stored for a given `uid` as a `psa_storage_info_t` |
| 118 | + * structure. |
| 119 | + * |
| 120 | + * \param[in] uid The `uid` value |
| 121 | + * \param[out] p_info A pointer to the `psa_storage_info_t` struct that will |
| 122 | + * be populated with the metadata |
| 123 | + * |
| 124 | + * \return A status indicating the success/failure of the operation |
| 125 | + * |
| 126 | + * \retval PSA_SUCCESS The operation completed successfully |
| 127 | + * \retval PSA_ERROR_DOES_NOT_EXIST The operation failed because the provided |
| 128 | + * uid value was not found in the storage |
| 129 | + * \retval PSA_ERROR_STORAGE_FAILURE The operation failed because the physical |
| 130 | + * storage has failed (Fatal error) |
| 131 | + * \retval PSA_ERROR_INVALID_ARGUMENT The operation failed because one of the |
| 132 | + * provided pointers(`p_info`) |
| 133 | + * is invalid, for example is `NULL` or |
| 134 | + * references memory the caller cannot |
| 135 | + * access |
| 136 | + */ |
| 137 | +psa_status_t psa_its_get_info(psa_storage_uid_t uid, struct psa_storage_info_t *p_info); |
| 138 | + |
| 139 | +/** |
| 140 | + * \brief Remove the provided uid and its associated data from the storage |
| 141 | + * |
| 142 | + * Deletes the data from internal storage. |
| 143 | + * |
| 144 | + * \param[in] uid The `uid` value |
| 145 | + * |
| 146 | + * \return A status indicating the success/failure of the operation |
| 147 | + * |
| 148 | + * \retval PSA_SUCCESS The operation completed successfully |
| 149 | + * \retval PSA_ERROR_INVALID_ARGUMENT The operation failed because one or more |
| 150 | + * of the given arguments were invalid (null |
| 151 | + * pointer, wrong flags and so on) |
| 152 | + * \retval PSA_ERROR_DOES_NOT_EXIST The operation failed because the provided |
| 153 | + * uid value was not found in the storage |
| 154 | + * \retval PSA_ERROR_NOT_PERMITTED The operation failed because the provided |
| 155 | + * uid value was created with |
| 156 | + * PSA_STORAGE_FLAG_WRITE_ONCE |
| 157 | + * \retval PSA_ERROR_STORAGE_FAILURE The operation failed because the physical |
| 158 | + * storage has failed (Fatal error) |
| 159 | + */ |
| 160 | +psa_status_t psa_its_remove(psa_storage_uid_t uid); |
| 161 | + |
| 162 | +/** @} */ |
| 163 | + |
| 164 | + |
| 165 | +#ifdef __cplusplus |
| 166 | +} |
| 167 | +#endif |
| 168 | + |
| 169 | +#endif /* PSA_INTERNAL_TRUSTED_STORAGE_H */ |
0 commit comments