Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add sha2 feature with oid subfeature enabled #255

Merged
merged 1 commit into from
Jan 20, 2023
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
8 changes: 7 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ pkcs8 = { version = "0.9", default-features = false, features = ["alloc"] }
signature = { version = "2", default-features = false , features = ["digest", "rand_core"] }
zeroize = { version = "1", features = ["alloc"] }

[dependencies.sha2]
version = "0.10.6"
optional = true
default-features = false
features = ["oid"]

[dependencies.serde_crate]
package = "serde"
optional = true
Expand Down Expand Up @@ -59,7 +65,7 @@ pkcs5 = ["pkcs8/encryption"]
getrandom = ["rand_core/getrandom"]

[package.metadata.docs.rs]
features = ["std", "pem", "serde", "expose-internals"]
features = ["std", "pem", "serde", "expose-internals", "sha2"]
rustdoc-args = ["--cfg", "docsrs"]

[profile.dev]
Expand Down
10 changes: 8 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,15 @@
//! ```
//!
//! ## PKCS#1 v1.5 signatures
//! ```
//!
//! Note: requires `sha2` feature of `rsa` crate is enabled.
//!
#![cfg_attr(feature = "sha2", doc = "```")]
#![cfg_attr(not(feature = "sha2"), doc = "```ignore")]
//! use rsa::RsaPrivateKey;
//! use rsa::pkcs1v15::{SigningKey, VerifyingKey};
//! use rsa::signature::{Keypair, RandomizedSigner, SignatureEncoding, Verifier};
//! use sha2::{Digest, Sha256};
//! use rsa::sha2::{Digest, Sha256};
//!
//! let mut rng = rand::thread_rng();
//!
Expand Down Expand Up @@ -224,6 +228,8 @@ mod raw;

pub use pkcs1;
pub use pkcs8;
#[cfg(feature = "sha2")]
pub use sha2;

pub use crate::{
key::{PublicKey, PublicKeyParts, RsaPrivateKey, RsaPublicKey},
Expand Down
12 changes: 10 additions & 2 deletions src/pkcs1v15.rs
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,11 @@ impl<D> SigningKey<D>
where
D: Digest,
{
/// Create a new signing key from the give RSA private key.
/// Create a new signing key from the give RSA private key with an empty prefix.
///
/// ## Note: unprefixed signatures are uncommon
///
/// In most cases you'll want to use [`SigningKey::new_with_prefix`].
pub fn new(key: RsaPrivateKey) -> Self {
Self {
inner: key,
Expand Down Expand Up @@ -587,7 +591,11 @@ impl<D> VerifyingKey<D>
where
D: Digest,
{
/// Create a new verifying key from an RSA public key.
/// Create a new verifying key from an RSA public key with an empty prefix.
///
/// ## Note: unprefixed signatures are uncommon
///
/// In most cases you'll want to use [`SigningKey::new_with_prefix`].
pub fn new(key: RsaPublicKey) -> Self {
Self {
inner: key,
Expand Down