dynamic_token/
auth_status.rs

1/// Defines authentication status based on the first rule that fails validation
2/// If the decoded string cannot be parsed at all, the status will be None
3#[derive(Debug, Clone, Copy, PartialEq)]
4pub enum AuthStatus {
5  None, // could not be authenticated
6  Ok, // is OK
7  ApiKeyUnmatched, // the API key is missing from the decoded token
8  ApiKeyMisplaced, // the API key is present but in the wrong place
9  UuidRequired, // a correctly formatted UUID is required
10  SecurityNumberRequired, // the random security number is not a valid integer, once decoded
11  TimedOut, // the injected timestamp is older the max age
12  InvalidTimestamp, // the timestamp components are malformed and cannot be converted to a millisecond timestamp
13}
14
15impl AuthStatus {
16  pub fn to_key(&self) -> String {
17    match self {
18      AuthStatus::None => "invalid",
19      AuthStatus::Ok => "ok",
20      AuthStatus::ApiKeyUnmatched => "api_key_unmatched",
21      AuthStatus::ApiKeyMisplaced => "api_key_misplaced",
22      AuthStatus::UuidRequired => "uuid_required",
23      AuthStatus::SecurityNumberRequired => "security_number_required",
24      AuthStatus::TimedOut => "timed_out",
25      AuthStatus::InvalidTimestamp => "invalid_imestamp",
26    }.to_string()
27  }
28}