Update base64 dependency to the latest 0.21

This commit is contained in:
Michal Nazarewicz 2023-01-19 19:17:45 +01:00
parent 6627109984
commit 101a830668
11 changed files with 41 additions and 26 deletions

View File

@ -2,6 +2,7 @@
## Unreleased - 2022-xx-xx
- Minimum supported Rust version (MSRV) is now 1.59.
- Upgrade `base64` dependency to `0.21`.
## 3.0.0 - 2022-07-24

View File

@ -37,7 +37,7 @@ actix-rt = "2.2"
actix-server = "2"
awc = { version = "3", default-features = false }
base64 = "0.13"
base64 = "0.21"
bytes = "1"
futures-core = { version = "0.3.17", default-features = false }
http = "0.2.5"

View File

@ -25,6 +25,9 @@
[#2955]: https://github.com/actix/actix-web/pull/2955
[#2956]: https://github.com/actix/actix-web/pull/2956
### Changed
- Upgrade `base64` dependency to `0.21`.
## 3.2.2 - 2022-09-11
### Changed

View File

@ -86,7 +86,7 @@ h2 = { version = "0.3.9", optional = true }
# websockets
local-channel = { version = "0.1", optional = true }
base64 = { version = "0.13", optional = true }
base64 = { version = "0.21", optional = true }
rand = { version = "0.8", optional = true }
sha1 = { version = "0.10", optional = true }

View File

@ -244,7 +244,12 @@ pub fn hash_key(key: &[u8]) -> [u8; 28] {
};
let mut hash_b64 = [0; 28];
let n = base64::encode_config_slice(hash, base64::STANDARD, &mut hash_b64);
let n = base64::Engine::encode_slice(
&base64::engine::general_purpose::STANDARD,
hash,
&mut hash_b64,
)
.unwrap();
assert_eq!(n, 28);
hash_b64

View File

@ -3,6 +3,7 @@
## Unreleased - 2022-xx-xx
### Changed
- Minimum supported Rust version (MSRV) is now 1.59 due to transitive `time` dependency.
- Upgrade `base64` dependency to `0.21`.
## 3.0.1 - 2022-08-25

View File

@ -63,7 +63,7 @@ actix-tls = { version = "3", features = ["connect", "uri"] }
actix-utils = "3"
ahash = "0.7"
base64 = "0.13"
base64 = "0.21"
bytes = "1"
cfg-if = "1"
derive_more = "0.99.5"

View File

@ -204,14 +204,11 @@ where
where
N: fmt::Display,
{
let auth = match password {
Some(password) => format!("{}:{}", username, password),
None => format!("{}:", username),
};
self.add_default_header((
header::AUTHORIZATION,
format!("Basic {}", base64::encode(auth)),
))
let auth = base64::Engine::encode(
&base64::engine::general_purpose::STANDARD,
format!("{}:{}", username, password.unwrap_or("")),
);
self.add_default_header((header::AUTHORIZATION, format!("Basic {auth}")))
}
/// Set client wide HTTP bearer authentication header

View File

@ -234,12 +234,11 @@ impl ClientRequest {
///
/// If no password is needed, just provide an empty string.
pub fn basic_auth(self, username: impl fmt::Display, password: impl fmt::Display) -> Self {
let auth = format!("{}:{}", username, password);
self.insert_header((
header::AUTHORIZATION,
format!("Basic {}", base64::encode(auth)),
))
let auth = base64::Engine::encode(
&base64::engine::general_purpose::STANDARD,
format!("{}:{}", username, password),
);
self.insert_header((header::AUTHORIZATION, format!("Basic {auth}")))
}
/// Set HTTP bearer authentication header

View File

@ -232,11 +232,11 @@ impl WebsocketsRequest {
where
U: fmt::Display,
{
let auth = match password {
Some(password) => format!("{}:{}", username, password),
None => format!("{}:", username),
};
self.header(AUTHORIZATION, format!("Basic {}", base64::encode(auth)))
let auth = base64::Engine::encode(
&base64::engine::general_purpose::STANDARD,
format!("{}:{}", username, password.unwrap_or("")),
);
self.header(AUTHORIZATION, format!("Basic {auth}"))
}
/// Set HTTP bearer authentication header
@ -320,8 +320,10 @@ impl WebsocketsRequest {
// Generate a random key for the `Sec-WebSocket-Key` header which is a base64-encoded
// (see RFC 4648 §4) value that, when decoded, is 16 bytes in length (RFC 6455 §1.3).
let sec_key: [u8; 16] = rand::random();
let key = base64::encode(sec_key);
let key = base64::Engine::encode(
&base64::engine::general_purpose::STANDARD,
rand::random::<[u8; 16]>(),
);
self.head.headers.insert(
header::SEC_WEBSOCKET_KEY,

View File

@ -777,13 +777,20 @@ async fn client_basic_auth() {
App::new().route(
"/",
web::to(|req: HttpRequest| {
let auth = format!(
"Basic {}",
base64::Engine::encode(
&base64::engine::general_purpose::STANDARD,
"username:password",
)
);
if req
.headers()
.get(header::AUTHORIZATION)
.unwrap()
.to_str()
.unwrap()
== format!("Basic {}", base64::encode("username:password"))
== auth
{
HttpResponse::Ok()
} else {