MCPcopy Create free account
hub / github.com/NVIDIA/OpenShell / longest_known_token_match

Method longest_known_token_match

crates/openshell-core/src/secrets.rs:386–403  ·  view source on GitHub ↗
(
        &'a self,
        text: &str,
        abs_start: usize,
    )

Source from the content-addressed store, hash-verified

384 }
385
386 fn longest_known_token_match<'a>(
387 &'a self,
388 text: &str,
389 abs_start: usize,
390 ) -> Option<(usize, &'a str)> {
391 let suffix = &text[abs_start..];
392 self.by_placeholder
393 .keys()
394 .filter_map(|placeholder| {
395 if !suffix.starts_with(placeholder) {
396 return None;
397 }
398 let key_end = abs_start + placeholder.len();
399 let boundary_ok = token_boundary_ok(text, abs_start, key_end, placeholder);
400 boundary_ok.then_some((key_end, placeholder.as_str()))
401 })
402 .max_by_key(|(_, placeholder)| placeholder.len())
403 }
404
405 /// Decode a Base64-encoded Basic auth token, resolve any placeholders in
406 /// the decoded `username:password` string, and re-encode.

Callers 1

credential_token_atMethod · 0.80

Calls 3

token_boundary_okFunction · 0.85
lenMethod · 0.80
as_strMethod · 0.45

Tested by

no test coverage detected