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

Signature-traits #10

Merged
merged 2 commits into from
Nov 25, 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
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ serde = { version = "1.0.160", features = ["derive"] }
serde_json = "1.0.96"
sha1 = "0.10.5"
sha2 = "0.10.6"
signature = "2.1.0"
signature = { version = "2.1.0", features = ["std", "digest"] }
thiserror = "1.0.40"
url = { version = "2.3.1", features = ["serde"] }
zeroize = { version = "1.6.0", features = ["std", "serde", "derive"] }
Expand Down
10 changes: 3 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ use jaws::JWTFormat;
// signing and verification status.
use jaws::Token;

use jaws::algorithms::rsa::RsaPkcs1v15Verify;
// The unverified token state, used like `Token<.., Unverified<..>, ..>`.
// It is generic over the type of the custom header parameters.
use jaws::token::Unverified;
Expand All @@ -104,10 +103,6 @@ use rsa::pkcs8::DecodePrivateKey;
// function, so we get it here from the `sha2` crate in the RustCrypto suite.
use sha2::Sha256;

// This is an alias for the RSA PKCS#1 v1.5 signing algorithm, which is
// implemented in the rsa crate as `rsa::pkcs1v15::SigningKey`.
use jaws::algorithms::rsa::RsaPkcs1v15;

// Using serde_json allows us to quickly construct a serializable payload,
// but applications may want to instead define a struct and use serde to
// derive serialize and deserialize for added type safety.
Expand All @@ -127,7 +122,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
// RsaPkcs1v15 is really an alias to the digital signature algorithm
// implementation in the `rsa` crate, but provided in JAWS to make
// it clear which types are compatible with JWTs.
let alg = RsaPkcs1v15::<Sha256>::new_with_prefix(key);
let alg = rsa::pkcs1v15::SigningKey::<Sha256>::new_with_prefix(key);

// Claims can combine registered and custom fields. The claims object
// can be any type which implements [serde::Serialize].
Expand Down Expand Up @@ -196,7 +191,8 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {

assert_eq!(&key, alg.as_ref().deref());

let alg: RsaPkcs1v15Verify<Sha256> = RsaPkcs1v15Verify::new_with_prefix(key);
let alg: rsa::pkcs1v15::VerifyingKey<Sha256> =
rsa::pkcs1v15::VerifyingKey::new_with_prefix(key);

// We can't access the claims until we verify the token.
let verified = token.verify(&alg).unwrap();
Expand Down
3 changes: 1 addition & 2 deletions examples/acme-new-account.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use jaws::algorithms::rsa::RsaPkcs1v15;
use jaws::Compact;
use jaws::JWTFormat;
use jaws::Token;
Expand Down Expand Up @@ -48,7 +47,7 @@ fn main() {
// RsaPkcs1v15 is really an alias to the digital signature algorithm
// implementation in the `rsa` crate, but provided in JAWS to make
// it clear which types are compatible with JWTs.
let alg = RsaPkcs1v15::<Sha256>::new_with_prefix(key);
let alg = rsa::pkcs1v15::SigningKey::<Sha256>::new_with_prefix(key);

let payload = json!({
"termsOfServiceAgreed": true,
Expand Down
10 changes: 3 additions & 7 deletions examples/rfc7515a2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ use jaws::JWTFormat;
// signing and verification status.
use jaws::Token;

use jaws::algorithms::rsa::RsaPkcs1v15Verify;
// The unverified token state, used like `Token<.., Unverified<..>, ..>`.
// It is generic over the type of the custom header parameters.
use jaws::token::Unverified;
Expand All @@ -26,10 +25,6 @@ use rsa::pkcs8::DecodePrivateKey;
// function, so we get it here from the `sha2` crate in the RustCrypto suite.
use sha2::Sha256;

// This is an alias for the RSA PKCS#1 v1.5 signing algorithm, which is
// implemented in the rsa crate as `rsa::pkcs1v15::SigningKey`.
use jaws::algorithms::rsa::RsaPkcs1v15;

// Using serde_json allows us to quickly construct a serializable payload,
// but applications may want to instead define a struct and use serde to
// derive serialize and deserialize for added type safety.
Expand All @@ -49,7 +44,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
// RsaPkcs1v15 is really an alias to the digital signature algorithm
// implementation in the `rsa` crate, but provided in JAWS to make
// it clear which types are compatible with JWTs.
let alg = RsaPkcs1v15::<Sha256>::new_with_prefix(key);
let alg = rsa::pkcs1v15::SigningKey::<Sha256>::new_with_prefix(key);

// Claims can combine registered and custom fields. The claims object
// can be any type which implements [serde::Serialize].
Expand Down Expand Up @@ -118,7 +113,8 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {

assert_eq!(&key, alg.as_ref().deref());

let alg: RsaPkcs1v15Verify<Sha256> = RsaPkcs1v15Verify::new_with_prefix(key);
let alg: rsa::pkcs1v15::VerifyingKey<Sha256> =
rsa::pkcs1v15::VerifyingKey::new_with_prefix(key);

// We can't access the claims until we verify the token.
let verified = token.verify(&alg).unwrap();
Expand Down
4 changes: 4 additions & 0 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ test:
@echo "Running tests..."
cargo hack test --feature-powerset --group-features ecdsa,p256,p384,p521

check:
@echo "Checking..."
cargo hack check --feature-powerset --group-features ecdsa,p256,p384,p521

doc:
@echo "Building docs..."
cargo doc --all-features
Loading
Loading