use core::fmt;
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
#[non_exhaustive]
pub enum Kind {
Email,
CreditCard,
IpV4,
IpV6,
Jwt,
UsSsn,
MacAddress,
AwsAccessKey,
PhoneNumber,
UrlCredentials,
GitHubToken,
SlackToken,
StripeKey,
GoogleApiKey,
OpenAiKey,
PrivateKey,
Iban,
GenericSecret,
Custom(&'static str),
}
impl Kind {
pub fn label(&self) -> &str {
match self {
Kind::Email => "EMAIL",
Kind::CreditCard => "CREDIT_CARD",
Kind::IpV4 => "IPV4",
Kind::IpV6 => "IPV6",
Kind::Jwt => "JWT",
Kind::UsSsn => "US_SSN",
Kind::MacAddress => "MAC",
Kind::AwsAccessKey => "AWS_ACCESS_KEY",
Kind::PhoneNumber => "PHONE",
Kind::UrlCredentials => "URL_CREDENTIALS",
Kind::GitHubToken => "GITHUB_TOKEN",
Kind::SlackToken => "SLACK_TOKEN",
Kind::StripeKey => "STRIPE_KEY",
Kind::GoogleApiKey => "GOOGLE_API_KEY",
Kind::OpenAiKey => "OPENAI_KEY",
Kind::PrivateKey => "PRIVATE_KEY",
Kind::Iban => "IBAN",
Kind::GenericSecret => "GENERIC_SECRET",
Kind::Custom(name) => name,
}
}
}
impl fmt::Display for Kind {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(self.label())
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Match {
pub kind: Kind,
pub start: usize,
pub end: usize,
}
impl Match {
pub fn new(kind: Kind, start: usize, end: usize) -> Self {
Self { kind, start, end }
}
pub fn len(&self) -> usize {
self.end - self.start
}
pub fn is_empty(&self) -> bool {
self.start == self.end
}
pub fn text<'a>(&self, input: &'a str) -> &'a str {
&input[self.start..self.end]
}
}