aboutsummaryrefslogtreecommitdiff
path: root/lockchain-core/src/users/tokens.rs
blob: 3f29af175aa3e432fefd91cbab8c184266e4140a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
use crate::crypto::{Key, KeyType};
use serde::{Serialize, Deserialize};
use std::borrow::Cow;

/// An authentication token that can be compared in constant time
///
/// ```
/// use lockchain_core::users::Token;
/// let t1 = Token::new();
/// let t2 = Token::new();
///
/// // Will fail, but no expose failure length
/// assert!(t1 != t2);
/// ```
#[derive(Debug, PartialEq, Eq, Serialize, Deserialize, Clone)]
pub struct Token {
    inner: Key,
}

impl Token {
    pub fn new() -> Self {
        Self {
            inner: Key::new(KeyType::Aes128),
        }
    }
}

/// A request wrapper around a username and token
///
/// This structure is accepted by most Vault-trait
/// functions to reduce the number of paramters required.auth
///
/// Because `Request` objects are short-lived and numerous,
/// they only deal with references to the original
/// username and token data.
#[derive(PartialEq, Eq, Serialize, Deserialize)]
pub struct Request<'outer> {
    username: &'outer str,
    token: Cow<'outer, Token>,
}