Skip to content

Commit 968a10a

Browse files
Update base64 to 0.21.0 (#278)
* chore: update base64 to 0.21.0
1 parent 4008c8b commit 968a10a

File tree

7 files changed

+16
-9
lines changed

7 files changed

+16
-9
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ include = ["src/**/*", "benches/**/*", "tests/**/*", "LICENSE", "README.md", "CH
1515
serde_json = "1.0"
1616
serde = {version = "1.0", features = ["derive"] }
1717
ring = { version = "0.16.5", features = ["std"] }
18-
base64 = "0.13"
18+
base64 = "0.21.0"
1919
# For PEM decoding
2020
pem = {version = "1", optional = true}
2121
simple_asn1 = {version = "0.6", optional = true}

src/decoding.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use base64::{engine::general_purpose::STANDARD, Engine};
12
use serde::de::DeserializeOwned;
23

34
use crate::algorithms::AlgorithmFamily;
@@ -56,7 +57,7 @@ impl DecodingKey {
5657

5758
/// If you're using HMAC with a base64 encoded secret, use this.
5859
pub fn from_base64_secret(secret: &str) -> Result<Self> {
59-
let out = base64::decode(secret)?;
60+
let out = STANDARD.decode(secret)?;
6061
Ok(DecodingKey { family: AlgorithmFamily::Hmac, kind: DecodingKeyKind::SecretOrDer(out) })
6162
}
6263

src/encoding.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use base64::{engine::general_purpose::STANDARD, Engine};
12
use serde::ser::Serialize;
23

34
use crate::algorithms::AlgorithmFamily;
@@ -24,7 +25,7 @@ impl EncodingKey {
2425

2526
/// If you have a base64 HMAC secret, use that.
2627
pub fn from_base64_secret(secret: &str) -> Result<Self> {
27-
let out = base64::decode(secret)?;
28+
let out = STANDARD.decode(secret)?;
2829
Ok(EncodingKey { family: AlgorithmFamily::Hmac, content: out })
2930
}
3031

src/header.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use std::result;
22

3+
use base64::{engine::general_purpose::STANDARD, Engine};
34
use serde::{Deserialize, Serialize};
45

56
use crate::algorithms::Algorithm;
@@ -93,7 +94,9 @@ impl Header {
9394
Ok(self
9495
.x5c
9596
.as_ref()
96-
.map(|b64_certs| b64_certs.iter().map(base64::decode).collect::<result::Result<_, _>>())
97+
.map(|b64_certs| {
98+
b64_certs.iter().map(|x| STANDARD.decode(x)).collect::<result::Result<_, _>>()
99+
})
97100
.transpose()?)
98101
}
99102
}

src/jwk.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -370,13 +370,13 @@ impl JwkSet {
370370
#[cfg(test)]
371371
mod tests {
372372
use crate::jwk::{AlgorithmParameters, JwkSet, OctetKeyType};
373+
use crate::serialization::b64_encode;
373374
use crate::Algorithm;
374375
use serde_json::json;
375376

376377
#[test]
377378
fn check_hs256() {
378-
let key =
379-
base64::encode_config("abcdefghijklmnopqrstuvwxyz012345", base64::URL_SAFE_NO_PAD);
379+
let key = b64_encode("abcdefghijklmnopqrstuvwxyz012345");
380380
let jwks_json = json!({
381381
"keys": [
382382
{

src/serialization.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1+
use base64::{engine::general_purpose::URL_SAFE_NO_PAD, Engine};
12
use serde::{Deserialize, Serialize};
23

34
use crate::errors::Result;
45

56
pub(crate) fn b64_encode<T: AsRef<[u8]>>(input: T) -> String {
6-
base64::encode_config(input, base64::URL_SAFE_NO_PAD)
7+
URL_SAFE_NO_PAD.encode(input)
78
}
89

910
pub(crate) fn b64_decode<T: AsRef<[u8]>>(input: T) -> Result<Vec<u8>> {
10-
base64::decode_config(input, base64::URL_SAFE_NO_PAD).map_err(|e| e.into())
11+
URL_SAFE_NO_PAD.decode(input).map_err(|e| e.into())
1112
}
1213

1314
/// Serializes a struct to JSON and encodes it in base64

tests/header/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use base64::{engine::general_purpose::STANDARD, Engine};
12
use jsonwebtoken::Header;
23

34
static CERT_CHAIN: [&str; 3] = include!("cert_chain.json");
@@ -14,7 +15,7 @@ fn x5c_der_empty_chain() {
1415
#[test]
1516
fn x5c_der_valid_chain() {
1617
let der_chain: Vec<Vec<u8>> =
17-
CERT_CHAIN.iter().map(base64::decode).collect::<Result<_, _>>().unwrap();
18+
CERT_CHAIN.iter().map(|x| STANDARD.decode(x)).collect::<Result<_, _>>().unwrap();
1819

1920
let x5c = Some(CERT_CHAIN.iter().map(ToString::to_string).collect());
2021
let header = Header { x5c, ..Default::default() };

0 commit comments

Comments
 (0)