diff options
Diffstat (limited to 'lockchain-core/src/users/tokens.rs')
-rw-r--r-- | lockchain-core/src/users/tokens.rs | 43 |
1 files changed, 20 insertions, 23 deletions
diff --git a/lockchain-core/src/users/tokens.rs b/lockchain-core/src/users/tokens.rs index f7226ef..e2b0747 100644 --- a/lockchain-core/src/users/tokens.rs +++ b/lockchain-core/src/users/tokens.rs @@ -1,41 +1,38 @@ -use crypto::random; - -const TOK_SIZE: usize = 64; +use crypto::{random, Key, KeyType}; /// An authentication token that can be compared in constant time -/// +/// /// ``` /// use lockchain_core::users::auth::Token; /// let t1 = Token::new(); /// let t2 = Token::new(); -/// +/// /// // Will fail, but no expose failure length /// assert_eq!(t1, t2); /// ``` +#[derive(PartialEq, Eq, Serialize, Deserialize)] pub struct Token { - tok: [u8; TOK_SIZE], + inner: Key, } impl Token { pub fn new() -> Self { - let v = random::bytes(TOK_SIZE); - let mut tok = [0; TOK_SIZE]; - tok.copy_from_slice(v.as_slice()); - - Self { tok } - } -} - -impl PartialEq for Token { - fn eq(&self, other: &Self) -> bool { - let mut ret = true; - for i in 0..TOK_SIZE { - if self.tok[i] != other.tok[i] { - ret = false; - } + Self { + inner: Key::new(KeyType::Aes128), } - ret } } -impl Eq for Token {} +/// 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: Token, +} |