paseto_core/
lib.rs

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