feat: init
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
#[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
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user