pub fn validate_hmac_token(
session_id: &str,
token: &[u8],
secret: &[u8],
) -> Result<bool, Error>
Expand description
Convenience helper to validate an authorized-class CSRF token.
This is a thin wrapper around validate_hmac_token_ctx
that always uses
TokenClass::Authorized
. It is intended for tests and simple validation flows
where only authorized tokens are expected.
ยงExamples
use actix_csrf_middleware::{
generate_hmac_token_ctx, validate_hmac_token, TokenClass
};
let sid = "SID-xyz";
let secret = b"application-secret-at-least-32-bytes-long";
let token = generate_hmac_token_ctx(TokenClass::Authorized, sid, secret);
assert!(validate_hmac_token(sid, token.as_bytes(), secret).unwrap());