Skip to content

Commit 771a970

Browse files
authored
Replace data-encoding with base64ct (#4294)
2 parents 5aa5771 + 5a4807c commit 771a970

File tree

5 files changed

+10
-16
lines changed

5 files changed

+10
-16
lines changed

Cargo.lock

+2-8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/axum-utils/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ workspace = true
1414
[dependencies]
1515
axum.workspace = true
1616
axum-extra.workspace = true
17+
base64ct.workspace = true
1718
chrono.workspace = true
18-
data-encoding = "2.8.0"
1919
headers.workspace = true
2020
http.workspace = true
2121
icu_locid = "1.5.0"

crates/axum-utils/src/csrf.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
// SPDX-License-Identifier: AGPL-3.0-only
55
// Please see LICENSE in the repository root for full details.
66

7+
use base64ct::{Base64UrlUnpadded, Encoding};
78
use chrono::{DateTime, Duration, Utc};
8-
use data_encoding::{BASE64URL_NOPAD, DecodeError};
99
use mas_storage::Clock;
1010
use rand::{Rng, RngCore, distributions::Standard, prelude::Distribution as _};
1111
use serde::{Deserialize, Serialize};
@@ -35,7 +35,7 @@ pub enum CsrfError {
3535

3636
/// Failed to decode the token
3737
#[error("could not decode CSRF token")]
38-
Decode(#[from] DecodeError),
38+
Decode(#[from] base64ct::Error),
3939
}
4040

4141
/// A CSRF token
@@ -68,7 +68,7 @@ impl CsrfToken {
6868
/// Get the value to include in HTML forms
6969
#[must_use]
7070
pub fn form_value(&self) -> String {
71-
BASE64URL_NOPAD.encode(&self.token[..])
71+
Base64UrlUnpadded::encode_string(&self.token[..])
7272
}
7373

7474
/// Verifies that the value got from an HTML form matches this token
@@ -77,7 +77,7 @@ impl CsrfToken {
7777
///
7878
/// Returns an error if the value in the form does not match this token
7979
pub fn verify_form_value(&self, form_value: &str) -> Result<(), CsrfError> {
80-
let form_value = BASE64URL_NOPAD.decode(form_value.as_bytes())?;
80+
let form_value = Base64UrlUnpadded::decode_vec(form_value)?;
8181
if self.token[..] == form_value {
8282
Ok(())
8383
} else {

crates/oauth2-types/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@ repository.workspace = true
1212
workspace = true
1313

1414
[dependencies]
15+
base64ct.workspace = true
1516
serde.workspace = true
1617
serde_json.workspace = true
1718
language-tags = { version = "0.3.2", features = ["serde"] }
1819
url.workspace = true
1920
serde_with = { version = "3.12.0", features = ["chrono"] }
2021
chrono.workspace = true
2122
sha2 = "0.10.8"
22-
data-encoding = "2.8.0"
2323
thiserror.workspace = true
2424

2525
mas-iana.workspace = true

crates/oauth2-types/src/pkce.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
1111
use std::borrow::Cow;
1212

13-
use data_encoding::BASE64URL_NOPAD;
13+
use base64ct::{Base64UrlUnpadded, Encoding};
1414
use mas_iana::oauth::PkceCodeChallengeMethod;
1515
use serde::{Deserialize, Serialize};
1616
use sha2::{Digest, Sha256};
@@ -98,7 +98,7 @@ impl CodeChallengeMethodExt for PkceCodeChallengeMethod {
9898
let mut hasher = Sha256::new();
9999
hasher.update(verifier.as_bytes());
100100
let hash = hasher.finalize();
101-
let verifier = BASE64URL_NOPAD.encode(&hash);
101+
let verifier = Base64UrlUnpadded::encode_string(&hash);
102102
verifier.into()
103103
}
104104
_ => return Err(CodeChallengeError::UnknownChallengeMethod),

0 commit comments

Comments
 (0)