Verify an `nda_` token. Returns the key record if valid.
(&self, token: &str)
| 169 | |
| 170 | /// Verify an `nda_` token. Returns the key record if valid. |
| 171 | pub fn verify(&self, token: &str) -> Option<AuthApiKey> { |
| 172 | let stripped = token.strip_prefix("nda_")?; |
| 173 | let parts: Vec<&str> = stripped.splitn(2, '_').collect(); |
| 174 | if parts.len() != 2 { |
| 175 | return None; |
| 176 | } |
| 177 | let secret = parts[1]; |
| 178 | let secret_hash = hash_secret(secret); |
| 179 | let hash_hex = hex_encode(&secret_hash); |
| 180 | |
| 181 | let idx = self.hash_index.read().unwrap_or_else(|p| p.into_inner()); |
| 182 | let key_id = idx.get(&hash_hex)?; |
| 183 | |
| 184 | let keys = self.keys.read().unwrap_or_else(|p| p.into_inner()); |
| 185 | let key = keys.get(key_id)?; |
| 186 | |
| 187 | if !key.is_valid(now_secs()) { |
| 188 | return None; |
| 189 | } |
| 190 | |
| 191 | Some(key.clone()) |
| 192 | } |
| 193 | |
| 194 | /// Update last-used tracking after successful verification. |
| 195 | /// No-op on keys that are no longer valid — prevents audit trails from |