paseto_v1/core/
mod.rs

1#[cfg(feature = "decrypting")]
2mod local;
3#[cfg(feature = "pie-wrap")]
4mod pie_wrap;
5#[cfg(feature = "pke")]
6mod pke;
7#[cfg(feature = "verifying")]
8mod public;
9#[cfg(feature = "pbkw")]
10mod pw_wrap;
11
12use paseto_core::version;
13
14pub struct V1;
15
16#[cfg(feature = "signing")]
17#[derive(Clone)]
18pub struct SecretKey(rsa::pss::SigningKey<sha2::Sha384>);
19#[cfg(feature = "verifying")]
20#[derive(Clone)]
21pub struct PublicKey(rsa::pss::VerifyingKey<sha2::Sha384>);
22
23#[cfg(feature = "decrypting")]
24#[derive(Clone)]
25pub struct LocalKey([u8; 32]);
26
27impl version::Version for V1 {
28    const HEADER: &'static str = "v1";
29    const PASERK_HEADER: &'static str = "k1";
30}
31
32#[cfg(feature = "id")]
33impl paseto_core::paserk::IdVersion for V1 {
34    fn hash_key(key_header: &'static str, key_data: &[u8]) -> [u8; 33] {
35        use sha2::{Digest, Sha384};
36
37        let mut ctx = Sha384::new();
38        ctx.update(b"k1");
39        ctx.update(key_header.as_bytes());
40        ctx.update(key_data);
41        let hash = ctx.finalize();
42        assert_eq!(hash.len(), 48);
43
44        hash[..33].try_into().unwrap()
45    }
46}