@@ -13,14 +13,9 @@ use sfv::{BareItem, Item, ListEntry, Parser};
1313/// IndexMap of signature name and HttpSignatureHeaders
1414pub type HttpSignatureHeadersMap = IndexMap < String , HttpSignatureHeaders , FxBuildHasher > ;
1515
16- /// Default signature name used to indicate signature in http header (`signature` and `signature-input`)
17- const DEFAULT_SIGNATURE_NAME : & str = "sig" ;
18-
1916#[ derive( Debug , Clone ) ]
2017/// Signature Headers derived from HttpSignatureBase
2118pub struct HttpSignatureHeaders {
22- /// signature name coupling signature with signature input
23- signature_name : String ,
2419 /// Signature value of "Signature" http header in the form of "<signature_name>=:<base64_signature>:"
2520 signature : HttpSignature ,
2621 /// signature-params value of "Signature-Input" http header in the form of "<signature_name>=:<signature_params>:"
@@ -87,9 +82,8 @@ impl HttpSignatureHeaders {
8782 let signature = HttpSignature ( signature_bytes) ;
8883
8984 Ok ( (
90- signature_name. clone ( ) ,
85+ signature_name,
9186 Self {
92- signature_name,
9387 signature,
9488 signature_params,
9589 } ,
@@ -99,11 +93,6 @@ impl HttpSignatureHeaders {
9993 Ok ( res)
10094 }
10195
102- /// Returns the signature name
103- pub fn signature_name ( & self ) -> & str {
104- & self . signature_name
105- }
106-
10796 /// Returns the signature value without name
10897 pub fn signature ( & self ) -> & HttpSignature {
10998 & self . signature
@@ -120,12 +109,12 @@ impl HttpSignatureHeaders {
120109 }
121110
122111 /// Returns the signature value of "Signature" http header in the form of "<signature_name>=:<base64_signature>:"
123- pub fn signature_header_value ( & self ) -> String {
124- format ! ( "{}=:{}:" , self . signature_name, self . signature)
112+ pub fn signature_header_value ( & self , signature_name : & str ) -> String {
113+ format ! ( "{}=:{}:" , signature_name, self . signature)
125114 }
126115 /// Returns the signature input value of "Signature-Input" http header in the form of "<signature_name>=<signature_params>"
127- pub fn signature_input_header_value ( & self ) -> String {
128- format ! ( "{}={}" , self . signature_name, self . signature_params)
116+ pub fn signature_input_header_value ( & self , signature_name : & str ) -> String {
117+ format ! ( "{}={}" , signature_name, self . signature_params)
129118 }
130119}
131120
@@ -190,16 +179,11 @@ impl HttpSignatureBase {
190179 }
191180
192181 /// Build the signature and signature-input headers structs
193- pub fn build_signature_headers (
194- & self ,
195- signing_key : & impl SigningKey ,
196- signature_name : Option < & str > ,
197- ) -> HttpSigResult < HttpSignatureHeaders > {
182+ pub fn build_signature_headers ( self , signing_key : & impl SigningKey ) -> HttpSigResult < HttpSignatureHeaders > {
198183 let signature = self . build_raw_signature ( signing_key) ?;
199184 Ok ( HttpSignatureHeaders {
200- signature_name : signature_name. unwrap_or ( DEFAULT_SIGNATURE_NAME ) . to_string ( ) ,
201185 signature : HttpSignature ( signature) ,
202- signature_params : self . signature_params . clone ( ) ,
186+ signature_params : self . signature_params ,
203187 } )
204188 }
205189
@@ -288,15 +272,15 @@ mod test {
288272 const SIGNATURE_INPUT : & str = r##"sig-b26=("date" "@method" "@path" "@authority" "content-type" "content-length");created=1618884473;keyid="test-key-ed25519", sig-b27=("date" "@method" "@path" "@authority" "content-type" "content-length");created=1618884473;keyid="test-key-ed25519-alt""## ;
289273 const SIGNATURE : & str = r##"sig-b26=:wqcAqbmYJ2ji2glfAMaRy4gruYYnx2nEFN2HN6jrnDnQCK1u02Gb04v9EDgwUPiu4A0w6vuQv5lIp5WPpBKRCw==:, sig-b27=:wqcAqbmYJ2ji2glfAMaRy4gruYYnx2nEFN2HN6jrnDnQCK1u02Gb04v9EDgwUPiu4A0w6vuQv5lIp5WPpBKRCw==:"## ;
290274
291- let header_map = HttpSignatureHeaders :: try_parse ( SIGNATURE , SIGNATURE_INPUT ) . unwrap ( ) ;
275+ let mut header_map = HttpSignatureHeaders :: try_parse ( SIGNATURE , SIGNATURE_INPUT ) . unwrap ( ) ;
292276 assert ! ( header_map. len( ) == 2 ) ;
293- let http_signature_headers = header_map. get ( "sig-b26" ) . unwrap ( ) ;
277+ let http_signature_headers = header_map. swap_remove ( "sig-b26" ) . unwrap ( ) ;
294278 assert_eq ! (
295- http_signature_headers. signature_header_value( ) ,
279+ http_signature_headers. signature_header_value( "sig-b26" ) ,
296280 SIGNATURE . split( ',' ) . next( ) . unwrap( )
297281 ) ;
298282 assert_eq ! (
299- http_signature_headers. signature_input_header_value( ) ,
283+ http_signature_headers. signature_input_header_value( "sig-b26" ) ,
300284 SIGNATURE_INPUT . split( ',' ) . next( ) . unwrap( )
301285 ) ;
302286 }
0 commit comments