From fd59c7826d979c2ac7c551c3b62b16190e0bf4c9 Mon Sep 17 00:00:00 2001 From: Tommy Chiu Date: Mon, 21 Oct 2024 16:06:20 +0800 Subject: [PATCH] [dice,cwt] Add more wrappers for cbor library It requires more wrappers to generate CDI Bug: 356532759 Signed-off-by: Tommy Chiu (cherry picked from commit c8e1260c8a820b00dc164df4f27569b7c1578e3c) --- sw/device/silicon_creator/lib/cert/cbor.h | 40 +++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-) diff --git a/sw/device/silicon_creator/lib/cert/cbor.h b/sw/device/silicon_creator/lib/cert/cbor.h index 99328287b2547..6f3d386a9e5db 100644 --- a/sw/device/silicon_creator/lib/cert/cbor.h +++ b/sw/device/silicon_creator/lib/cert/cbor.h @@ -31,6 +31,25 @@ static inline rom_error_t cbor_map_init(struct CborOut *p, CBOR_CHECK_OVERFLOWED_AND_RETURN(p); } +static inline rom_error_t cbor_array_init(struct CborOut *p, + const size_t num_elements) { + CborWriteArray(num_elements, p); + CBOR_CHECK_OVERFLOWED_AND_RETURN(p); +} + +static inline rom_error_t cbor_write_string(struct CborOut *p, + const char *str) { + CborWriteTstr(str, p); + CBOR_CHECK_OVERFLOWED_AND_RETURN(p); +} + +static inline rom_error_t cbor_write_bytes(struct CborOut *p, + const uint8_t *data, + const size_t data_size) { + CborWriteBstr(data_size, data, p); + CBOR_CHECK_OVERFLOWED_AND_RETURN(p); +} + // Wrappers to encode a pair of data for cbor-map static inline rom_error_t cbor_write_pair_uint_uint(struct CborOut *p, uint64_t key, @@ -57,13 +76,30 @@ static inline rom_error_t cbor_write_pair_uint_int(struct CborOut *p, } static inline rom_error_t cbor_write_pair_int_bytes(struct CborOut *p, - int64_t key, uint8_t *value, - size_t value_size) { + int64_t key, + const uint8_t *value, + const size_t value_size) { CborWriteInt(key, p); CborWriteBstr(value_size, value, p); CBOR_CHECK_OVERFLOWED_AND_RETURN(p); } +static inline rom_error_t cbor_write_pair_uint_tstr(struct CborOut *p, + uint64_t key, + const char *value) { + CborWriteUint(key, p); + CborWriteTstr(value, p); + CBOR_CHECK_OVERFLOWED_AND_RETURN(p); +} + +static inline rom_error_t cbor_write_pair_int_tstr(struct CborOut *p, + int64_t key, + const char *value) { + CborWriteInt(key, p); + CborWriteTstr(value, p); + CBOR_CHECK_OVERFLOWED_AND_RETURN(p); +} + #undef CBOR_CHECK_OVERFLOWED_AND_RETURN #endif // OPENTITAN_SW_DEVICE_SILICON_CREATOR_LIB_CERT_CBOR_H_