diff --git a/src/key_pair.rs b/src/key_pair.rs index 4ecb0f3f..c72d9e00 100644 --- a/src/key_pair.rs +++ b/src/key_pair.rs @@ -144,9 +144,7 @@ impl KeyPair { }) } - pub(crate) fn from_raw<'b>( - pkcs8: impl Into>, - ) -> Result<(KeyPairKind, &'static SignatureAlgorithm), RcgenError> { + pub(crate) fn from_raw<'b>(pkcs8: impl Into>) -> Result { let pkcs8 = pkcs8.into(); let (kind, alg) = if let Ok(edkp) = Ed25519KeyPair::from_pkcs8_maybe_unchecked(&pkcs8) { @@ -167,7 +165,12 @@ impl KeyPair { } else { return Err(RcgenError::CouldNotParseKeyPair); }; - Ok((kind, alg)) + + Ok(KeyPair { + kind, + alg, + serialized_der: pkcs8.to_vec(), + }) } } @@ -190,12 +193,7 @@ impl TryFrom<&[u8]> for KeyPair { type Error = RcgenError; fn try_from(pkcs8: &[u8]) -> Result { - let (kind, alg) = KeyPair::from_raw(pkcs8)?; - Ok(KeyPair { - kind, - alg, - serialized_der: pkcs8.to_vec(), - }) + KeyPair::from_raw(pkcs8) } } @@ -203,12 +201,7 @@ impl TryFrom> for KeyPair { type Error = RcgenError; fn try_from(pkcs8: Vec) -> Result { - let (kind, alg) = KeyPair::from_raw(pkcs8.as_slice())?; - Ok(KeyPair { - kind, - alg, - serialized_der: pkcs8, - }) + KeyPair::from_raw(pkcs8) } }