Files
gitks/session/storage/session_key.rs
T
2026-06-07 11:30:56 +08:00

29 lines
626 B
Rust

#[derive(Debug, Clone, PartialEq, Eq)]
pub struct SessionKey(pub String);
impl TryFrom<String> for SessionKey {
type Error = &'static str;
fn try_from(val: String) -> Result<Self, Self::Error> {
if val.len() > 4064 {
return Err("session key exceeds 4064 bytes");
}
if val.contains('\0') {
return Err("session key contains null bytes");
}
Ok(SessionKey(val))
}
}
impl AsRef<str> for SessionKey {
fn as_ref(&self) -> &str {
&self.0
}
}
impl From<SessionKey> for String {
fn from(key: SessionKey) -> Self {
key.0
}
}