@@ -117,7 +117,7 @@ impl From<AuthError> for HttpError {
117117#[ derive( Debug , Error ) ]
118118pub enum SigningKeyError {
119119 #[ error( "Cloud signing failed: {0}" ) ]
120- CloudKmsError ( #[ from] CloudKmsError ) ,
120+ CloudKmsError ( #[ from] Box < CloudKmsError > ) ,
121121 #[ error( "Failed to immediately verify generated signature" ) ]
122122 GeneratedInvalidSignature ,
123123 #[ error( "Failed to parse public key: {0}" ) ]
@@ -288,16 +288,20 @@ impl Signer for CloudKmsSigningKey {
288288 let signature = match response {
289289 Ok ( ( _, response) ) => {
290290 tracing:: info!( "Library deserialization succeeded" ) ;
291- response. signature . ok_or ( CloudKmsError :: MissingSignature )
291+ response
292+ . signature
293+ . ok_or_else ( || Box :: new ( CloudKmsError :: MissingSignature ) )
292294 }
293295 Err ( google_cloudkms1:: Error :: JsonDecodeError ( body, _) ) => {
294296 tracing:: info!( "Using fallback deserialization" ) ;
295297 serde_json:: from_str :: < CloudKmsSignatureResponse > ( & body)
296- . map_err ( |err| CloudKmsError :: FailedToDeserialize ( err) )
298+ . map_err ( CloudKmsError :: FailedToDeserialize )
299+ . map_err ( Box :: new)
297300 . and_then ( |resp| {
298- let decoded = BASE64_STANDARD
301+ BASE64_STANDARD
299302 . decode ( & resp. signature )
300303 . map_err ( CloudKmsError :: FailedToDecodeSignature )
304+ . map_err ( Box :: new)
301305 . and_then ( |decoded| {
302306 let check = crc32c ( & decoded) ;
303307 let check_valid = resp
@@ -309,14 +313,12 @@ impl Signer for CloudKmsSigningKey {
309313 if check_valid {
310314 Ok ( decoded)
311315 } else {
312- Err ( CloudKmsError :: CorruptedSignature )
316+ Err ( Box :: new ( CloudKmsError :: CorruptedSignature ) )
313317 }
314- } ) ;
315-
316- decoded
318+ } )
317319 } )
318320 }
319- Err ( err) => Err ( CloudKmsError :: from ( err) ) ,
321+ Err ( err) => Err ( Box :: new ( CloudKmsError :: from ( err) ) ) ,
320322 } ?;
321323
322324 Ok ( signature)
@@ -381,7 +383,7 @@ impl AsymmetricKey {
381383 pub async fn private_key ( & self ) -> Result < RsaPrivateKey , SigningKeyError > {
382384 Ok ( match self {
383385 AsymmetricKey :: LocalSigner { private, .. } => {
384- RsaPrivateKey :: from_pkcs8_pem ( & private) . unwrap ( )
386+ RsaPrivateKey :: from_pkcs8_pem ( private) . unwrap ( )
385387 }
386388 _ => unimplemented ! ( ) ,
387389 } )
@@ -390,7 +392,7 @@ impl AsymmetricKey {
390392 pub fn public_key ( & self ) -> Result < RsaPublicKey , SigningKeyError > {
391393 Ok ( match self {
392394 AsymmetricKey :: LocalVerifier { public, .. } => {
393- RsaPublicKey :: from_public_key_pem ( & public) ?
395+ RsaPublicKey :: from_public_key_pem ( public) ?
394396 }
395397 AsymmetricKey :: LocalSigner { .. } => Err ( SigningKeyError :: KeyDoesNotSupportFunction ) ?,
396398 AsymmetricKey :: CkmsVerifier { .. } => {
@@ -405,12 +407,16 @@ impl AsymmetricKey {
405407 )
406408 . doit ( )
407409 . await
408- . map_err ( |err| CloudKmsError :: from ( err) ) ?
410+ . map_err ( CloudKmsError :: from)
411+ . map_err ( Box :: new) ?
409412 . 1 ,
410413 )
411414 } ) ?;
412415
413- let pem = public_key. pem . ok_or ( CloudKmsError :: MissingPem ) ?;
416+ let pem = public_key
417+ . pem
418+ . ok_or ( CloudKmsError :: MissingPem )
419+ . map_err ( Box :: new) ?;
414420 RsaPublicKey :: from_public_key_pem ( & pem) ?
415421 }
416422 AsymmetricKey :: CkmsSigner { .. } => Err ( SigningKeyError :: KeyDoesNotSupportFunction ) ?,
@@ -420,7 +426,7 @@ impl AsymmetricKey {
420426 pub fn as_signer ( & self ) -> Result < Arc < dyn Signer > , SigningKeyError > {
421427 Ok ( match self {
422428 AsymmetricKey :: LocalSigner { private, .. } => {
423- let private_key = RsaPrivateKey :: from_pkcs8_pem ( & private) . unwrap ( ) ;
429+ let private_key = RsaPrivateKey :: from_pkcs8_pem ( private) . unwrap ( ) ;
424430 let signing_key = SigningKey :: new ( private_key) ;
425431
426432 Arc :: new ( LocalSigningKey { signing_key } )
0 commit comments