Skip to content

Commit 6d886ca

Browse files
authored
Fix deprecated use of base64::en/decode (#1216)
Change: base64endecode
1 parent a02fc3a commit 6d886ca

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

hyper_cgi/src/bin/hyper-cgi-test-server.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ use futures::FutureExt;
99

1010
use hyper::server::Server;
1111

12+
// Import the base64 crate Engine trait anonymously so we can
13+
// call its methods without adding to the namespace.
14+
use base64::engine::general_purpose::STANDARD as BASE64;
15+
use base64::engine::Engine as _;
16+
1217
#[macro_export]
1318
macro_rules! some_or {
1419
($e:expr, $b:block) => {
@@ -51,7 +56,7 @@ pub fn parse_auth(req: &hyper::Request<hyper::Body>) -> Option<(String, String)>
5156
let u = ok_or!(String::from_utf8(line[6..].to_vec()), {
5257
return None;
5358
});
54-
let decoded = ok_or!(base64::decode(&u), {
59+
let decoded = ok_or!(BASE64.decode(&u), {
5560
return None;
5661
});
5762
let s = ok_or!(String::from_utf8(decoded), {

josh-proxy/src/auth.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
// Import the base64 crate Engine trait anonymously so we can
2+
// call its methods without adding to the namespace.
3+
use base64::engine::general_purpose::STANDARD as BASE64;
4+
use base64::engine::Engine as _;
5+
16
lazy_static! {
27
static ref AUTH: std::sync::Mutex<std::collections::HashMap<Handle, Header>> =
38
std::sync::Mutex::new(std::collections::HashMap::new());
@@ -42,7 +47,7 @@ impl Handle {
4247
let u = josh::ok_or!(String::from_utf8(line[6..].to_vec()), {
4348
return Ok(("".to_string(), "".to_string()));
4449
});
45-
let decoded = josh::ok_or!(base64::decode(u), {
50+
let decoded = josh::ok_or!(BASE64.decode(u), {
4651
return Ok(("".to_string(), "".to_string()));
4752
});
4853
let s = josh::ok_or!(String::from_utf8(decoded), {
@@ -54,7 +59,7 @@ impl Handle {
5459
}
5560

5661
pub fn add_auth(token: &str) -> josh::JoshResult<Handle> {
57-
let header = hyper::header::HeaderValue::from_str(&format!("Basic {}", base64::encode(token)))?;
62+
let header = hyper::header::HeaderValue::from_str(&format!("Basic {}", BASE64.encode(token)))?;
5863
let hp = Handle {
5964
hash: format!(
6065
"{:?}",

0 commit comments

Comments
 (0)