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]
18pub enum PasetoError {
20 Base64DecodeError,
22 InvalidKey,
24 InvalidToken,
26 CryptoError,
28 ClaimsError,
30 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}