1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
//! PASETO v4 (libsodium)
//!
//! ```
//! use paseto_v4_sodium::{SignedToken, UnsignedToken, SecretKey, PublicKey};
//! use paseto_json::{RegisteredClaims, Time, HasExpiry, FromIssuer, ForSubject, Validate};
//! use std::time::Duration;
//!
//! // init libsodium
//! paseto_v4_sodium::ensure_init().expect("libsodium should initialise successfully");
//!
//! // create a new keypair
//! let secret_key = SecretKey::random().unwrap();
//! let public_key = secret_key.public_key();
//!
//! // create a set of token claims
//! let claims = RegisteredClaims::now(Duration::from_secs(3600))
//! .from_issuer("https://paseto.conrad.cafe/".to_string())
//! .for_subject("conradludgate".to_string());
//!
//! // create and sign a new token
//! let signed_token = UnsignedToken::new(claims).sign(&secret_key).unwrap();
//!
//! // serialize the token.
//! let token = signed_token.to_string();
//! // "v4.public.eyJpc3MiOiJodHRwczovL3Bhc2V0by5jb25yYWQuY2FmZS8iLCJzdWIiOiJjb25yYWRsdWRnYXRlIiwiYXVkIjpudWxsLCJleHAiOiIyMDI1LTA5LTIwVDEyOjAxOjEzLjcyMjQ3OVoiLCJuYmYiOiIyMDI1LTA5LTIwVDExOjAxOjEzLjcyMjQ3OVoiLCJpYXQiOiIyMDI1LTA5LTIwVDExOjAxOjEzLjcyMjQ3OVoiLCJqdGkiOm51bGx9N7O1CAXQpQ3rpxhq6xFZt32z27VSL8suiek38-5W4LRGr1tDmKcP0_xrlp5-kdE6o7B_K8KU-6Fwmu0hzrkiDQ"
//!
//! // serialize the public key.
//! let key = public_key.to_string();
//! // "k4.public.xRPdFzRvXY-H-6L3S2I3_TmdMKu6XwLKLSR10lZ-yfk"
//!
//! // ...
//!
//! // parse the token
//! let signed_token: SignedToken<RegisteredClaims> = token.parse().unwrap();
//!
//! // parse the key
//! let public_key: PublicKey = key.parse().unwrap();
//!
//! // verify the token signature and validate the claims.
//! let validation = Time::valid_now()
//! .and_then(HasExpiry)
//! .and_then(FromIssuer("https://paseto.conrad.cafe/"))
//! .and_then(ForSubject("conradludgate"));
//! let verified_token = signed_token.verify(&public_key, &validation).unwrap();
//! ```
/// Low level implementation primitives.
pub use PasetoError;
/// A token with publically readable data, but not yet verified
pub type SignedToken<M, F = > = SignedToken;
/// A token with secret data
pub type EncryptedToken<M, F = > = EncryptedToken;
/// A [`SignedToken`] that has been verified
pub type UnsignedToken<M, F = > = UnsignedToken;
/// An [`EncryptedToken`] that has been decrypted
pub type UnencryptedToken<M, F = > = UnencryptedToken;
/// Private key used for [`encryption`](UnencryptedToken::encrypt) and [`decryption`](EncryptedToken::decrypt)
pub type LocalKey = LocalKey;
/// Public key used for signature [`verification`](SignedToken::verify)
pub type PublicKey = PublicKey;
/// Private key used for token [`signing`](UnsignedToken::sign)
pub type SecretKey = SecretKey;
/// A short ID for a key.
pub type KeyId<K> = KeyId;
/// A plaintext encoding of a key.
pub type KeyText<K> = KeyText;
/// Public key used for [`sealing`](LocalKey::seal) a [`LocalKey`] for a recipient.
pub type PkePublicKey = PkePublicKey;
/// Private key used for [`unsealing`](SealedKey::unseal) a sealed [`LocalKey`].
pub type PkeSecretKey = PkeSecretKey;
/// An asymmetrically encrypted [`LocalKey`].
pub type SealedKey = SealedKey;
pub use ensure_init;