diff --git a/Cargo.toml b/Cargo.toml index 98df0527..80170008 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -68,3 +68,8 @@ opt-level = 2 [profile.bench] debug = true + + +[patch.crates-io] +# pkcs1: split RsaPublicKey into RsaPublicKeyRef and RsaPublicKeyOwned - #2411 +pkcs1 = { git = "https://github.com/RustCrypto/formats.git", rev = "0072dd7246ce370e7b89047b1389f44b67ab63b7" } diff --git a/src/encoding.rs b/src/encoding.rs index 086c8c92..9632bb45 100644 --- a/src/encoding.rs +++ b/src/encoding.rs @@ -34,7 +34,7 @@ impl pkcs1::DecodeRsaPrivateKey for RsaPrivateKey { impl pkcs1::DecodeRsaPublicKey for RsaPublicKey { fn from_pkcs1_der(bytes: &[u8]) -> pkcs1::Result { - pkcs1::RsaPublicKey::from_der(bytes)?.try_into() + pkcs1::RsaPublicKeyRef::from_der(bytes)?.try_into() } } @@ -67,10 +67,10 @@ impl TryFrom> for RsaPrivateKey { } } -impl TryFrom> for RsaPublicKey { +impl TryFrom> for RsaPublicKey { type Error = pkcs1::Error; - fn try_from(pkcs1_key: pkcs1::RsaPublicKey<'_>) -> pkcs1::Result { + fn try_from(pkcs1_key: pkcs1::RsaPublicKeyRef<'_>) -> pkcs1::Result { use pkcs1::Error::KeyMalformed; let bits = u32::try_from(pkcs1_key.modulus.as_bytes().len()).map_err(|_| KeyMalformed)? * 8; @@ -140,7 +140,7 @@ impl pkcs1::EncodeRsaPublicKey for RsaPublicKey { let modulus = self.n().to_be_bytes(); let public_exponent = self.e().to_be_bytes(); - Ok(Document::encode_msg(&pkcs1::RsaPublicKey { + Ok(Document::encode_msg(&pkcs1::RsaPublicKeyRef { modulus: pkcs1::UintRef::new(&modulus)?, public_exponent: pkcs1::UintRef::new(&public_exponent)?, })?) @@ -188,7 +188,7 @@ impl TryFrom> for RsaPublicKey { verify_algorithm_id(&spki.algorithm)?; - pkcs1::RsaPublicKey::try_from(spki.subject_public_key.as_bytes().ok_or(KeyMalformed)?) + pkcs1::RsaPublicKeyRef::try_from(spki.subject_public_key.as_bytes().ok_or(KeyMalformed)?) .and_then(TryInto::try_into) .map_err(pkcs1_error_to_spki) }