#[derive(Debug, Clone, PartialEq, Eq)] pub struct SessionKey(pub String); impl TryFrom for SessionKey { type Error = &'static str; fn try_from(val: String) -> Result { 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 for SessionKey { fn as_ref(&self) -> &str { &self.0 } } impl From for String { fn from(key: SessionKey) -> Self { key.0 } }