Update to edition 2018

This commit is contained in:
Vincent Prouillet 2019-07-06 20:36:32 +02:00
parent 22cd4dbb62
commit b8627260b2
11 changed files with 26 additions and 20 deletions

View File

@ -4,6 +4,7 @@
- Add support for PS256, PS384 and PS512
- Change API for both sign/verify to take a `Key` enum rather than bytes
- Update to 2018 edition
## 6.0.1 (2019-05-10)

View File

@ -8,6 +8,7 @@ description = "Create and parse JWT in a strongly typed way."
homepage = "https://github.com/Keats/rust-jwt"
repository = "https://github.com/Keats/rust-jwt"
keywords = ["jwt", "web", "api", "token", "json"]
edition = "2018"
[dependencies]
serde_json = "1.0"

View File

@ -1,4 +1,4 @@
use errors::{new_error, Error, ErrorKind, Result};
use crate::errors::{new_error, Error, ErrorKind, Result};
use std::str::FromStr;
/// The algorithms supported for signing/verifying

View File

@ -1,13 +1,11 @@
use std::sync::Arc;
use base64;
use ring::constant_time::verify_slices_are_equal;
use ring::{digest, hmac, rand, signature};
use untrusted;
use algorithms::Algorithm;
use errors::{new_error, ErrorKind, Result};
use keys::Key;
use crate::algorithms::Algorithm;
use crate::errors::{new_error, ErrorKind, Result};
use crate::keys::Key;
/// The actual HS signing + encoding
fn sign_hmac(alg: &'static digest::Algorithm, key: Key, signing_input: &str) -> Result<String> {
@ -41,7 +39,11 @@ fn sign_ecdsa(
/// The actual RSA signing + encoding
/// Taken from Ring doc https://briansmith.org/rustdoc/ring/signature/index.html
fn sign_rsa(alg: &'static signature::RsaEncoding, key: Key, signing_input: &str) -> Result<String> {
fn sign_rsa(
alg: &'static dyn signature::RsaEncoding,
key: Key,
signing_input: &str,
) -> Result<String> {
let key_pair = match key {
Key::Der(bytes) => signature::RsaKeyPair::from_der(untrusted::Input::from(bytes))
.map_err(|_| ErrorKind::InvalidRsaKey)?,
@ -52,7 +54,6 @@ fn sign_rsa(alg: &'static signature::RsaEncoding, key: Key, signing_input: &str)
}
};
let key_pair = Arc::new(key_pair);
let mut signature = vec![0; key_pair.public_modulus_len()];
let rng = rand::SystemRandom::new();
key_pair

View File

@ -1,4 +1,4 @@
use algorithms::Algorithm;
use crate::algorithms::Algorithm;
/// A basic JWT header, the alg defaults to HS256 and typ is automatically
/// set to `JWT`. All the other fields are optional.

View File

@ -31,9 +31,9 @@ pub use validation::Validation;
use serde::de::DeserializeOwned;
use serde::ser::Serialize;
use errors::{new_error, ErrorKind, Result};
use serialization::{from_jwt_part, from_jwt_part_claims, to_jwt_part};
use validation::validate;
use crate::errors::{new_error, ErrorKind, Result};
use crate::serialization::{from_jwt_part, from_jwt_part_claims, to_jwt_part};
use crate::validation::validate;
/// Encode the header and claims given and sign the payload using the algorithm from the header and the key
///

View File

@ -4,8 +4,8 @@ use serde::ser::Serialize;
use serde_json::map::Map;
use serde_json::{from_str, to_string, Value};
use errors::Result;
use header::Header;
use crate::errors::Result;
use crate::header::Header;
/// The return type of a successful call to decode
#[derive(Debug)]

View File

@ -3,8 +3,8 @@ use serde::ser::Serialize;
use serde_json::map::Map;
use serde_json::{from_value, to_value, Value};
use algorithms::Algorithm;
use errors::{new_error, ErrorKind, Result};
use crate::algorithms::Algorithm;
use crate::errors::{new_error, ErrorKind, Result};
/// Contains the various validations that are applied after decoding a token.
///
@ -164,7 +164,7 @@ mod tests {
use super::{validate, Validation};
use errors::ErrorKind;
use crate::errors::ErrorKind;
#[test]
fn exp_in_future_ok() {

View File

@ -7,7 +7,7 @@ use chrono::Utc;
use jsonwebtoken::{decode, encode, sign, verify, Algorithm, Header, Key, Validation};
#[derive(Debug, PartialEq, Clone, Serialize, Deserialize)]
struct Claims {
pub struct Claims {
sub: String,
company: String,
exp: i64,

View File

@ -11,7 +11,7 @@ use jsonwebtoken::{
use std::str::FromStr;
#[derive(Debug, PartialEq, Clone, Serialize, Deserialize)]
struct Claims {
pub struct Claims {
sub: String,
company: String,
exp: i64,

View File

@ -16,7 +16,7 @@ const RSA_ALGORITHMS: &[Algorithm] = &[
];
#[derive(Debug, PartialEq, Clone, Serialize, Deserialize)]
struct Claims {
pub struct Claims {
sub: String,
company: String,
exp: i64,
@ -62,3 +62,6 @@ fn fails_with_different_key_format() {
let privkey = include_bytes!("private_rsa_key.der");
sign("hello world", Key::Pkcs8(&privkey[..]), Algorithm::RS256).unwrap();
}
#[test]
fn can_decode_jwt_io_example() {}