Skip to main content

topcoat_session/token/
hash.rs

1use std::ops::Deref;
2
3/// The SHA-256 hash of a [`Token`](crate::Token), identifying a session.
4///
5/// This is the value the application persists (and looks sessions up by):
6/// deriving the token from it is infeasible, so a leaked session database
7/// contains nothing a client could present. Obtain one from
8/// [`start`](crate::start) when creating a session, or
9/// [`token_hash`](crate::token_hash) when resolving the current request's
10/// session.
11#[derive(Debug, Clone, PartialEq, Eq, Hash)]
12pub struct TokenHash([u8; 32]);
13
14impl TokenHash {
15    /// Creates a hash from raw bytes, typically loaded back out of the
16    /// application's session storage.
17    #[must_use]
18    pub fn new(bytes: [u8; 32]) -> Self {
19        Self(bytes)
20    }
21}
22
23impl Deref for TokenHash {
24    type Target = [u8; 32];
25
26    fn deref(&self) -> &Self::Target {
27        &self.0
28    }
29}