1 /*
2  * Copyright (c) 2018-2022, Arm Limited. All rights reserved.
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  *
6  */
7 
8 #ifndef __PS_OBJECT_DEFS_H__
9 #define __PS_OBJECT_DEFS_H__
10 
11 #include <stdint.h>
12 
13 #include "config_ps.h"
14 #include "psa/protected_storage.h"
15 
16 #ifdef PS_ENCRYPTION
17 #include "crypto/ps_crypto_interface.h"
18 #endif
19 
20 /*!
21  * \struct ps_object_info_t
22  *
23  * \brief Object information.
24  */
25 struct ps_object_info_t {
26     uint32_t current_size; /*!< Current size of the object content in bytes */
27     uint32_t max_size;     /*!< Maximum size of the object content in bytes */
28     psa_storage_create_flags_t create_flags; /*!< Object creation flags */
29 };
30 
31 /*!
32  * \struct ps_obj_header_t
33  *
34  * \brief Metadata attached as a header to object data before storage.
35  */
36 struct ps_obj_header_t {
37 #ifdef PS_ENCRYPTION
38     union ps_crypto_t crypto;     /*!< Crypto metadata */
39 #else
40     uint32_t version;              /*!< Object version */
41     uint32_t fid;                  /*!< File ID */
42 #endif
43     struct ps_object_info_t info; /*!< Object information */
44 };
45 
46 
47 #define PS_MAX_OBJECT_DATA_SIZE  PS_MAX_ASSET_SIZE
48 
49 /*!
50  * \struct ps_object_t
51  *
52  * \brief The object to be written to the file system below. Made up of the
53  *        object header and the object data.
54  */
55 struct ps_object_t {
56     struct ps_obj_header_t header;         /*!< Object header */
57     uint8_t data[PS_MAX_OBJECT_DATA_SIZE]; /*!< Object data */
58 };
59 
60 
61 #define PS_OBJECT_HEADER_SIZE    sizeof(struct ps_obj_header_t)
62 #define PS_MAX_OBJECT_SIZE       sizeof(struct ps_object_t)
63 
64 /*!
65  * \def PS_MAX_NUM_OBJECTS
66  *
67  * \brief Specifies the maximum number of objects in the system, which is the
68  *        number of defined assets, the object table and 2 temporary objects to
69  *        store the temporary object table and temporary updated object.
70  */
71 #define PS_MAX_NUM_OBJECTS (PS_NUM_ASSETS + 3)
72 
73 #endif /* __PS_OBJECT_DEFS_H__ */
74