@@ -71,31 +71,17 @@ pub(crate) trait DcKey: Serialize + Deserializable + Clone {
7171 }
7272
7373 /// Create a key from an ASCII-armored string.
74- ///
75- /// Returns the key and a map of any headers which might have been set in
76- /// the ASCII-armored representation.
77- fn from_asc ( data : & str ) -> Result < ( Self , BTreeMap < String , String > ) > {
74+ fn from_asc ( data : & str ) -> Result < Self > {
7875 let bytes = data. as_bytes ( ) ;
7976 let res = Self :: from_armor_single ( Cursor :: new ( bytes) ) ;
80- let ( key, headers ) = match res {
77+ let ( key, _headers ) = match res {
8178 Err ( pgp:: errors:: Error :: NoMatchingPacket { .. } ) => match Self :: is_private ( ) {
8279 true => bail ! ( "No private key packet found" ) ,
8380 false => bail ! ( "No public key packet found" ) ,
8481 } ,
8582 _ => res. context ( "rPGP error" ) ?,
8683 } ;
87- let headers = headers
88- . into_iter ( )
89- . map ( |( key, values) | {
90- (
91- key. trim ( ) . to_lowercase ( ) ,
92- values
93- . last ( )
94- . map_or_else ( String :: new, |s| s. trim ( ) . to_string ( ) ) ,
95- )
96- } )
97- . collect ( ) ;
98- Ok ( ( key, headers) )
84+ Ok ( key)
9985 }
10086
10187 /// Serialise the key as bytes.
@@ -446,7 +432,7 @@ pub(crate) async fn store_self_keypair(context: &Context, keypair: &KeyPair) ->
446432/// to avoid generating the key in tests.
447433/// Use import/export APIs instead.
448434pub async fn preconfigure_keypair ( context : & Context , secret_data : & str ) -> Result < ( ) > {
449- let secret = SignedSecretKey :: from_asc ( secret_data) ?. 0 ;
435+ let secret = SignedSecretKey :: from_asc ( secret_data) ?;
450436 let public = secret. split_public_key ( ) ?;
451437 let keypair = KeyPair { public, secret } ;
452438 store_self_keypair ( context, & keypair) . await ?;
@@ -532,7 +518,7 @@ mod tests {
532518
533519 #[ test]
534520 fn test_from_armored_string ( ) {
535- let ( private_key, _ ) = SignedSecretKey :: from_asc (
521+ let private_key = SignedSecretKey :: from_asc (
536522 "-----BEGIN PGP PRIVATE KEY BLOCK-----
537523
538524xcLYBF0fgz4BCADnRUV52V4xhSsU56ZaAn3+3oG86MZhXy4X8w14WZZDf0VJGeTh
@@ -600,17 +586,13 @@ i8pcjGO+IZffvyZJVRWfVooBJmWWbPB1pueo3tx8w3+fcuzpxz+RLFKaPyqXO+dD
600586 fn test_asc_roundtrip ( ) {
601587 let key = KEYPAIR . public . clone ( ) ;
602588 let asc = key. to_asc ( Some ( ( "spam" , "ham" ) ) ) ;
603- let ( key2, hdrs ) = SignedPublicKey :: from_asc ( & asc) . unwrap ( ) ;
589+ let key2 = SignedPublicKey :: from_asc ( & asc) . unwrap ( ) ;
604590 assert_eq ! ( key, key2) ;
605- assert_eq ! ( hdrs. len( ) , 1 ) ;
606- assert_eq ! ( hdrs. get( "spam" ) , Some ( & String :: from( "ham" ) ) ) ;
607591
608592 let key = KEYPAIR . secret . clone ( ) ;
609593 let asc = key. to_asc ( Some ( ( "spam" , "ham" ) ) ) ;
610- let ( key2, hdrs ) = SignedSecretKey :: from_asc ( & asc) . unwrap ( ) ;
594+ let key2 = SignedSecretKey :: from_asc ( & asc) . unwrap ( ) ;
611595 assert_eq ! ( key, key2) ;
612- assert_eq ! ( hdrs. len( ) , 1 ) ;
613- assert_eq ! ( hdrs. get( "spam" ) , Some ( & String :: from( "ham" ) ) ) ;
614596 }
615597
616598 #[ test]
0 commit comments