mikkyang / rust-jwt

JSON Web Token library for Rust
MIT License
176 stars 38 forks source link

How to use rsa256 with sign_with_key? #94

Closed lcmgh closed 11 months ago

lcmgh commented 11 months ago

Hi!

I tried to extend this test to make it sign a claim with rsa256:

https://github.com/mikkyang/rust-jwt/blob/a09172fcbf667db7a982c787ff709c6d6294ef18/src/algorithm/openssl.rs#L129C1-L140 but sign_with_key neither accepts the pem bytes or PKey::private_key_from_pem(pem).unwrap();

How can I get the key from within this test to be accepted by Token::new(header, claims).sign_with_key(&pem).unwrap(); ?

lcmgh commented 11 months ago

I checked the code and found impl SigningAlgorithm for PKeyWithDigest<Private> so I had to pass over algorithm

let algorithm = PKeyWithDigest {
    digest: MessageDigest::sha256(),
    key: key.clone(),
};