paseto_core/
lib.rs

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