3030
3131#include "bsl/BPSecLib_Private.h"
3232#include "bsl/BPSecLib_Public.h"
33- #include "bsl/dynamic/CBOR.h"
34-
35- #include <m-bptree.h>
3633
3734#ifdef __cplusplus
3835extern "C" {
@@ -42,7 +39,7 @@ extern "C" {
4239#define BSLX_COSESC_CTX_ID 3
4340
4441/// Internal option enumerations
45- enum BSLX_CoseSC_Option_e
42+ enum BSLX_CoseSc_Option_e
4643{
4744 /** Key ID as a byte string.
4845 * The value is a byte string (which may contain encoded UTF8 text).
@@ -64,7 +61,8 @@ enum BSLX_CoseSC_Option_e
6461 */
6562 BSLX_COSESC_OPTION_TGT_ALG ,
6663 /** AAD Scope as raw encoded data.
67- * The value is encoded CBOR interpreted as ::BSLX_CoseSc_AadScope_t.
64+ * The value is encoded CBOR interpreted as ::BSLX_CoseSc_AadScope_t,
65+ * and can use the BSLX_CoseSc_SetAadScope() helper in policy providers.
6866 * Optional for source, optional exact-match for verifier/acceptor.
6967 */
7068 BSLX_COSESC_OPTION_AAD_SCOPE ,
@@ -111,7 +109,7 @@ enum BSLX_CoseSC_Option_e
111109};
112110
113111/// @brief From https://www.ietf.org/archive/id/draft-ietf-dtn-bpsec-cose-16.html#section-2.2
114- enum BSLX_CoseSC_Param_e
112+ enum BSLX_CoseSc_Param_e
115113{
116114 /// Additional Protected headers
117115 BSLX_COSESC_PARAM_ADDL_PHDR = 3 ,
@@ -122,7 +120,7 @@ enum BSLX_CoseSC_Param_e
122120};
123121
124122/// @brief From https://www.ietf.org/archive/id/draft-ietf-dtn-bpsec-cose-16.html#section-2.3
125- enum BSLX_CoseSC_Result_e
123+ enum BSLX_CoseSc_Result_e
126124{
127125 BSLX_COSESC_RESULT_COSE_ENCRYPT0 = 16 ,
128126 BSLX_COSESC_RESULT_COSE_MAC0 = 17 ,
@@ -132,30 +130,47 @@ enum BSLX_CoseSC_Result_e
132130 BSLX_COSESC_RESULT_COSE_SIGN = 98 ,
133131};
134132
135- /** @struct BSLX_CoseSc_AadScope_t
136- * An internal representation of AAD Scope map, with keys sorted in
137- * CBOR deterministic order and values as a bit mask of
138- * ::BSLX_CoseSC_AAD_Flag_e flags.
139- */
140- // NOLINTBEGIN
141- /// @cond Doxygen_Suppress
142- // GCOV_EXCL_START
143- M_BPTREE_DEF2 (BSLX_CoseSc_AadScope , 4 , int64_t , M_OPEXTEND (M_BASIC_OPLIST , CMP (API_6 (BSL_CBOR_Compare_Int64 ))),
144- uint64_t , M_BASIC_OPLIST )
145- // GCOV_EXCL_STOP
146- /// @endcond
147- // NOLINTEND
133+ /// Special keys for AAD Scope parameter
134+ enum BSLX_CoseSc_AadScope_Special_e
135+ {
136+ /// Reference the security target block
137+ BSLX_COSESC_AADSCOPE_SPECIAL_TARGET = -1 ,
138+ /// Reference the parent security block
139+ BSLX_COSESC_AADSCOPE_SPECIAL_SECURITY = -2 ,
140+ };
148141
149142/// Flags for AAD Scope parameter
150- enum BSLX_CoseSC_AAD_Flag_e
143+ enum BSLX_CoseSc_AadScope_Flag_e
151144{
152- BSLX_COSESC_AAD_FLAG_METADATA = 0x1 ,
153- BSLX_COSESC_AAD_FLAG_BTSD = 0x2 ,
145+ /// Include block header items in AAD
146+ BSLX_COSESC_AADSCOPE_FLAG_METADATA = 0x1 ,
147+ /// Include BTSD in AAD
148+ BSLX_COSESC_AADSCOPE_FLAG_BTSD = 0x2 ,
154149};
155150
156- int BSLX_CoseSc_AadScope_Encode (QCBOREncodeContext * enc , const BSLX_CoseSc_AadScope_t * scope );
151+ /** Native C structure for each item of COSE Context AAD Scope.
152+ */
153+ typedef struct
154+ {
155+ /// Block number or special key from ::BSLX_CoseSc_AadScope_Special_e
156+ int64_t key ;
157+ /** Choice of flags from ::BSLX_CoseSc_AadScope_Flag_e.
158+ * This type is compatible with ::BSL_IdValPair_s storage.
159+ */
160+ int64_t flags ;
161+ } BSLX_CoseSc_AadScope_Item_t ;
157162
158- int BSLX_CoseSc_AadScope_Decode (QCBORDecodeContext * dec , BSLX_CoseSc_AadScope_t * scope );
163+ /** Utility to set the ::BSLX_COSESC_OPTION_AAD_SCOPE option without exposing
164+ * the encoding internals.
165+ *
166+ * @param[in,out] option Pointer to the option to set the AAD Scope on.
167+ * @param[in] list Pointer to an array of integer values, each
168+ * subsequent pair of values is interpreted as a (key, value) in the scope map.
169+ * The order of keys in this form is not significant.
170+ * @param count The number of @b pairs of values in the @c list array.
171+ * @return BSL_SUCCESS if successful.
172+ */
173+ int BSLX_CoseSc_SetAadScope (BSL_IdValPair_t * option , const BSLX_CoseSc_AadScope_Item_t * list , size_t count );
159174
160175/// Match signature ::BSL_SecCtx_Validate_f
161176bool BSLX_CoseSc_Validate (BSL_LibCtx_t * lib , BSL_BundleRef_t * bundle , BSL_SecOper_t * sec_oper );
0 commit comments