common_access_token/
constants.rs

1//! # Constants for Common Access Token
2//!
3//! This module provides centralized constants used throughout the Common Access Token library.
4//! It includes constants for CAT-specific claim keys, URI components, match types, and more.
5
6/// CAT-specific claim keys
7pub mod cat_keys {
8    /// Common Access Token Replay (catreplay) claim key
9    pub const CATREPLAY: i32 = 308;
10    /// Common Access Token Probability of Rejection (catpor) claim key
11    pub const CATPOR: i32 = 309;
12    /// Common Access Token Version (catv) claim key
13    pub const CATV: i32 = 310;
14    /// Common Access Token Network IP (catnip) claim key
15    pub const CATNIP: i32 = 311;
16    /// Common Access Token URI (catu) claim key
17    pub const CATU: i32 = 312;
18    /// Common Access Token Methods (catm) claim key
19    pub const CATM: i32 = 313;
20    /// Common Access Token ALPN (catalpn) claim key
21    pub const CATALPN: i32 = 314;
22    /// Common Access Token Header (cath) claim key
23    pub const CATH: i32 = 315;
24    /// Common Access Token Geographic ISO3166 (catgeoiso3166) claim key
25    pub const CATGEOISO3166: i32 = 316;
26    /// Common Access Token Geographic Coordinate (catgeocoord) claim key
27    pub const CATGEOCOORD: i32 = 317;
28    /// Common Access Token Altitude (catgeoalt) claim key
29    pub const CATGEOALT: i32 = 318;
30    /// Common Access Token TLS Public Key (cattpk) claim key
31    pub const CATTPK: i32 = 319;
32    /// Common Access Token If Data (catifdata) claim key
33    pub const CATIFDATA: i32 = 320;
34    /// Common Access Token DPoP Settings (catdpop) claim key
35    pub const CATDPOP: i32 = 321;
36    /// Common Access Token If (catif) claim key
37    pub const CATIF: i32 = 322;
38    /// Common Access Token Renewal (catr) claim key
39    pub const CATR: i32 = 323;
40    /// Common Access Token TLS Fingerprint (cattprint) claim key
41    pub const CATTPRINT: i32 = 324;
42}
43
44/// URI component identifiers for CATU claim
45pub mod uri_components {
46    /// Scheme (RFC 3986 Section 3.1)
47    pub const SCHEME: i32 = 0;
48    /// Host (RFC 3986 Section 3.2.2)
49    pub const HOST: i32 = 1;
50    /// Port (RFC 3986 Section 3.2.3)
51    pub const PORT: i32 = 2;
52    /// Path (RFC 3986 Section 3.3)
53    pub const PATH: i32 = 3;
54    /// Query (RFC 3986 Section 3.4)
55    pub const QUERY: i32 = 4;
56    /// Parent path
57    pub const PARENT_PATH: i32 = 5;
58    /// Filename
59    pub const FILENAME: i32 = 6;
60    /// Stem
61    pub const STEM: i32 = 7;
62    /// Extension
63    pub const EXTENSION: i32 = 8;
64}
65
66/// Match types for CATU claim
67pub mod match_types {
68    /// Exact text match
69    pub const EXACT: i32 = 0;
70    /// Prefix match
71    pub const PREFIX: i32 = 1;
72    /// Suffix match
73    pub const SUFFIX: i32 = 2;
74    /// Contains match
75    pub const CONTAINS: i32 = 3;
76    /// Regular expression match
77    pub const REGEX: i32 = 4;
78    /// SHA-256 match
79    pub const SHA256: i32 = -1;
80    /// SHA-512/256 match
81    pub const SHA512_256: i32 = -2;
82}
83
84/// Renewal types for CATR claim
85pub mod renewal_types {
86    /// Automatic renewal
87    pub const AUTOMATIC: i32 = 0;
88    /// Cookie renewal
89    pub const COOKIE: i32 = 1;
90    /// Header renewal
91    pub const HEADER: i32 = 2;
92    /// Redirect renewal
93    pub const REDIRECT: i32 = 3;
94}
95
96/// Renewal parameter labels for CATR claim
97pub mod renewal_params {
98    /// Renewal type
99    pub const TYPE: i32 = 0;
100    /// Expiration extension
101    pub const EXPADD: i32 = 1;
102    /// Renewal deadline
103    pub const DEADLINE: i32 = 2;
104    /// Name for cookie
105    pub const COOKIE_NAME: i32 = 3;
106    /// Name for header
107    pub const HEADER_NAME: i32 = 4;
108    /// Additional cookie parameters
109    pub const COOKIE_PARAMS: i32 = 5;
110    /// Additional header parameters
111    pub const HEADER_PARAMS: i32 = 6;
112    /// Status code for redirects
113    pub const STATUS_CODE: i32 = 7;
114}
115
116/// CATREPLAY values
117pub mod replay_values {
118    /// Replay is permitted
119    pub const PERMITTED: i32 = 0;
120    /// Replay is prohibited
121    pub const PROHIBITED: i32 = 1;
122    /// Reuse-detection
123    pub const REUSE_DETECTION: i32 = 2;
124}
125
126// Parameter labels for CATTPRINT claim
127pub mod tprint_params {
128    /// TLS Fingerprint Type
129    pub const FINGERPRINT_TYPE: i32 = 0;
130    /// TLS Fingerprint Value
131    pub const FINGERPRINT_VALUE: i32 = 1;
132}
133
134#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
135#[repr(i64)] // Use i64 to match CBOR Integer type used in serialization
136pub enum FingerprintType {
137    JA3 = 0,
138    JA3S = 1,
139    JA4 = 2,
140    JA4S = 3,
141    JA4H = 4,
142    JA4L = 5,
143    JA4X = 6,
144    JA4SSH = 7,
145    JA4T = 8,
146    JA4TS = 9,
147    JA4TSCAN = 10,
148    JA4D = 11,
149    JA4D6 = 12,
150}
151
152impl FingerprintType {
153    pub fn as_str(&self) -> &'static str {
154        match self {
155            FingerprintType::JA3 => "JA3",
156            FingerprintType::JA3S => "JA3S",
157            FingerprintType::JA4 => "JA4",
158            FingerprintType::JA4S => "JA4S",
159            FingerprintType::JA4H => "JA4H",
160            FingerprintType::JA4L => "JA4L",
161            FingerprintType::JA4X => "JA4X",
162            FingerprintType::JA4SSH => "JA4SSH",
163            FingerprintType::JA4T => "JA4T",
164            FingerprintType::JA4TS => "JA4TS",
165            FingerprintType::JA4TSCAN => "JA4TScan", 
166            FingerprintType::JA4D => "JA4D",
167            FingerprintType::JA4D6 => "JA4D6",
168        }
169    }
170
171    pub fn from_i64(val: i64) -> Option<Self> {
172        match val {
173            0 => Some(FingerprintType::JA3),
174            1 => Some(FingerprintType::JA3S),
175            2 => Some(FingerprintType::JA4),
176            3 => Some(FingerprintType::JA4S),
177            4 => Some(FingerprintType::JA4H),
178            5 => Some(FingerprintType::JA4L),
179            6 => Some(FingerprintType::JA4X),
180            7 => Some(FingerprintType::JA4SSH),
181            8 => Some(FingerprintType::JA4T),
182            9 => Some(FingerprintType::JA4TS),
183            10 => Some(FingerprintType::JA4TSCAN),
184            11 => Some(FingerprintType::JA4D),
185            12 => Some(FingerprintType::JA4D6),
186            _ => None,
187        }
188    }
189}
190
191impl std::fmt::Display for FingerprintType {
192    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
193        write!(f, "{}", self.as_str())
194    }
195}
196
197/// CWT claim keys as defined in RFC 8392
198pub mod cwt_keys {
199    /// Issuer claim key
200    pub const ISS: i32 = 1;
201    /// Subject claim key
202    pub const SUB: i32 = 2;
203    /// Audience claim key
204    pub const AUD: i32 = 3;
205    /// Expiration time claim key
206    pub const EXP: i32 = 4;
207    /// Not before claim key
208    pub const NBF: i32 = 5;
209    /// Issued at claim key
210    pub const IAT: i32 = 6;
211    /// CWT ID claim key
212    pub const CTI: i32 = 7;
213}
214
215/// COSE header parameter labels
216pub mod cose_labels {
217    /// Algorithm (used in protected header)
218    pub const ALG: i32 = 1;
219    /// Key identifier (used in protected or unprotected header)
220    pub const KID: i32 = 4;
221}
222
223/// COSE algorithm identifiers
224pub mod cose_algs {
225    /// HMAC with SHA-256 (COSE algorithm identifier: 5)
226    pub const HMAC_SHA_256: i32 = 5;
227}