Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump base64 to 0.21 #1308

Merged
merged 7 commits into from
Oct 12, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion kube-client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ features = ["client", "rustls-tls", "openssl-tls", "ws", "oauth", "oidc", "jsonp
rustdoc-args = ["--cfg", "docsrs"]

[dependencies]
base64 = { version = "0.20.0", optional = true }
base64 = { version = "0.21.4", optional = true }
chrono = { version = "0.4.23", optional = true, default-features = false }
home = { version = "0.5.4", optional = true }
serde = { version = "1.0.130", features = ["derive"] }
Expand Down
20 changes: 7 additions & 13 deletions kube-client/src/client/auth/oidc.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
use std::collections::HashMap;

use base64::{
alphabet,
engine::{
fast_portable::{FastPortable, FastPortableConfig},
DecodePaddingMode,
},
};
use base64::{alphabet, engine, Engine as _};
clux marked this conversation as resolved.
Show resolved Hide resolved
use chrono::{Duration, TimeZone, Utc};
use form_urlencoded::Serializer;
use http::{
Expand Down Expand Up @@ -137,11 +131,11 @@ pub mod errors {
}
}

const BASE64_ENGINE: FastPortable = FastPortable::from(
const BASE64_ENGINE: engine::GeneralPurpose = engine::GeneralPurpose::new(
clux marked this conversation as resolved.
Show resolved Hide resolved
&alphabet::URL_SAFE,
FastPortableConfig::new()
engine::GeneralPurposeConfig::new()
.with_decode_allow_trailing_bits(true)
.with_decode_padding_mode(DecodePaddingMode::Indifferent),
.with_decode_padding_mode(engine::DecodePaddingMode::Indifferent),
);

#[derive(Debug)]
Expand All @@ -164,7 +158,7 @@ impl Oidc {
.split('.')
.nth(1)
.ok_or(errors::IdTokenError::InvalidFormat)?;
let payload = base64::decode_engine(part, &BASE64_ENGINE)?;
let payload = BASE64_ENGINE.decode(part)?;
let expiry = serde_json::from_slice::<Claims>(&payload)?.expiry;
let timestamp = Utc
.timestamp_opt(expiry, 0)
Expand Down Expand Up @@ -370,7 +364,7 @@ impl Refresher {
AUTHORIZATION,
format!(
"Basic {}",
base64::encode(format!(
BASE64_ENGINE.encode(format!(
clux marked this conversation as resolved.
Show resolved Hide resolved
"{}:{}",
self.client_id.expose_secret(),
self.client_secret.expose_secret()
Expand Down Expand Up @@ -481,7 +475,7 @@ mod tests {
let invalid_claims_token = format!(
"{}.{}.{}",
token_valid.split_once('.').unwrap().0,
base64::encode(serde_json::to_string(&invalid_claims).unwrap()),
BASE64_ENGINE.encode(serde_json::to_string(&invalid_claims).unwrap()),
nightkr marked this conversation as resolved.
Show resolved Hide resolved
token_valid.rsplit_once('.').unwrap().1,
);
oidc.id_token = invalid_claims_token.into();
Expand Down
4 changes: 2 additions & 2 deletions kube-client/src/client/upgrade.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ pub enum UpgradeConnectionError {
GetPendingUpgrade(#[source] hyper::Error),
}


// Verify upgrade response according to RFC6455.
// Based on `tungstenite` and added subprotocol verification.
pub fn verify_response(res: &Response<Body>, key: &str) -> Result<(), UpgradeConnectionError> {
Expand Down Expand Up @@ -90,6 +89,7 @@ pub fn verify_response(res: &Response<Body>, key: &str) -> Result<(), UpgradeCon
/// Generate a random key for the `Sec-WebSocket-Key` header.
/// This must be nonce consisting of a randomly selected 16-byte value in base64.
pub fn sec_websocket_key() -> String {
use base64::Engine;
let r: [u8; 16] = rand::random();
base64::encode(r)
base64::engine::general_purpose::STANDARD.encode(r)
}
6 changes: 4 additions & 2 deletions kube-client/src/config/file_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,10 @@ fn load_from_base64_or_file<P: AsRef<Path>>(
}

fn load_from_base64(value: &str) -> Result<Vec<u8>, LoadDataError> {
base64::decode(value).map_err(LoadDataError::DecodeBase64)
use base64::Engine;
base64::engine::general_purpose::STANDARD
.decode(value)
.map_err(LoadDataError::DecodeBase64)
}

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


let kubeconfig1 = Kubeconfig::from_yaml(config1)?;
let kubeconfig2 = Kubeconfig::from_yaml(config2)?;
let merged = kubeconfig1.merge(kubeconfig2).unwrap();
Expand Down