@@ -113,29 +113,30 @@ impl KeyPair {
113113
114114 let kind = if alg == & PKCS_ED25519 {
115115 KeyPairKind :: Ed (
116- Ed25519KeyPair :: from_pkcs8_maybe_unchecked ( pkcs8) . map_err ( key_rejected_err) ?,
116+ Ed25519KeyPair :: from_pkcs8_maybe_unchecked ( pkcs8)
117+ . map_err ( |e| Error :: Ring ( e. to_string ( ) ) ) ?,
117118 )
118119 } else if alg == & PKCS_ECDSA_P256_SHA256 {
119120 KeyPairKind :: Ec (
120121 EcdsaKeyPair :: from_pkcs8 ( & signature:: ECDSA_P256_SHA256_ASN1_SIGNING , pkcs8, rng)
121- . map_err ( key_rejected_err ) ?,
122+ . map_err ( |e| Error :: Ring ( e . to_string ( ) ) ) ?,
122123 )
123124 } else if alg == & PKCS_ECDSA_P384_SHA384 {
124125 KeyPairKind :: Ec (
125126 EcdsaKeyPair :: from_pkcs8 ( & signature:: ECDSA_P384_SHA384_ASN1_SIGNING , pkcs8, rng)
126- . map_err ( key_rejected_err ) ?,
127+ . map_err ( |e| Error :: Ring ( e . to_string ( ) ) ) ?,
127128 )
128129 } else if alg == & PKCS_RSA_SHA256 {
129- let rsakp = RsaKeyPair :: from_pkcs8 ( pkcs8) . map_err ( key_rejected_err ) ?;
130+ let rsakp = RsaKeyPair :: from_pkcs8 ( pkcs8) . map_err ( |e| Error :: Ring ( e . to_string ( ) ) ) ?;
130131 KeyPairKind :: Rsa ( rsakp, & signature:: RSA_PKCS1_SHA256 )
131132 } else if alg == & PKCS_RSA_SHA384 {
132- let rsakp = RsaKeyPair :: from_pkcs8 ( pkcs8) . map_err ( key_rejected_err ) ?;
133+ let rsakp = RsaKeyPair :: from_pkcs8 ( pkcs8) . map_err ( |e| Error :: Ring ( e . to_string ( ) ) ) ?;
133134 KeyPairKind :: Rsa ( rsakp, & signature:: RSA_PKCS1_SHA384 )
134135 } else if alg == & PKCS_RSA_SHA512 {
135- let rsakp = RsaKeyPair :: from_pkcs8 ( pkcs8) . map_err ( key_rejected_err ) ?;
136+ let rsakp = RsaKeyPair :: from_pkcs8 ( pkcs8) . map_err ( |e| Error :: Ring ( e . to_string ( ) ) ) ?;
136137 KeyPairKind :: Rsa ( rsakp, & signature:: RSA_PKCS1_SHA512 )
137138 } else if alg == & PKCS_RSA_PSS_SHA256 {
138- let rsakp = RsaKeyPair :: from_pkcs8 ( pkcs8) . map_err ( key_rejected_err ) ?;
139+ let rsakp = RsaKeyPair :: from_pkcs8 ( pkcs8) . map_err ( |e| Error :: Ring ( e . to_string ( ) ) ) ?;
139140 KeyPairKind :: Rsa ( rsakp, & signature:: RSA_PSS_SHA256 )
140141 } else {
141142 panic ! ( "Unknown SignatureAlgorithm specified!" ) ;
@@ -180,7 +181,7 @@ impl KeyPair {
180181 match alg. sign_alg {
181182 SignAlgo :: EcDsa ( sign_alg) => {
182183 let key_pair_doc = EcdsaKeyPair :: generate_pkcs8 ( sign_alg, rng)
183- . map_err ( |_| Error :: RingUnspecified ) ?;
184+ . map_err ( |_| Error :: Ring ( "Unspecified error" . into ( ) ) ) ?;
184185 let key_pair_serialized = key_pair_doc. as_ref ( ) . to_vec ( ) ;
185186
186187 let key_pair =
@@ -192,8 +193,8 @@ impl KeyPair {
192193 } )
193194 } ,
194195 SignAlgo :: EdDsa ( _sign_alg) => {
195- let key_pair_doc =
196- Ed25519KeyPair :: generate_pkcs8 ( rng ) . map_err ( |_| Error :: RingUnspecified ) ?;
196+ let key_pair_doc = Ed25519KeyPair :: generate_pkcs8 ( rng )
197+ . map_err ( |_| Error :: Ring ( "Unspecified error" . into ( ) ) ) ?;
197198 let key_pair_serialized = key_pair_doc. as_ref ( ) . to_vec ( ) ;
198199
199200 let key_pair = Ed25519KeyPair :: from_pkcs8 ( & & key_pair_doc. as_ref ( ) ) . unwrap ( ) ;
@@ -236,7 +237,7 @@ impl KeyPair {
236237 let system_random = SystemRandom :: new ( ) ;
237238 let signature = kp
238239 . sign ( & system_random, msg)
239- . map_err ( |_| Error :: RingUnspecified ) ?;
240+ . map_err ( |_| Error :: Ring ( "Unspecified error" . into ( ) ) ) ?;
240241 let sig = & signature. as_ref ( ) ;
241242 writer. write_bitvec_bytes ( & sig, & sig. len ( ) * 8 ) ;
242243 } ,
@@ -249,7 +250,7 @@ impl KeyPair {
249250 let system_random = SystemRandom :: new ( ) ;
250251 let mut signature = vec ! [ 0 ; kp. public( ) . modulus_len( ) ] ;
251252 kp. sign ( * padding_alg, & system_random, msg, & mut signature)
252- . map_err ( |_| Error :: RingUnspecified ) ?;
253+ . map_err ( |_| Error :: Ring ( "Unspecified error" . into ( ) ) ) ?;
253254 let sig = & signature. as_ref ( ) ;
254255 writer. write_bitvec_bytes ( & sig, & sig. len ( ) * 8 ) ;
255256 } ,
@@ -376,10 +377,6 @@ pub trait RemoteKeyPair {
376377 fn algorithm ( & self ) -> & ' static SignatureAlgorithm ;
377378}
378379
379- pub ( crate ) fn key_rejected_err ( err : ring:: error:: KeyRejected ) -> Error {
380- Error :: RingKeyRejected ( err. to_string ( ) )
381- }
382-
383380pub ( crate ) trait PublicKeyData {
384381 fn alg ( & self ) -> & SignatureAlgorithm ;
385382
0 commit comments