pub enum TokenClass {
Anonymous,
Authorized,
}
Expand description
Classification of CSRF tokens by context.
TokenClass::Anonymous
: Token associated with a pre-session (not yet authenticated).TokenClass::Authorized
: Token bound to an authenticated session.
This distinction helps prevent accidental mixing of tokens. For example, an anonymous token must not be accepted on endpoints that require an authenticated session.
§Examples
Choosing the correct class when generating HMAC tokens:
use actix_csrf_middleware::{generate_hmac_token_ctx, validate_hmac_token_ctx, TokenClass};
let secret = b"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
let session_id = "SID-42";
let t = generate_hmac_token_ctx(TokenClass::Authorized, session_id, secret);
assert!(validate_hmac_token_ctx(TokenClass::Authorized, session_id, t.as_bytes(), secret).unwrap());
Variants§
Anonymous
Token used before authentication.
Authorized
Token used after authentication; tied to a session id.
Trait Implementations§
Source§impl Clone for TokenClass
impl Clone for TokenClass
Source§fn clone(&self) -> TokenClass
fn clone(&self) -> TokenClass
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreSource§impl Debug for TokenClass
impl Debug for TokenClass
Source§impl PartialEq for TokenClass
impl PartialEq for TokenClass
impl Copy for TokenClass
impl Eq for TokenClass
impl StructuralPartialEq for TokenClass
Auto Trait Implementations§
impl Freeze for TokenClass
impl RefUnwindSafe for TokenClass
impl Send for TokenClass
impl Sync for TokenClass
impl Unpin for TokenClass
impl UnwindSafe for TokenClass
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
Mutably borrows from an owned value. Read more
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
Compare self to
key
and return true
if they are equal.