Skip to content

Commit 07b7891

Browse files
authored
Remove rand dependency in favor of tungstenite fn (#1691)
Get rid of rand dependency in favor of tungstenite builtin fn Found https://docs.rs/tungstenite/latest/tungstenite/handshake/client/fn.generate_key.html which means we can let upstream tungstenite be in charge of bumping rand. Signed-off-by: clux <[email protected]>
1 parent 267c224 commit 07b7891

File tree

3 files changed

+2
-11
lines changed

3 files changed

+2
-11
lines changed

kube-client/Cargo.toml

+1-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ rustls-tls = ["rustls", "hyper-rustls", "hyper-http-proxy?/rustls-tls-native-roo
1717
webpki-roots = ["hyper-rustls/webpki-roots"]
1818
aws-lc-rs = ["rustls?/aws-lc-rs"]
1919
openssl-tls = ["openssl", "hyper-openssl"]
20-
ws = ["client", "tokio-tungstenite", "rand", "kube-core/ws", "tokio/macros"]
20+
ws = ["client", "tokio-tungstenite", "kube-core/ws", "tokio/macros"]
2121
kubelet-debug = ["ws", "kube-core/kubelet-debug"]
2222
oauth = ["client", "tame-oauth"]
2323
oidc = ["client", "form_urlencoded"]
@@ -72,7 +72,6 @@ tower = { workspace = true, features = ["buffer", "filter", "util"], optional =
7272
tower-http = { workspace = true, features = ["auth", "map-response-body", "trace"], optional = true }
7373
hyper-timeout = { workspace = true, optional = true }
7474
tame-oauth = { workspace = true, features = ["gcp"], optional = true }
75-
rand = { workspace = true, optional = true }
7675
secrecy = { workspace = true }
7776
tracing = { workspace = true, features = ["log"], optional = true }
7877
hyper-openssl = { workspace = true, features = ["client-legacy"], optional = true }

kube-client/src/client/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ impl Client {
206206
http::header::SEC_WEBSOCKET_VERSION,
207207
HeaderValue::from_static("13"),
208208
);
209-
let key = upgrade::sec_websocket_key();
209+
let key = tokio_tungstenite::tungstenite::handshake::client::generate_key();
210210
parts.headers.insert(
211211
http::header::SEC_WEBSOCKET_KEY,
212212
key.parse().expect("valid header value"),

kube-client/src/client/upgrade.rs

-8
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,3 @@ pub fn verify_response(res: &Response<Body>, key: &str) -> Result<(), UpgradeCon
8686

8787
Ok(())
8888
}
89-
90-
/// Generate a random key for the `Sec-WebSocket-Key` header.
91-
/// This must be nonce consisting of a randomly selected 16-byte value in base64.
92-
pub fn sec_websocket_key() -> String {
93-
use base64::Engine;
94-
let r: [u8; 16] = rand::random();
95-
base64::engine::general_purpose::STANDARD.encode(r)
96-
}

0 commit comments

Comments
 (0)