summaryrefslogtreecommitdiffstats
path: root/vendor/pasetors/src/version.rs
blob: 6e5962c6ad9ef6c1847e3513b2402d35378d50f6 (plain)
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
use crate::errors::Error;

pub(crate) mod private {
    use super::Error;

    // Inside private module to prevent users from implementing this themself.

    /// A given version must implement validation logic in terms of both itself and the kind of key.
    pub trait Version {
        /// Size for a `local` key.
        const LOCAL_KEY: usize;
        /// Size for a secret `public` key.
        const SECRET_KEY: usize;
        /// Size for a public `public` key.
        const PUBLIC_KEY: usize;
        /// Size of the signature for a public token.
        const PUBLIC_SIG: usize;
        /// Size of the nonce for a local token.
        const LOCAL_NONCE: usize;
        /// Size of the authentication tag for a local token.
        const LOCAL_TAG: usize;
        /// Header for a public token for this version.
        const PUBLIC_HEADER: &'static str;
        /// Header for a local token for this version.
        const LOCAL_HEADER: &'static str;
        /// Size of a PASERK ID.
        #[cfg(feature = "paserk")]
        const PASERK_ID: usize;

        /// Validate bytes for a `local` key of a given version.
        fn validate_local_key(key_bytes: &[u8]) -> Result<(), Error>;
        /// Validate bytes for a secret `public` key of a given version.
        fn validate_secret_key(key_bytes: &[u8]) -> Result<(), Error>;
        /// Validate bytes for a public `local` key of a given version.
        fn validate_public_key(key_bytes: &[u8]) -> Result<(), Error>;
    }
}