Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
104 changes: 43 additions & 61 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions ssh-key/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "ssh-key"
version = "0.4.3"
version = "0.5.0-pre"
description = """
Pure Rust implementation of SSH key file format decoders/encoders as described
in RFC4251 and RFC4253 as well as the OpenSSH key formats, certificates
Expand All @@ -27,12 +27,12 @@ aes = { version = "0.8", optional = true, default-features = false }
ctr = { version = "0.9", optional = true, default-features = false }
bcrypt-pbkdf = { version = "0.9", optional = true, default-features = false }
ed25519-dalek = { version = "1.0.1", optional = true, default-features = false, features = ["u64_backend"] }
p256 = { version = "0.10", optional = true, default-features = false, features = ["ecdsa"] }
p256 = { version = "0.11", optional = true, default-features = false, features = ["ecdsa"] }
rand_core = { version = "0.6", optional = true, default-features = false }
rsa = { version = "0.6.1", optional = true }
sec1 = { version = "0.2", optional = true, default-features = false }
rsa = { version = "=0.7.0-rc.0", optional = true }
sec1 = { version = "0.3", optional = true, default-features = false, features = ["point"] }
serde = { version = "1", optional = true }
sha2 = { version = "0.10", optional = true, default-features = false }
sha2 = { version = "0.10.6", optional = true, default-features = false, features = ["oid"] }
signature = { version = "1.3.1", optional = true, default-features = false }
subtle = { version = "2", optional = true, default-features = false }

Expand Down
2 changes: 1 addition & 1 deletion ssh-key/src/private.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ use subtle::{Choice, ConstantTimeEq};
const CONVERSION_ERROR_MSG: &str = "SSH private key conversion error";

/// Default key size to use for RSA keys in bits.
#[cfg(feature = "rsa")]
#[cfg(all(feature = "rand_core", feature = "rsa"))]
const DEFAULT_RSA_KEY_SIZE: usize = 4096;

/// Maximum supported block size.
Expand Down
18 changes: 16 additions & 2 deletions ssh-key/src/private/rsa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ use zeroize::Zeroize;
use {
crate::Error,
rand_core::{CryptoRng, RngCore},
rsa::PublicKeyParts,
rsa::{pkcs1v15, PublicKeyParts},
sha2::{digest::const_oid::AssociatedOid, Digest},
};

#[cfg(feature = "subtle")]
Expand Down Expand Up @@ -194,7 +195,7 @@ impl TryFrom<&RsaKeypair> for rsa::RsaPrivateKey {
rsa::BigUint::try_from(&key.private.p)?,
rsa::BigUint::try_from(&key.private.p)?,
],
);
)?;

if ret.size().saturating_mul(8) >= RsaKeypair::MIN_KEY_SIZE {
Ok(ret)
Expand Down Expand Up @@ -242,6 +243,19 @@ impl TryFrom<&rsa::RsaPrivateKey> for RsaKeypair {
}
}

#[cfg(feature = "rsa")]
#[cfg_attr(docsrs, doc(cfg(feature = "rsa")))]
impl<D> TryFrom<&RsaKeypair> for pkcs1v15::SigningKey<D>
where
D: Digest + AssociatedOid,
{
type Error = Error;

fn try_from(keypair: &RsaKeypair) -> Result<pkcs1v15::SigningKey<D>> {
Ok(pkcs1v15::SigningKey::new_with_prefix(keypair.try_into()?))
}
}

#[cfg(feature = "subtle")]
#[cfg_attr(docsrs, doc(cfg(feature = "subtle")))]
impl ConstantTimeEq for RsaKeypair {
Expand Down
16 changes: 15 additions & 1 deletion ssh-key/src/public/rsa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ use crate::{
#[cfg(feature = "rsa")]
use {
crate::{private::RsaKeypair, Error},
rsa::PublicKeyParts,
rsa::{pkcs1v15, PublicKeyParts},
sha2::{digest::const_oid::AssociatedOid, Digest},
};

/// RSA public key.
Expand Down Expand Up @@ -101,3 +102,16 @@ impl TryFrom<&rsa::RsaPublicKey> for RsaPublicKey {
})
}
}

#[cfg(feature = "rsa")]
#[cfg_attr(docsrs, doc(cfg(feature = "rsa")))]
impl<D> TryFrom<&RsaPublicKey> for pkcs1v15::VerifyingKey<D>
where
D: Digest + AssociatedOid,
{
type Error = Error;

fn try_from(key: &RsaPublicKey) -> Result<pkcs1v15::VerifyingKey<D>> {
Ok(pkcs1v15::VerifyingKey::new_with_prefix(key.try_into()?))
}
}
Loading