Skip to content

Commit

Permalink
feat: implement From bytes for SecWebsocketKey
Browse files Browse the repository at this point in the history
  • Loading branch information
tottoto committed Apr 2, 2024
1 parent 2ffcd7a commit cf34fe9
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/common/sec_websocket_key.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,19 @@
use base64::{engine::general_purpose::STANDARD, Engine};
use http::HeaderValue;

/// The `Sec-Websocket-Key` header.
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
pub struct SecWebsocketKey(pub(super) http::HeaderValue);
pub struct SecWebsocketKey(pub(super) HeaderValue);

derive_header! {
SecWebsocketKey(_),
name: SEC_WEBSOCKET_KEY
}

impl From<[u8; 16]> for SecWebsocketKey {
fn from(bytes: [u8; 16]) -> Self {
let mut value = HeaderValue::from_str(&STANDARD.encode(bytes)).unwrap();
value.set_sensitive(true);
Self(value)
}
}

0 comments on commit cf34fe9

Please sign in to comment.