From e59b2b91df906a7dd9a61dad0f0d2efd5e354b86 Mon Sep 17 00:00:00 2001 From: Ayush Singh Date: Sun, 22 Jan 2023 00:17:04 +0530 Subject: [PATCH] Update base64 to 0.21 Signed-off-by: Ayush Singh --- Cargo.toml | 3 +-- src/common/authorization.rs | 8 +++++--- src/common/sec_websocket_accept.rs | 5 +++-- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index b49c86e7..28fd6ea0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -19,8 +19,7 @@ members = [ [dependencies] http = "0.2.0" headers-core = { version = "0.2", path = "./headers-core" } -base64 = "0.13" -bitflags = "1.0" +base64 = "0.21.3" bytes = "1" mime = "0.3.14" sha1 = "0.10" diff --git a/src/common/authorization.rs b/src/common/authorization.rs index 734bc6e2..e62f2fd9 100644 --- a/src/common/authorization.rs +++ b/src/common/authorization.rs @@ -1,6 +1,7 @@ //! Authorization header and types. -use base64; +use base64::engine::general_purpose::STANDARD as ENGINE; +use base64::Engine; use bytes::Bytes; use util::HeaderValueString; @@ -158,7 +159,8 @@ impl Credentials for Basic { let bytes = &value.as_bytes()["Basic ".len()..]; let non_space_pos = bytes.iter().position(|b| *b != b' ')?; let bytes = &bytes[non_space_pos..]; - let bytes = base64::decode(bytes).ok()?; + + let bytes = ENGINE.decode(bytes).ok()?; let decoded = String::from_utf8(bytes).ok()?; @@ -169,7 +171,7 @@ impl Credentials for Basic { fn encode(&self) -> HeaderValue { let mut encoded = String::from("Basic "); - base64::encode_config_buf(&self.decoded, base64::STANDARD, &mut encoded); + ENGINE.encode_string(&self.decoded, &mut encoded); let bytes = Bytes::from(encoded); HeaderValue::from_maybe_shared(bytes) diff --git a/src/common/sec_websocket_accept.rs b/src/common/sec_websocket_accept.rs index 9e9176f0..89ec7c07 100644 --- a/src/common/sec_websocket_accept.rs +++ b/src/common/sec_websocket_accept.rs @@ -1,4 +1,5 @@ -use base64; +use base64::engine::general_purpose::STANDARD as ENGINE; +use base64::Engine; use bytes::Bytes; use sha1::{Digest, Sha1}; @@ -39,7 +40,7 @@ fn sign(key: &[u8]) -> SecWebsocketAccept { let mut sha1 = Sha1::default(); sha1.update(key); sha1.update(&b"258EAFA5-E914-47DA-95CA-C5AB0DC85B11"[..]); - let b64 = Bytes::from(base64::encode(&sha1.finalize())); + let b64 = Bytes::from(ENGINE.encode(&sha1.finalize())); let val = ::HeaderValue::from_maybe_shared(b64).expect("base64 is a valid value");