From 5d19c091064973e601242f8bf43c601e9dbe21eb Mon Sep 17 00:00:00 2001 From: Constantin Nickel Date: Fri, 29 Mar 2024 09:06:17 +0100 Subject: [PATCH] Switch from `base64` to `data-encoding` It offers the same functionality with a simpler API and lower MSRV. --- Cargo.toml | 2 +- src/util.rs | 21 ++++++++++----------- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 955156290..c8fcbcd3a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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" diff --git a/src/util.rs b/src/util.rs index 88a5200e6..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 }