Skip to content

Commit fba2b9d

Browse files
cluxnightkr
andauthored
Bump base64 to 0.21 (#1308)
* Bump base64 to 0.21 Signed-off-by: clux <[email protected]> * Fix build and tests Signed-off-by: clux <[email protected]> * Update kube-client/src/client/auth/oidc.rs Co-authored-by: Natalie <[email protected]> Signed-off-by: Eirik A <[email protected]> * Update kube-client/src/client/auth/oidc.rs Co-authored-by: Natalie <[email protected]> Signed-off-by: Eirik A <[email protected]> * separate names for separate engines Signed-off-by: clux <[email protected]> * actually think this test should use JWT engine Signed-off-by: clux <[email protected]> * avoid polluting import space and use big names in one place Signed-off-by: clux <[email protected]> --------- Signed-off-by: clux <[email protected]> Signed-off-by: Eirik A <[email protected]> Co-authored-by: Natalie <[email protected]>
1 parent 3d7ebdd commit fba2b9d

File tree

4 files changed

+16
-19
lines changed

4 files changed

+16
-19
lines changed

kube-client/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ features = ["client", "rustls-tls", "openssl-tls", "ws", "oauth", "oidc", "jsonp
3737
rustdoc-args = ["--cfg", "docsrs"]
3838

3939
[dependencies]
40-
base64 = { version = "0.20.0", optional = true }
40+
base64 = { version = "0.21.4", optional = true }
4141
chrono = { version = "0.4.23", optional = true, default-features = false }
4242
home = { version = "0.5.4", optional = true }
4343
serde = { version = "1.0.130", features = ["derive"] }

kube-client/src/client/auth/oidc.rs

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,5 @@
11
use std::collections::HashMap;
22

3-
use base64::{
4-
alphabet,
5-
engine::{
6-
fast_portable::{FastPortable, FastPortableConfig},
7-
DecodePaddingMode,
8-
},
9-
};
103
use chrono::{Duration, TimeZone, Utc};
114
use form_urlencoded::Serializer;
125
use http::{
@@ -137,12 +130,14 @@ pub mod errors {
137130
}
138131
}
139132

140-
const BASE64_ENGINE: FastPortable = FastPortable::from(
141-
&alphabet::URL_SAFE,
142-
FastPortableConfig::new()
133+
use base64::Engine as _;
134+
const JWT_BASE64_ENGINE: base64::engine::GeneralPurpose = base64::engine::GeneralPurpose::new(
135+
&base64::alphabet::URL_SAFE,
136+
base64::engine::GeneralPurposeConfig::new()
143137
.with_decode_allow_trailing_bits(true)
144-
.with_decode_padding_mode(DecodePaddingMode::Indifferent),
138+
.with_decode_padding_mode(base64::engine::DecodePaddingMode::Indifferent),
145139
);
140+
use base64::engine::general_purpose::STANDARD as STANDARD_BASE64_ENGINE;
146141

147142
#[derive(Debug)]
148143
pub struct Oidc {
@@ -164,7 +159,7 @@ impl Oidc {
164159
.split('.')
165160
.nth(1)
166161
.ok_or(errors::IdTokenError::InvalidFormat)?;
167-
let payload = base64::decode_engine(part, &BASE64_ENGINE)?;
162+
let payload = JWT_BASE64_ENGINE.decode(part)?;
168163
let expiry = serde_json::from_slice::<Claims>(&payload)?.expiry;
169164
let timestamp = Utc
170165
.timestamp_opt(expiry, 0)
@@ -370,7 +365,7 @@ impl Refresher {
370365
AUTHORIZATION,
371366
format!(
372367
"Basic {}",
373-
base64::encode(format!(
368+
STANDARD_BASE64_ENGINE.encode(format!(
374369
"{}:{}",
375370
self.client_id.expose_secret(),
376371
self.client_secret.expose_secret()
@@ -481,7 +476,7 @@ mod tests {
481476
let invalid_claims_token = format!(
482477
"{}.{}.{}",
483478
token_valid.split_once('.').unwrap().0,
484-
base64::encode(serde_json::to_string(&invalid_claims).unwrap()),
479+
JWT_BASE64_ENGINE.encode(serde_json::to_string(&invalid_claims).unwrap()),
485480
token_valid.rsplit_once('.').unwrap().1,
486481
);
487482
oidc.id_token = invalid_claims_token.into();

kube-client/src/client/upgrade.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ pub enum UpgradeConnectionError {
3939
GetPendingUpgrade(#[source] hyper::Error),
4040
}
4141

42-
4342
// Verify upgrade response according to RFC6455.
4443
// Based on `tungstenite` and added subprotocol verification.
4544
pub fn verify_response(res: &Response<Body>, key: &str) -> Result<(), UpgradeConnectionError> {
@@ -90,6 +89,7 @@ pub fn verify_response(res: &Response<Body>, key: &str) -> Result<(), UpgradeCon
9089
/// Generate a random key for the `Sec-WebSocket-Key` header.
9190
/// This must be nonce consisting of a randomly selected 16-byte value in base64.
9291
pub fn sec_websocket_key() -> String {
92+
use base64::Engine;
9393
let r: [u8; 16] = rand::random();
94-
base64::encode(r)
94+
base64::engine::general_purpose::STANDARD.encode(r)
9595
}

kube-client/src/config/file_config.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -537,7 +537,10 @@ fn load_from_base64_or_file<P: AsRef<Path>>(
537537
}
538538

539539
fn load_from_base64(value: &str) -> Result<Vec<u8>, LoadDataError> {
540-
base64::decode(value).map_err(LoadDataError::DecodeBase64)
540+
use base64::Engine;
541+
base64::engine::general_purpose::STANDARD
542+
.decode(value)
543+
.map_err(LoadDataError::DecodeBase64)
541544
}
542545

543546
fn load_from_file<P: AsRef<Path>>(file: &P) -> Result<Vec<u8>, LoadDataError> {
@@ -768,7 +771,6 @@ users:
768771
client-key-data: aGVsbG8K
769772
"#;
770773

771-
772774
let kubeconfig1 = Kubeconfig::from_yaml(config1)?;
773775
let kubeconfig2 = Kubeconfig::from_yaml(config2)?;
774776
let merged = kubeconfig1.merge(kubeconfig2).unwrap();

0 commit comments

Comments
 (0)