Skip to content

Commit 26d482b

Browse files
authored
ssh-key: support making RSA-SHA1 signatures (#323)
1 parent 8667977 commit 26d482b

1 file changed

Lines changed: 22 additions & 7 deletions

File tree

ssh-key/src/signature.rs

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -663,21 +663,36 @@ impl Verifier<Signature> for EcdsaPublicKey {
663663
}
664664

665665
#[cfg(feature = "rsa")]
666-
impl Signer<Signature> for RsaKeypair {
666+
impl Signer<Signature> for (&RsaKeypair, Option<HashAlg>) {
667667
fn try_sign(&self, message: &[u8]) -> signature::Result<Signature> {
668-
let data = rsa::pkcs1v15::SigningKey::<Sha512>::try_from(self)?
669-
.try_sign(message)
670-
.map_err(|_| signature::Error::new())?;
668+
let data = match self.1 {
669+
Some(HashAlg::Sha512) => {
670+
rsa::pkcs1v15::SigningKey::<Sha512>::try_from(self.0)?.try_sign(message)
671+
}
672+
Some(HashAlg::Sha256) => {
673+
rsa::pkcs1v15::SigningKey::<Sha256>::try_from(self.0)?.try_sign(message)
674+
}
675+
#[cfg(all(feature = "rsa", feature = "sha1"))]
676+
None => rsa::pkcs1v15::SigningKey::<Sha1>::try_from(self.0)?.try_sign(message),
677+
#[cfg(not(all(feature = "rsa", feature = "sha1")))]
678+
None => return Err(Algorithm::Rsa { hash: None }.unsupported_error().into()),
679+
}
680+
.map_err(|_| signature::Error::new())?;
671681

672682
Ok(Signature {
673-
algorithm: Algorithm::Rsa {
674-
hash: Some(HashAlg::Sha512),
675-
},
683+
algorithm: Algorithm::Rsa { hash: self.1 },
676684
data: data.to_vec(),
677685
})
678686
}
679687
}
680688

689+
#[cfg(feature = "rsa")]
690+
impl Signer<Signature> for RsaKeypair {
691+
fn try_sign(&self, message: &[u8]) -> signature::Result<Signature> {
692+
(self, Some(HashAlg::Sha512)).try_sign(message)
693+
}
694+
}
695+
681696
#[cfg(feature = "rsa")]
682697
impl Verifier<Signature> for RsaPublicKey {
683698
fn verify(&self, message: &[u8], signature: &Signature) -> signature::Result<()> {

0 commit comments

Comments
 (0)