MCPcopy Create free account
hub / github.com/NodeDB-Lab/nodedb / verify

Method verify

nodedb/src/control/security/auth_apikey.rs:171–192  ·  view source on GitHub ↗

Verify an `nda_` token. Returns the key record if valid.

(&self, token: &str)

Source from the content-addressed store, hash-verified

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

Calls 9

collectMethod · 0.80
hash_secretFunction · 0.70
hex_encodeFunction · 0.70
now_secsFunction · 0.70
lenMethod · 0.45
readMethod · 0.45
getMethod · 0.45
is_validMethod · 0.45
cloneMethod · 0.45