Skip to content

Commit

Permalink
Bump base64 to 0.21
Browse files Browse the repository at this point in the history
This is the same version `reqwest` uses, which avoids depending on two
versions.
  • Loading branch information
ramosbugs committed Mar 21, 2024
1 parent e9f603c commit db0ea44
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Cargo-1.65.lock
Original file line number Diff line number Diff line change
Expand Up @@ -966,7 +966,7 @@ version = "5.0.0-alpha.3"
dependencies = [
"anyhow",
"async-std",
"base64 0.13.1",
"base64 0.21.7",
"chrono",
"curl",
"getrandom",
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ name = "wunderlist"
required-features = ["reqwest-blocking"]

[dependencies]
base64 = "0.13"
base64 = "0.21"
thiserror = "1.0"
http = "0.2"
rand = "0.8"
Expand Down
3 changes: 2 additions & 1 deletion src/endpoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use crate::{
CONTENT_TYPE_FORMENCODED, CONTENT_TYPE_JSON,
};

use base64::prelude::*;
use http::header::{ACCEPT, AUTHORIZATION, CONTENT_TYPE};
use http::{HeaderValue, StatusCode};
use serde::de::DeserializeOwned;
Expand Down Expand Up @@ -119,7 +120,7 @@ pub(crate) fn endpoint_request<'a>(
let urlencoded_secret: String =
form_urlencoded::byte_serialize(secret.secret().as_bytes()).collect();
let b64_credential =
base64::encode(format!("{}:{}", &urlencoded_id, urlencoded_secret));
BASE64_STANDARD.encode(format!("{}:{}", &urlencoded_id, urlencoded_secret));
builder = builder.header(
AUTHORIZATION,
HeaderValue::from_str(&format!("Basic {}", &b64_credential)).unwrap(),
Expand Down
7 changes: 4 additions & 3 deletions src/types.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use base64::prelude::*;
use rand::{thread_rng, Rng};
use serde::{Deserialize, Serialize};
use sha2::{Digest, Sha256};
Expand Down Expand Up @@ -465,7 +466,7 @@ impl PkceCodeChallenge {
// This implies 32-96 octets of random data to be base64 encoded.
assert!((32..=96).contains(&num_bytes));
let random_bytes: Vec<u8> = (0..num_bytes).map(|_| thread_rng().gen::<u8>()).collect();
PkceCodeVerifier::new(base64::encode_config(random_bytes, base64::URL_SAFE_NO_PAD))
PkceCodeVerifier::new(BASE64_URL_SAFE_NO_PAD.encode(random_bytes))
}

/// Generate a SHA-256 PKCE code challenge from the supplied PKCE code verifier.
Expand All @@ -480,7 +481,7 @@ impl PkceCodeChallenge {
assert!(code_verifier.secret().len() >= 43 && code_verifier.secret().len() <= 128);

let digest = Sha256::digest(code_verifier.secret().as_bytes());
let code_challenge = base64::encode_config(digest, base64::URL_SAFE_NO_PAD);
let code_challenge = BASE64_URL_SAFE_NO_PAD.encode(digest);

Self {
code_challenge,
Expand Down Expand Up @@ -560,7 +561,7 @@ new_secret_type![
/// * `num_bytes` - Number of random bytes to generate, prior to base64-encoding.
pub fn new_random_len(num_bytes: u32) -> Self {
let random_bytes: Vec<u8> = (0..num_bytes).map(|_| thread_rng().gen::<u8>()).collect();
CsrfToken::new(base64::encode_config(random_bytes, base64::URL_SAFE_NO_PAD))
CsrfToken::new(BASE64_URL_SAFE_NO_PAD.encode(random_bytes))
}
}
];
Expand Down

0 comments on commit db0ea44

Please sign in to comment.