Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch from base64 to data-encoding #1861

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ __rustls-ring = ["hyper-rustls?/ring", "tokio-rustls?/ring", "rustls?/ring", "qu
__internal_proxy_sys_no_cache = []

[dependencies]
base64 = "0.22"
data-encoding = "2.5"
http = "1"
url = "2.4"
bytes = "1.0"
Expand Down
21 changes: 10 additions & 11 deletions src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,18 @@ where
U: std::fmt::Display,
P: std::fmt::Display,
{
use base64::prelude::BASE64_STANDARD;
use base64::write::EncoderWriter;
use std::io::Write;
use data_encoding::BASE64;

let mut buf = b"Basic ".to_vec();
{
let mut encoder = EncoderWriter::new(&mut buf, &BASE64_STANDARD);
let _ = write!(encoder, "{username}:");
if let Some(password) = password {
let _ = write!(encoder, "{password}");
}
let mut buf = String::from("Basic ");
let mut input = username.to_string();
input.push(':');
if let Some(password) = password {
input.push_str(&password.to_string());
}
let mut header = HeaderValue::from_bytes(&buf).expect("base64 is always valid HeaderValue");
BASE64.encode_append(input.as_bytes(), &mut buf);

let mut header =
HeaderValue::from_bytes(buf.as_bytes()).expect("base64 is always valid HeaderValue");
header.set_sensitive(true);
header
}
Expand Down