Skip to content

Commit 1dbf6c0

Browse files
committed
ssh-key: support making RSA-SHA1 signatures
1 parent 5b22856 commit 1dbf6c0

File tree

1 file changed

+21
-4
lines changed

1 file changed

+21
-4
lines changed

ssh-key/src/signature.rs

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -663,11 +663,21 @@ 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(feature = "rsa-sha1")]
676+
None => rsa::pkcs1v15::SigningKey::<Sha1>::try_from(self.0)?.try_sign(message),
677+
#[cfg(not(feature = "rsa-sha1"))]
678+
None => return Err(Algorithm::Rsa { hash: None }.unsupported_error().into()),
679+
}
680+
.map_err(|_| signature::Error::new())?;
671681

672682
Ok(Signature {
673683
algorithm: Algorithm::Rsa {
@@ -678,6 +688,13 @@ impl Signer<Signature> for RsaKeypair {
678688
}
679689
}
680690

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

0 commit comments

Comments
 (0)