diff --git a/Cargo.toml b/Cargo.toml index c808eb77b..2f22793eb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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" diff --git a/src/util.rs b/src/util.rs index 018db307f..aff9e87a6 100644 --- a/src/util.rs +++ b/src/util.rs @@ -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 }