You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
PKCS#1 v1.5 signatures example on docs.rs doesn't work #253
I've been trying to get signing to work, but did not have any luck trying. One of my trouble shooting steps is to create a new rust binary package and try to run this example but it doesn't seem to compile due to an unsatisfied trait bound.
main.rs:
use rsa::RsaPrivateKey;use rsa::pkcs1v15::{SigningKey,VerifyingKey};use rsa::signature::{Keypair,RandomizedSigner,SignatureEncoding,Verifier};use sha2::{Digest,Sha256};fnmain(){letmut rng = rand::thread_rng();let bits = 2048;let private_key = RsaPrivateKey::new(&mut rng, bits).expect("failed to generate a key");let signing_key = SigningKey::<Sha256>::new_with_prefix(private_key);let verifying_key = signing_key.verifying_key();// Signlet data = b"hello world";let signature = signing_key.sign_with_rng(&mut rng, data);assert_ne!(signature.to_bytes().as_ref(), data.as_slice());// Verify
verifying_key.verify(data,&signature).expect("failed to verify");}
cargo.toml:
[package]
name = "rsa-test"version = "0.1.0"edition = "2021"# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
rand = "0.8.5"rsa = "0.8.0"sha2 = "0.10.6"
Activity
tarcieri commentedon Jan 19, 2023
Note that all of the docs on https://docs.rs are doctested in CI, so in general they will not ever be out-of-date for a given version.
The problem is you need the
oidfeature of thesha2crate enabled:We should probably add an explicit dependency on
sha2with theoidfeature to alleviate this problem.rster2002 commentedon Jan 19, 2023
I couldn't find that in the docs. Thanks for the help.
Add `sha2` feature with `oid` subfeature enabled
Add `sha2` feature with `oid` subfeature enabled (#255)
Add `sha2` feature with `oid` subfeature enabled (RustCrypto#255)