@@ -14,11 +14,6 @@ mod signature;
1414pub use metadata:: { DocumentRef , Metadata , UuidV7 } ;
1515pub use signature:: Kid ;
1616
17- /// Catalyst Signed Document Content Encoding Key.
18- const CONTENT_ENCODING_KEY : & str = "Content-Encoding" ;
19- /// Catalyst Signed Document Content Encoding Value.
20- const CONTENT_ENCODING_VALUE : & str = "br" ;
21-
2217/// Keep all the contents private.
2318/// Better even to use a structure like this. Wrapping in an Arc means we don't have to
2419/// manage the Arc anywhere else. These are likely to be large, best to have the Arc be
@@ -77,37 +72,23 @@ impl TryFrom<Vec<u8>> for CatalystSignedDocument {
7772 let cose = coset:: CoseSign :: from_tagged_slice ( & cose_bytes)
7873 . or ( coset:: CoseSign :: from_slice ( & cose_bytes) )
7974 . map_err ( |e| anyhow:: anyhow!( "Invalid COSE Sign document: {e}" ) ) ?;
80- let mut content_errors = Vec :: new ( ) ;
81- let expected_header = cose_protected_header ( ) ;
8275
83- if cose. protected . header . content_type != expected_header. content_type {
84- content_errors
85- . push ( "Invalid COSE document protected header `content-type` field" . to_string ( ) ) ;
86- }
76+ let mut content_errors = Vec :: new ( ) ;
8777
88- if !cose. protected . header . rest . iter ( ) . any ( |( key, value) | {
89- key == & coset:: Label :: Text ( CONTENT_ENCODING_KEY . to_string ( ) )
90- && value == & coset:: cbor:: Value :: Text ( CONTENT_ENCODING_VALUE . to_string ( ) )
91- } ) {
92- content_errors. push (
93- "Invalid COSE document protected header {CONTENT_ENCODING_KEY} field" . to_string ( ) ,
94- ) ;
95- }
9678 let metadata = Metadata :: from ( & cose. protected ) ;
79+
9780 if metadata. has_error ( ) {
9881 content_errors. extend_from_slice ( metadata. content_errors ( ) ) ;
9982 }
100- let payload = match & cose. payload {
101- Some ( payload) => {
102- let mut buf = Vec :: new ( ) ;
103- let mut bytes = payload. as_slice ( ) ;
104- brotli:: BrotliDecompress ( & mut bytes, & mut buf) ?;
105- serde_json:: from_slice ( & buf) ?
106- } ,
107- None => {
108- println ! ( "COSE missing payload field with the JSON content in it" ) ;
109- serde_json:: Value :: Object ( serde_json:: Map :: new ( ) )
110- } ,
83+
84+ let payload = if let Some ( payload) = & cose. payload {
85+ let mut buf = Vec :: new ( ) ;
86+ let mut bytes = payload. as_slice ( ) ;
87+ brotli:: BrotliDecompress ( & mut bytes, & mut buf) ?;
88+ serde_json:: from_slice ( & buf) ?
89+ } else {
90+ println ! ( "COSE missing payload field with the JSON content in it" ) ;
91+ serde_json:: Value :: Object ( serde_json:: Map :: new ( ) )
11192 } ;
11293 let signatures = cose. signatures . clone ( ) ;
11394 let inner = InnerCatalystSignedDocument {
@@ -173,27 +154,5 @@ impl CatalystSignedDocument {
173154 pub fn doc_section ( & self ) -> Option < String > {
174155 self . inner . metadata . doc_section ( )
175156 }
176- }
177-
178- /// Generate the COSE protected header used by Catalyst Signed Document.
179- fn cose_protected_header ( ) -> coset:: Header {
180- coset:: HeaderBuilder :: new ( )
181- . content_format ( coset:: iana:: CoapContentFormat :: Json )
182- . text_value (
183- CONTENT_ENCODING_KEY . to_string ( ) ,
184- CONTENT_ENCODING_VALUE . to_string ( ) . into ( ) ,
185- )
186- . build ( )
187- }
188157
189- /// Find a value for a given key in the protected header.
190- fn cose_protected_header_find (
191- cose : & coset:: CoseSign , rest_key : & str ,
192- ) -> Option < coset:: cbor:: Value > {
193- cose. protected
194- . header
195- . rest
196- . iter ( )
197- . find ( |( key, _) | key == & coset:: Label :: Text ( rest_key. to_string ( ) ) )
198- . map ( |( _, value) | value. clone ( ) )
199158}
0 commit comments