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 Jun 1, 2023
1 parent cec216b commit 295e1e4
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 @@ -80,7 +80,7 @@ __rustls = ["hyper-rustls", "tokio-rustls", "rustls", "__tls", "rustls-pemfile"]
__internal_proxy_sys_no_cache = []

[dependencies]
base64 = "0.21"
data-encoding = "2.4"
http = "0.2"
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 295e1e4

Please sign in to comment.