paseto_core/
lib.rs

1pub mod encodings;
2pub mod pae;
3pub mod tokens;
4pub mod version;
5pub use rand_core;
6pub mod key;
7
8mod sealed {
9    pub trait Sealed {}
10}
11
12#[derive(Debug)]
13#[non_exhaustive]
14/// Error returned for all PASETO and PASERK operations that can fail
15pub enum PasetoError {
16    /// The token was not Base64 URL encoded correctly.
17    Base64DecodeError,
18    /// Could not decode the provided key string
19    InvalidKey,
20    /// The PASETO or PASERK was not of a valid form
21    InvalidToken,
22    /// Could not verify/decrypt the PASETO/PASERK.
23    CryptoError,
24    /// There was an error with payload processing
25    PayloadError(std::io::Error),
26}
27
28impl std::error::Error for PasetoError {
29    fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
30        match self {
31            PasetoError::PayloadError(x) => Some(x),
32            _ => None,
33        }
34    }
35}
36
37impl std::fmt::Display for PasetoError {
38    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
39        match self {
40            PasetoError::Base64DecodeError => f.write_str("The token could not be base64 decoded"),
41            PasetoError::InvalidKey => f.write_str("Could not parse the key"),
42            PasetoError::InvalidToken => f.write_str("Could not parse the token"),
43            PasetoError::CryptoError => f.write_str("Token signature could not be validated"),
44            PasetoError::PayloadError(x) => {
45                write!(f, "there was an error with the payload encoding: {x}")
46            }
47        }
48    }
49}