Skip to content

scan

Finds the well-known credentials in text.

The text is cut into words made of letters, digits, _, - and ., and each word is checked with detect; a PEM private key header line (-----BEGIN ... PRIVATE KEY-----) is found as a whole line. Quotes, =, :, spaces and other punctuation around a token are not part of it. Like detect this is a format check: expect false negatives for formats it does not know, and use it as a safety net, not as your only protection.

use helpers4::secret::scan;

Cargo feature secret (enabled by default). To compile only this module:

cargo add helpers4 --no-default-features --features secret

or in Cargo.toml:

[dependencies]
helpers4 = { version = "0.0.6", default-features = false, features = ["secret"] }
pub fn scan(text: &str) -> Vec<Finding>
ParameterTypeDescription
text&strThe text to search, such as a file or a log.

Vec<Finding> — The findings in the order they appear, with their byte ranges in text.

use helpers4::secret::{scan, TokenKind};

let findings = scan("AWS_KEY=\"AKIAIOSFODNN7EXAMPLE\" # and nothing else");
assert_eq!(findings.len(), 1);
assert_eq!(findings[0].kind(), TokenKind::AwsAccessKey);

src/secret/scan.rs