Skip to content

Commit 69cbfa3

Browse files
committed
fix cargo format
1 parent d80832c commit 69cbfa3

File tree

14 files changed

+66
-53
lines changed

14 files changed

+66
-53
lines changed

examples/custom_time.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
use jsonwebtoken::{Algorithm, DecodingKey, EncodingKey, Header, Validation};
21
use serde::{Deserialize, Serialize};
32
use time::{Duration, OffsetDateTime};
43

4+
use jsonwebtoken::{Algorithm, DecodingKey, EncodingKey, Header, Validation};
5+
56
const SECRET: &str = "some-secret";
67

78
#[derive(Debug, PartialEq, Serialize, Deserialize)]
@@ -60,13 +61,15 @@ mod jwt_numeric_date {
6061

6162
#[cfg(test)]
6263
mod tests {
63-
const EXPECTED_TOKEN: &str = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJDdXN0b20gT2Zmc2V0RGF0ZVRpbWUgc2VyL2RlIiwiaWF0IjowLCJleHAiOjMyNTAzNjgwMDAwfQ.BcPipupP9oIV6uFRI6Acn7FMLws_wA3oo6CrfeFF3Gg";
64+
use time::{Duration, OffsetDateTime};
6465

65-
use super::super::{Claims, SECRET};
6666
use jsonwebtoken::{
6767
decode, encode, Algorithm, DecodingKey, EncodingKey, Header, Validation,
6868
};
69-
use time::{Duration, OffsetDateTime};
69+
70+
use super::super::{Claims, SECRET};
71+
72+
const EXPECTED_TOKEN: &str = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJDdXN0b20gT2Zmc2V0RGF0ZVRpbWUgc2VyL2RlIiwiaWF0IjowLCJleHAiOjMyNTAzNjgwMDAwfQ.BcPipupP9oIV6uFRI6Acn7FMLws_wA3oo6CrfeFF3Gg";
7073

7174
#[test]
7275
fn round_trip() {

examples/ed25519.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ pub struct Claims {
1616
fn main() {
1717
let secret_key = SecretKey::random(&mut OsRng);
1818
let pkcs8 = secret_key.to_pkcs8_pem(Default::default()).unwrap();
19-
let pkcs8= pkcs8.as_bytes();
19+
let pkcs8 = pkcs8.as_bytes();
2020

2121
let encoding_key = EncodingKey::from_ed_der(pkcs8);
2222

@@ -45,7 +45,7 @@ mod tests {
4545
fn new() -> Jot {
4646
let secret_key = SecretKey::random(&mut OsRng);
4747
let pkcs8 = secret_key.to_pkcs8_pem(Default::default()).unwrap();
48-
let pkcs8= pkcs8.as_bytes();
48+
let pkcs8 = pkcs8.as_bytes();
4949
let encoding_key = EncodingKey::from_ed_der(pkcs8);
5050

5151
let public_key_der = secret_key.public_key().to_public_key_der().unwrap();

examples/validation.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
use serde::{Deserialize, Serialize};
2+
13
use jsonwebtoken::errors::ErrorKind;
24
use jsonwebtoken::{decode, encode, Algorithm, DecodingKey, EncodingKey, Header, Validation};
3-
use serde::{Deserialize, Serialize};
45

56
#[derive(Debug, Serialize, Deserialize)]
67
struct Claims {

src/algorithms.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
use crate::errors::{Error, ErrorKind, Result};
2-
use serde::{Deserialize, Serialize};
31
use std::str::FromStr;
42

3+
use serde::{Deserialize, Serialize};
4+
5+
use crate::errors::{Error, ErrorKind, Result};
6+
57
#[derive(Debug, Eq, PartialEq, Copy, Clone, Serialize, Deserialize)]
68
pub(crate) enum AlgorithmFamily {
79
Hmac,

src/crypto/ecdsa.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ fn es256_sign(key: &[u8], message: &[u8]) -> Result<String> {
1818
use p256::ecdsa::{Signature, SigningKey};
1919
use p256::pkcs8::DecodePrivateKey;
2020
use p256::SecretKey;
21-
let secret_key = SecretKey::from_pkcs8_der(key)
22-
.map_err(|_e| crate::errors::ErrorKind::InvalidEcdsaKey)?;
21+
let secret_key =
22+
SecretKey::from_pkcs8_der(key).map_err(|_e| crate::errors::ErrorKind::InvalidEcdsaKey)?;
2323
let signing_key: SigningKey = secret_key.into();
2424

2525
let signature: Signature = signing_key.sign(message);
@@ -32,8 +32,8 @@ fn es384_sign(key: &[u8], message: &[u8]) -> Result<String> {
3232
use p384::ecdsa::{Signature, SigningKey};
3333
use p384::pkcs8::DecodePrivateKey;
3434
use p384::SecretKey;
35-
let secret_key = SecretKey::from_pkcs8_der(key)
36-
.map_err(|_e| crate::errors::ErrorKind::InvalidEcdsaKey)?;
35+
let secret_key =
36+
SecretKey::from_pkcs8_der(key).map_err(|_e| crate::errors::ErrorKind::InvalidEcdsaKey)?;
3737
let signing_key: SigningKey = secret_key.into();
3838
let signature: Signature = signing_key.sign(message);
3939
let bytes = signature.to_bytes();
@@ -53,8 +53,8 @@ fn es384_verify(signature: &str, message: &[u8], key: &[u8]) -> Result<bool> {
5353
use p384::ecdsa::{Signature, VerifyingKey};
5454
use p384::PublicKey;
5555

56-
let public_key = PublicKey::from_sec1_bytes(key)
57-
.map_err(|_e| crate::errors::ErrorKind::InvalidEcdsaKey)?;
56+
let public_key =
57+
PublicKey::from_sec1_bytes(key).map_err(|_e| crate::errors::ErrorKind::InvalidEcdsaKey)?;
5858
let verifying_key: VerifyingKey = public_key.into();
5959
let signature = Signature::from_slice(&b64_decode(signature)?)
6060
.map_err(|_e| crate::errors::ErrorKind::InvalidSignature)?;
@@ -71,4 +71,4 @@ fn es256_verify(signature: &str, message: &[u8], key: &[u8]) -> Result<bool> {
7171
let signature = Signature::from_slice(&b64_decode(signature)?)
7272
.map_err(|_e| crate::errors::ErrorKind::InvalidSignature)?;
7373
Ok(verifying_key.verify(message, &signature).is_ok())
74-
}
74+
}

src/crypto/hmac.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
use hmac::{Hmac, Mac};
22
use sha2::{Sha256, Sha384, Sha512};
33

4-
use crate::Algorithm;
54
use crate::errors::Result;
65
use crate::serialization::{b64_decode, b64_encode};
6+
use crate::Algorithm;
77

88
type HmacSha256 = Hmac<Sha256>;
99
type HmacSha384 = Hmac<Sha384>;
@@ -66,7 +66,6 @@ impl HmacAlgorithm for Box<dyn HmacAlgorithm + '_> {
6666
}
6767

6868
impl HmacAlgorithm for HmacSha256 {
69-
7069
fn sign(&mut self, message: &[u8]) -> Vec<u8> {
7170
self.reset();
7271
self.update(message);
@@ -80,7 +79,6 @@ impl HmacAlgorithm for HmacSha256 {
8079
}
8180

8281
impl HmacAlgorithm for HmacSha384 {
83-
8482
fn sign(&mut self, message: &[u8]) -> Vec<u8> {
8583
self.reset();
8684
self.update(message);
@@ -94,7 +92,6 @@ impl HmacAlgorithm for HmacSha384 {
9492
}
9593

9694
impl HmacAlgorithm for HmacSha512 {
97-
9895
fn sign(&mut self, message: &[u8]) -> Vec<u8> {
9996
self.reset();
10097
self.update(message);
@@ -106,4 +103,4 @@ impl HmacAlgorithm for HmacSha512 {
106103
self.update(message);
107104
self.clone().verify_slice(signature).is_ok()
108105
}
109-
}
106+
}

src/jwk.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@
44
//! Most of the code in this file is taken from https://github.com/lawliet89/biscuit but
55
//! tweaked to remove the private bits as it's not the goal for this crate currently.
66
7+
use std::{fmt, str::FromStr};
8+
9+
use serde::{de, Deserialize, Deserializer, Serialize, Serializer};
10+
711
use crate::{
812
errors::{self, Error, ErrorKind},
913
Algorithm,
1014
};
11-
use serde::{de, Deserialize, Deserializer, Serialize, Serializer};
12-
use std::{fmt, str::FromStr};
1315

1416
/// The intended usage of the public `KeyType`. This enum is serialized `untagged`
1517
#[derive(Clone, Debug, Eq, PartialEq, Hash)]
@@ -435,11 +437,12 @@ impl JwkSet {
435437

436438
#[cfg(test)]
437439
mod tests {
440+
use serde_json::json;
441+
use wasm_bindgen_test::wasm_bindgen_test;
442+
438443
use crate::jwk::{AlgorithmParameters, JwkSet, OctetKeyType};
439444
use crate::serialization::b64_encode;
440445
use crate::Algorithm;
441-
use serde_json::json;
442-
use wasm_bindgen_test::wasm_bindgen_test;
443446

444447
#[test]
445448
#[wasm_bindgen_test]

src/lib.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@
33
//! Documentation: [stable](https://docs.rs/jsonwebtoken/)
44
#![deny(missing_docs)]
55

6+
pub use algorithms::Algorithm;
7+
pub use decoding::{decode, decode_header, DecodingKey, TokenData};
8+
pub use encoding::{encode, EncodingKey};
9+
pub use header::Header;
10+
pub use validation::{get_current_timestamp, Validation};
11+
612
mod algorithms;
713
/// Lower level functions, if you want to do something other than JWTs
814
pub mod crypto;
@@ -16,9 +22,3 @@ pub mod jwk;
1622
mod pem;
1723
mod serialization;
1824
mod validation;
19-
20-
pub use algorithms::Algorithm;
21-
pub use decoding::{decode, decode_header, DecodingKey, TokenData};
22-
pub use encoding::{encode, EncodingKey};
23-
pub use header::Header;
24-
pub use validation::{get_current_timestamp, Validation};

src/validation.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -170,12 +170,14 @@ pub(crate) struct ClaimsForValidation<'a> {
170170
#[serde(borrow)]
171171
aud: TryParse<Audience<'a>>,
172172
}
173+
173174
#[derive(Debug)]
174175
enum TryParse<T> {
175176
Parsed(T),
176177
FailedToParse,
177178
NotPresent,
178179
}
180+
179181
impl<'de, T: Deserialize<'de>> Deserialize<'de> for TryParse<T> {
180182
fn deserialize<D: serde::Deserializer<'de>>(
181183
deserializer: D,
@@ -187,6 +189,7 @@ impl<'de, T: Deserialize<'de>> Deserialize<'de> for TryParse<T> {
187189
})
188190
}
189191
}
192+
190193
impl<T> Default for TryParse<T> {
191194
fn default() -> Self {
192195
Self::NotPresent
@@ -212,6 +215,7 @@ enum Issuer<'a> {
212215
/// We use this struct in this case.
213216
#[derive(Deserialize, PartialEq, Eq, Hash)]
214217
struct BorrowedCowIfPossible<'a>(#[serde(borrow)] Cow<'a, str>);
218+
215219
impl std::borrow::Borrow<str> for BorrowedCowIfPossible<'_> {
216220
fn borrow(&self) -> &str {
217221
&self.0
@@ -345,14 +349,15 @@ where
345349

346350
#[cfg(test)]
347351
mod tests {
352+
use std::collections::HashSet;
353+
348354
use serde_json::json;
349355
use wasm_bindgen_test::wasm_bindgen_test;
350356

351-
use super::{get_current_timestamp, validate, ClaimsForValidation, Validation};
352-
353357
use crate::errors::ErrorKind;
354358
use crate::Algorithm;
355-
use std::collections::HashSet;
359+
360+
use super::{get_current_timestamp, validate, ClaimsForValidation, Validation};
356361

357362
fn deserialize_claims(claims: &serde_json::Value) -> ClaimsForValidation {
358363
serde::Deserialize::deserialize(claims).unwrap()

tests/ecdsa/mod.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1+
use serde::{Deserialize, Serialize};
2+
#[cfg(feature = "use_pem")]
3+
use time::OffsetDateTime;
4+
use wasm_bindgen_test::wasm_bindgen_test;
5+
16
use jsonwebtoken::{
27
crypto::{sign, verify},
38
Algorithm, DecodingKey, EncodingKey,
49
};
5-
use serde::{Deserialize, Serialize};
6-
710
#[cfg(feature = "use_pem")]
811
use jsonwebtoken::{decode, encode, Header, Validation};
9-
#[cfg(feature = "use_pem")]
10-
use time::OffsetDateTime;
11-
use wasm_bindgen_test::wasm_bindgen_test;
1212

1313
#[derive(Debug, PartialEq, Eq, Clone, Serialize, Deserialize)]
1414
pub struct Claims {

0 commit comments

Comments
 (0)