@@ -7,18 +7,20 @@ mod content_type;
77mod document_ref;
88mod extra_fields;
99mod section;
10+ pub ( crate ) mod utils;
1011
1112use algorithm:: Algorithm ;
1213use catalyst_types:: {
1314 problem_report:: ProblemReport ,
14- uuid:: { CborContext , UuidV4 , UuidV7 } ,
15+ uuid:: { UuidV4 , UuidV7 } ,
1516} ;
1617pub use content_encoding:: ContentEncoding ;
1718pub use content_type:: ContentType ;
18- use coset:: { iana:: CoapContentFormat , CborSerializable } ;
19+ use coset:: iana:: CoapContentFormat ;
1920pub use document_ref:: DocumentRef ;
2021pub use extra_fields:: ExtraFields ;
2122pub use section:: Section ;
23+ use utils:: { cose_protected_header_find, decode_cbor_uuid, encode_cbor_uuid} ;
2224
2325/// `content_encoding` field COSE key value
2426const CONTENT_ENCODING_KEY : & str = "Content-Encoding" ;
@@ -298,43 +300,3 @@ impl TryFrom<&Metadata> for coset::Header {
298300 Ok ( builder. build ( ) )
299301 }
300302}
301-
302- /// Find a value for a predicate in the protected header.
303- fn cose_protected_header_find (
304- protected : & coset:: ProtectedHeader , mut predicate : impl FnMut ( & coset:: Label ) -> bool ,
305- ) -> Option < & coset:: cbor:: Value > {
306- protected
307- . header
308- . rest
309- . iter ( )
310- . find ( |( key, _) | predicate ( key) )
311- . map ( |( _, value) | value)
312- }
313-
314- /// Encode `uuid::Uuid` type into `coset::cbor::Value`.
315- ///
316- /// This is used to encode `UuidV4` and `UuidV7` types.
317- pub ( crate ) fn encode_cbor_uuid < T : minicbor:: encode:: Encode < CborContext > > (
318- value : T ,
319- ) -> anyhow:: Result < coset:: cbor:: Value > {
320- let mut cbor_bytes = Vec :: new ( ) ;
321- minicbor:: encode_with ( value, & mut cbor_bytes, & mut CborContext :: Tagged )
322- . map_err ( |e| anyhow:: anyhow!( "Unable to encode CBOR value, err: {e}" ) ) ?;
323- coset:: cbor:: Value :: from_slice ( & cbor_bytes)
324- . map_err ( |e| anyhow:: anyhow!( "Invalid CBOR value, err: {e}" ) )
325- }
326-
327- /// Decode `From<uuid::Uuid>` type from `coset::cbor::Value`.
328- ///
329- /// This is used to decode `UuidV4` and `UuidV7` types.
330- pub ( crate ) fn decode_cbor_uuid < T : for < ' a > minicbor:: decode:: Decode < ' a , CborContext > > (
331- value : coset:: cbor:: Value ,
332- ) -> anyhow:: Result < T > {
333- match value. to_vec ( ) {
334- Ok ( cbor_value) => {
335- minicbor:: decode_with ( & cbor_value, & mut CborContext :: Tagged )
336- . map_err ( |e| anyhow:: anyhow!( "Invalid UUID, err: {e}" ) )
337- } ,
338- Err ( e) => anyhow:: bail!( "Invalid CBOR value, err: {e}" ) ,
339- }
340- }
0 commit comments