use compact_str::CompactString;
use std::borrow::Cow;
use std::fmt;
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
#[non_exhaustive]
pub enum Category {
Email,
Name,
Phone,
CreditCard,
Ssn,
IpV4,
IpV6,
MacAddress,
Hostname,
ContainerId,
Uuid,
Jwt,
AuthToken,
FilePath,
WindowsSid,
Url,
AwsArn,
AzureResourceId,
Custom(CompactString),
}
impl fmt::Display for Category {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Category::Custom(name) => write!(f, "custom:{name}"),
other => f.write_str(other.as_str()),
}
}
}
impl Category {
#[must_use]
pub fn as_str(&self) -> &str {
match self {
Category::Email => "email",
Category::Name => "name",
Category::Phone => "phone",
Category::CreditCard => "credit_card",
Category::Ssn => "ssn",
Category::IpV4 => "ipv4",
Category::IpV6 => "ipv6",
Category::MacAddress => "mac_address",
Category::Hostname => "hostname",
Category::ContainerId => "container_id",
Category::Uuid => "uuid",
Category::Jwt => "jwt",
Category::AuthToken => "auth_token",
Category::FilePath => "file_path",
Category::WindowsSid => "windows_sid",
Category::Url => "url",
Category::AwsArn => "aws_arn",
Category::AzureResourceId => "azure_resource_id",
Category::Custom(name) => name.as_str(),
}
}
#[must_use]
pub fn domain_tag_hmac(&self) -> Cow<'_, str> {
match self {
Category::Custom(name) => Cow::Owned(format!("custom:{name}")),
other => Cow::Borrowed(other.as_str()),
}
}
}