pub struct SessionToken(/* private fields */);Expand description
A cryptographically random 32-byte session token.
The raw bytes are never transmitted; only the hex-encoded form is written to the signed cookie, and the SHA-256 hash is stored in the database so that a stolen database cannot be used to forge cookies.
Debug and Display both redact the value as "****" to prevent
accidental logging.
Implementations§
Source§impl SessionToken
impl SessionToken
Sourcepub fn from_hex(s: &str) -> Result<Self, &'static str>
pub fn from_hex(s: &str) -> Result<Self, &'static str>
Decode a session token from a 64-character lowercase hex string.
§Errors
Returns Err if the string is not exactly 64 characters or contains
non-hexadecimal characters.
Sourcepub fn as_hex(&self) -> String
pub fn as_hex(&self) -> String
Encode the token as a 64-character lowercase hex string.
This is the value written into the session cookie.
Sourcepub fn hash(&self) -> String
pub fn hash(&self) -> String
Compute the SHA-256 hash of the token and return it as a 64-character lowercase hex string.
This hash is what is stored in sessions.token_hash. Storing only
the hash ensures that a read of the database cannot be used to impersonate
users.
Trait Implementations§
Source§impl Clone for SessionToken
impl Clone for SessionToken
Source§fn clone(&self) -> SessionToken
fn clone(&self) -> SessionToken
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for SessionToken
impl Debug for SessionToken
Source§impl Display for SessionToken
impl Display for SessionToken
Source§impl Hash for SessionToken
impl Hash for SessionToken
Source§impl PartialEq for SessionToken
impl PartialEq for SessionToken
impl Eq for SessionToken
impl StructuralPartialEq for SessionToken
Auto Trait Implementations§
impl Freeze for SessionToken
impl RefUnwindSafe for SessionToken
impl Send for SessionToken
impl Sync for SessionToken
impl Unpin for SessionToken
impl UnsafeUnpin for SessionToken
impl UnwindSafe for SessionToken
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<T> ToStringFallible for Twhere
T: Display,
impl<T> ToStringFallible for Twhere
T: Display,
Source§fn try_to_string(&self) -> Result<String, TryReserveError>
fn try_to_string(&self) -> Result<String, TryReserveError>
ToString::to_string, but without panic on OOM.