4343#include <syslog.h>
4444#include <time.h>
4545#include <sys/types.h>
46- #include <qcbor/UsefulBuf.h>
4746
4847#include "BPSecLib_Public.h"
4948
@@ -289,105 +288,8 @@ void BSL_LogEvent(int severity, const char *filename, int lineno, const char *fu
289288
290289#define ASSERT_POSTCONDITION (expr ) ASSERT_TEMPL(expr, "Panic: Precondition failed to satisfy")
291290
292- // TODO(Bvb): These can be moved to backend, or removed.
293- /// Data pointer for BSL_Data_t
294- typedef uint8_t * BSL_DataPtr_t ;
295- /// Pointer to constant data for BSL_Data_t
296- typedef const uint8_t * BSL_DataConstPtr_t ;
297-
298- /** Heap data storage and views.
299- */
300- typedef struct BSL_Data_s
301- {
302- /// @brief True if this data is a copy
303- bool owned ;
304- /// @brief Pointer to the front of the buffer
305- BSL_DataPtr_t ptr ;
306- /// @brief Size of the data buffer
307- size_t len ;
308- } BSL_Data_t ;
309-
310- /** Static initializer for a data store.
311- * @sa BSL_Data_Init()
312- */
313- #define BSL_DATA_INIT_NULL \
314- { \
315- .owned = false, .ptr = NULL, .len = 0 \
316- }
317-
318- /**
319- * Return size of library context
320- */
321- size_t BSL_LibCtx_Sizeof (void );
322-
323- /** Initialize an empty data struct.
324- *
325- * @param[in,out] data The data to initialize, which must not be NULL.
326- * @return Zero upon success.
327- * @sa BSL_DATA_INIT_NULL
328- */
329- int BSL_Data_Init (BSL_Data_t * data );
330-
331- /** Initialize with an owned buffer of size bytelen
332- *
333- * @todo Clarify to indicate this calls MALLOC.
334- *
335- * @param[in,out] data The data to initialize.
336- * @param[in] bytelen Length of buffer to allocate.
337- * @return Zero upon success.
338- */
339- int BSL_Data_InitBuffer (BSL_Data_t * data , size_t bytelen );
340-
341- /** Initialize a data struct as an overlay on optional external data.
342- *
343- * @param[in,out] data The data to initialize, which must not be NULL.
344- * @param[in] len The total length to allocate, which may be zero.
345- * @param[in] src An optional source buffer to point to.
346- * @return Zero upon success.
347- */
348- int BSL_Data_InitView (BSL_Data_t * data , size_t len , BSL_DataPtr_t src );
349-
350- /// @overload
351- void BSL_Data_InitMove (BSL_Data_t * data , BSL_Data_t * src );
352-
353- /** De-initialize a data struct, freeing if necessary.
354- *
355- * @param[in,out] data The data to de-initialize, which must not be NULL.
356- * @return Zero upon success.
357- * @post The struct must be initialized before using again.
358- */
359- int BSL_Data_Deinit (BSL_Data_t * data );
360-
361- /** Resize the data, copying if necessary.
362- *
363- * @param[in,out] data The data to resize, which must not be NULL.
364- * @param[in] len The new total size.
365- * @return Zero upon success.
366- */
367- int BSL_Data_Resize (BSL_Data_t * data , size_t len );
368-
369- /** Set an initialized data struct to a given size.
370- *
371- * @param[in,out] data The data to copy into, which must not be NULL.
372- * @param[in] len The total length to allocate, which may be non-zero.
373- * @param[in] src An optional source buffer to copy from, from which @c len
374- * bytes will be copied.
375- * @return Zero upon success.
376- */
377- int BSL_Data_CopyFrom (BSL_Data_t * data , size_t len , BSL_DataConstPtr_t src );
378-
379- /** Append an initialized data struct with a given size.
380- *
381- * @param[in,out] data The data to copy into, which must not be NULL.
382- * @param[in] len The total length to allocate, which may be non-zero.
383- * @param[in] src An optional source buffer to copy from, from which @c len
384- * bytes will be copied.
385- * @return Zero upon success.
386- */
387- int BSL_Data_AppendFrom (BSL_Data_t * data , size_t len , BSL_DataConstPtr_t src );
388-
389291/// @brief Forward declaration for file-like sequential reader.
390- typedef struct BSL_SeqReader BSL_SeqReader_t ;
292+ typedef struct BSL_SeqReader_s BSL_SeqReader_t ;
391293
392294/** Release resources from a sequential reader.
393295 *
@@ -407,7 +309,7 @@ int BSL_SeqReader_Deinit(BSL_SeqReader_t *obj);
407309int BSL_SeqReader_Get (BSL_SeqReader_t * obj , uint8_t * buf , size_t * bufsize );
408310
409311/// @brief Forward-declaration for file-like interface for a sequential writer.
410- typedef struct BSL_SeqWriter BSL_SeqWriter_t ;
312+ typedef struct BSL_SeqWriter_s BSL_SeqWriter_t ;
411313
412314/** Release resources from a sequential writer.
413315 *
@@ -582,17 +484,6 @@ typedef enum
582484 */
583485int BSL_BundleCtx_GetBundleMetadata (const BSL_BundleRef_t * bundle , BSL_PrimaryBlock_t * result_primary_block );
584486
585- /** @brief Returns an array in which each element contains the id of the corresponding block.abort
586- *
587- * @param[in] bundle Bundle context
588- * @param[in] array_count Number of elements in `block_id_index_array`
589- * @param[out] block_id_index_array Array of `array_count` elements for results
590- * @param[out] result_count Contains the number of elements put into the array
591- * @return 0 on success, negative on error
592- */
593- int BSL_BundleCtx_GetBlockIds (const BSL_BundleRef_t * bundle , size_t array_count , uint64_t * block_ids_array ,
594- size_t * result_count );
595-
596487/** @brief Returns information about the bundle Canonical block
597488 *
598489 * @param[in] bundle Context bundle
@@ -638,6 +529,10 @@ int BSL_BundleCtx_DeleteBundle(BSL_BundleRef_t *bundle);
638529 */
639530int BSL_BundleCtx_ReallocBTSD (BSL_BundleRef_t * bundle , uint64_t block_num , size_t bytesize );
640531
532+ BSL_SeqReader_t * BSL_BundleCtx_ReadBTSD (BSL_BundleRef_t * bundle , uint64_t block_num );
533+
534+ BSL_SeqWriter_t * BSL_BundleCtx_WriteBTSD (BSL_BundleRef_t * bundle , uint64_t block_num );
535+
641536#define BSL_DEFAULT_BYTESTR_LEN (128)
642537
643538/** @brief Security role of an operation
@@ -678,7 +573,7 @@ typedef struct BSL_SecResult_s BSL_SecResult_t;
678573 * @return 0 on success, negative on error
679574 */
680575int BSL_SecResult_Init (BSL_SecResult_t * self , uint64_t result_id , uint64_t context_id , uint64_t target_block_num ,
681- BSL_Data_t content );
576+ const BSL_Data_t * content );
682577
683578/** Return true when internal invariant checks pass
684579 *
@@ -1022,19 +917,19 @@ int BSL_AbsSecBlock_StripResults(BSL_AbsSecBlock_t *self, uint64_t target_block_
1022917 *
1023918 * @param[in] self This ASB.
1024919 * @param[in] buf A buffer with allocated space for the encoded CBOR
1025- * or the @c SizeCalculateUsefulBuf value to get the real size.
920+ * or a zero-length buffer to calculate the needed size.
1026921 * @return Integer contains number of bytes written to buffer, negative indicates error.
1027922 *
1028923 */
1029- ssize_t BSL_AbsSecBlock_EncodeToCBOR (const BSL_AbsSecBlock_t * self , UsefulBuf buf );
924+ ssize_t BSL_AbsSecBlock_EncodeToCBOR (const BSL_AbsSecBlock_t * self , BSL_Data_t * buf );
1030925
1031926/** Decodes and populates this ASB from a CBOR string.
1032927 *
1033928 * @param[in,out] self This allocated, but uninitialized ASB to populate.
1034- * @param[in] encoded_cbor A buffer containing a CBOR string representing the ASB
929+ * @param[in] buf A buffer containing a CBOR string representing the ASB
1035930 * @return Negative on error
1036931 */
1037- int BSL_AbsSecBlock_DecodeFromCBOR (BSL_AbsSecBlock_t * self , const BSL_Data_t * encoded_cbor );
932+ int BSL_AbsSecBlock_DecodeFromCBOR (BSL_AbsSecBlock_t * self , const BSL_Data_t * buf );
1038933
1039934/** @brief Represents the output following execution of a security operation.
1040935 */
0 commit comments