1
0
mirror of https://github.com/BitskiCo/jwk-rs synced 2024-11-25 13:29:21 +00:00

Update jsonwebtoken v8.0

Squashed commit of the following:

commit cb6264921e3918bef33358857360f83f7ba03080
Author: Christian Haynes <06chaynes@gmail.com>
Date:   Sat Feb 5 10:53:33 2022 -0500

    clippy fixes

commit 0df0aa3c594cb270f50d7e6854695db8921b7eff
Author: Christian Haynes <06chaynes@gmail.com>
Date:   Sat Feb 5 10:51:29 2022 -0500

    updated jsonwebtoken to v8.0
This commit is contained in:
Jacob Lee 2022-04-01 19:23:50 -07:00
parent 07ff6341af
commit bf3dc9fb09
No known key found for this signature in database
GPG Key ID: 8ED9D3088ACB297B
5 changed files with 21 additions and 18 deletions

View File

@ -13,7 +13,7 @@ edition = "2018"
base64 = "0.13" base64 = "0.13"
bitflags = "1.2" bitflags = "1.2"
generic-array = "0.14" generic-array = "0.14"
jsonwebtoken = { version = "7.2", optional = true } jsonwebtoken = { version = "8.0", optional = true }
num-bigint = { version = "0.4", optional = true } num-bigint = { version = "0.4", optional = true }
p256 = { version = "0.9", optional = true, features = ["arithmetic"] } p256 = { version = "0.9", optional = true, features = ["arithmetic"] }
rand = { version = "0.8", optional = true } rand = { version = "0.8", optional = true }
@ -29,7 +29,7 @@ jwt-convert = ["pkcs-convert", "jsonwebtoken"]
generate = ["p256", "rand"] generate = ["p256", "rand"]
[dev-dependencies] [dev-dependencies]
jsonwebtoken = "7.2" jsonwebtoken = "8.0"
[package.metadata.docs.rs] [package.metadata.docs.rs]
all-features = true all-features = true

View File

@ -85,7 +85,7 @@ mod tests {
static BASE64_JSON: &str = "\"AQIDBAUGBw\""; static BASE64_JSON: &str = "\"AQIDBAUGBw\"";
fn get_de() -> serde_json::Deserializer<serde_json::de::StrRead<'static>> { fn get_de() -> serde_json::Deserializer<serde_json::de::StrRead<'static>> {
serde_json::Deserializer::from_str(&BASE64_JSON) serde_json::Deserializer::from_str(BASE64_JSON)
} }
#[test] #[test]

View File

@ -32,7 +32,9 @@
//! extern crate jsonwebkey as jwk; //! extern crate jsonwebkey as jwk;
//! //!
//! #[derive(serde::Serialize, serde::Deserialize)] //! #[derive(serde::Serialize, serde::Deserialize)]
//! struct TokenClaims {} //! struct TokenClaims {
//! exp: usize,
//! }
//! //!
//! let mut my_jwk = jwk::JsonWebKey::new(jwk::Key::generate_p256()); //! let mut my_jwk = jwk::JsonWebKey::new(jwk::Key::generate_p256());
//! my_jwk.set_algorithm(jwk::Algorithm::ES256); //! my_jwk.set_algorithm(jwk::Algorithm::ES256);
@ -40,7 +42,9 @@
//! let alg: jwt::Algorithm = my_jwk.algorithm.unwrap().into(); //! let alg: jwt::Algorithm = my_jwk.algorithm.unwrap().into();
//! let token = jwt::encode( //! let token = jwt::encode(
//! &jwt::Header::new(alg), //! &jwt::Header::new(alg),
//! &TokenClaims {}, //! &TokenClaims {
//! exp: 0,
//! },
//! &my_jwk.key.to_encoding_key(), //! &my_jwk.key.to_encoding_key(),
//! ).unwrap(); //! ).unwrap();
//! //!
@ -309,7 +313,7 @@ impl Key {
]); ]);
let oids = &[Some(&rsa_encryption_oid), None]; let oids = &[Some(&rsa_encryption_oid), None];
let write_bytevec = |writer: DERWriter<'_>, vec: &ByteVec| { let write_bytevec = |writer: DERWriter<'_>, vec: &ByteVec| {
let bigint = BigUint::from_bytes_be(&vec); let bigint = BigUint::from_bytes_be(vec);
writer.write_biguint(&bigint); writer.write_biguint(&bigint);
}; };
@ -333,9 +337,7 @@ impl Key {
match private { match private {
Some( Some(
private private @ RsaPrivate {
@
RsaPrivate {
d: _, d: _,
p: Some(_), p: Some(_),
q: Some(_), q: Some(_),
@ -577,20 +579,19 @@ const _IMPL_JWT_CONVERSIONS: () = {
self.try_to_encoding_key().unwrap() self.try_to_encoding_key().unwrap()
} }
pub fn to_decoding_key(&self) -> jwt::DecodingKey<'static> { pub fn to_decoding_key(&self) -> jwt::DecodingKey {
match self { match self {
Self::Symmetric { key } => jwt::DecodingKey::from_secret(key).into_static(), Self::Symmetric { key } => jwt::DecodingKey::from_secret(key),
Self::EC { .. } => { Self::EC { .. } => {
// The following will not panic: all EC JWKs have public components due to // The following will not panic: all EC JWKs have public components due to
// typing. PEM conversion will always succeed, for the same reason. // typing. PEM conversion will always succeed, for the same reason.
// Hence, jwt::DecodingKey shall have no issue with de-converting. // Hence, jwt::DecodingKey shall have no issue with de-converting.
jwt::DecodingKey::from_ec_pem(self.to_public().unwrap().to_pem().as_bytes()) jwt::DecodingKey::from_ec_pem(self.to_public().unwrap().to_pem().as_bytes())
.unwrap() .unwrap()
.into_static()
} }
Self::RSA { .. } => jwt::DecodingKey::from_rsa_pem(self.to_pem().as_bytes()) Self::RSA { .. } => {
.unwrap() jwt::DecodingKey::from_rsa_pem(self.to_pem().as_bytes()).unwrap()
.into_static(), }
} }
} }
} }

View File

@ -97,7 +97,9 @@ fn generate_p256() {
extern crate jsonwebtoken as jwt; extern crate jsonwebtoken as jwt;
#[derive(Serialize, Deserialize)] #[derive(Serialize, Deserialize)]
struct TokenClaims {} struct TokenClaims {
exp: usize,
}
let mut the_jwk = JsonWebKey::new(Key::generate_p256()); let mut the_jwk = JsonWebKey::new(Key::generate_p256());
the_jwk.set_algorithm(Algorithm::ES256).unwrap(); the_jwk.set_algorithm(Algorithm::ES256).unwrap();
@ -105,7 +107,7 @@ fn generate_p256() {
let encoding_key = jwt::EncodingKey::from_ec_der(&the_jwk.key.to_der()); let encoding_key = jwt::EncodingKey::from_ec_der(&the_jwk.key.to_der());
let token = jwt::encode( let token = jwt::encode(
&jwt::Header::new(the_jwk.algorithm.unwrap().into()), &jwt::Header::new(the_jwk.algorithm.unwrap().into()),
&TokenClaims {}, &TokenClaims { exp: 0 },
&encoding_key, &encoding_key,
) )
.unwrap(); .unwrap();

View File

@ -33,7 +33,7 @@ pub(crate) mod serde_base64 {
let err_msg = e.to_string().to_lowercase(); let err_msg = e.to_string().to_lowercase();
#[cfg(not(debug_assertions))] #[cfg(not(debug_assertions))]
let err_msg = "invalid base64"; let err_msg = "invalid base64";
de::Error::custom(err_msg.strip_suffix(".").unwrap_or(&err_msg)) de::Error::custom(err_msg.strip_suffix('.').unwrap_or(&err_msg))
}) })
} }
} }