pub trait TokenRng: CryptoRng {
    fn generate_token(&mut self) -> Result<String, Error>;
Expand description

Used to generate CSRF tokens.

This trait is used to generate a token that can be used as a CSRF token. It is implemented for all CSRNG (Cryptographically Secure RNG) types. This should not be implemented directly; instead, implement CryptoRng and RngCore instead.

Implementors of this trait should generate a token that’s difficult to guess and is safe to store as a cookie. For blanket implementations, this is 32 bytes of random data, encoded as base64 without padding.

Required Methods

Generates a CSRF token.


Returns an error if the underlying RNG fails to generate a token.