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
use AsRef;
use PhantomData;
use Deref;
/// A nonce key for use in PASETO algorithms
///
/// Key sizes for nonces are either 32 or 24 bytes in size
///
/// Nonces can be specified directly for testing or randomly in production
/// # Example usage
/// ```
/// # #[cfg(feature = "v4_local")]
/// # {
/// use serde_json::json;
/// use rusty_paseto::core::*;
///
/// let key = PasetoSymmetricKey::<V4, Local>::from(Key::<32>::try_from("707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f")?);
/// // generate a random nonce with
/// let nonce = Key::<32>::try_new_random()?;
/// let nonce = PasetoNonce::<V4, Local>::from(&nonce);
///
/// let payload = json!({"data": "this is a secret message", "exp":"2022-01-01T00:00:00+00:00"}).to_string();
/// let payload = payload.as_str();
/// let payload = Payload::from(payload);
///
/// //create a public v4 token
/// let token = Paseto::<V4, Local>::builder()
/// .set_payload(payload)
/// .try_encrypt(&key, &nonce)?;
/// # }
/// # Ok::<(),anyhow::Error>(())
/// ```