Skip to content

Commit

Permalink
Switch from base64 to data-encoding
Browse files Browse the repository at this point in the history
It offers the same functionality with a simpler API and lower MSRV.
  • Loading branch information
nickelc committed Mar 29, 2024
1 parent 68a3f58 commit 5d19c09
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 12 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ __rustls = ["dep:hyper-rustls", "dep:tokio-rustls", "dep:rustls", "__tls", "dep:
__internal_proxy_sys_no_cache = []

[dependencies]
base64 = "0.21"
data-encoding = "2.5"
http = "1"
url = "2.2"
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

0 comments on commit 5d19c09

Please sign in to comment.