pub(crate) const GENERIC_PREFIX: &str = "generic-";
pub(crate) const ENTROPY_PREFIX: &str = "entropy-";
pub(crate) const REASSEMBLED_SUFFIX: &str = ":reassembled";
#[inline]
pub(crate) fn policy_detector_id(detector_id: &str) -> &str {
detector_id
.strip_suffix(REASSEMBLED_SUFFIX)
.unwrap_or(detector_id) }
pub(crate) const GENERIC_SECRET: &str = "generic-secret";
pub(crate) const GENERIC_KEYWORD_SECRET: &str = "generic-keyword-secret";
pub(crate) const GENERIC_API_KEY: &str = "generic-api-key";
#[cfg(test)]
pub(crate) const GENERIC_PASSWORD: &str = "generic-password";
pub(crate) const ENTROPY: &str = "entropy";
pub(crate) const PRIVATE_KEY: &str = "private-key";
pub(crate) const AWS_ACCESS_KEY: &str = "aws-access-key";
pub(crate) const GITHUB_CLASSIC_PAT: &str = "github-classic-pat";
pub(crate) const GITHUB_PAT_FINE_GRAINED: &str = "github-pat-fine-grained";
pub(crate) const GITLAB_PERSONAL_ACCESS_TOKEN: &str = "gitlab-personal-access-token";
pub(crate) const NPM_ACCESS_TOKEN: &str = "npm-access-token";
pub(crate) const PYPI_API_TOKEN: &str = "pypi-api-token";
pub(crate) const SLACK_BOT_TOKEN: &str = "slack-bot-token";
pub(crate) const STRIPE_SECRET_KEY: &str = "stripe-secret-key";
#[inline]
pub(crate) fn is_generic_detector(detector_id: &str) -> bool {
detector_id.starts_with(GENERIC_PREFIX)
}
#[inline]
pub(crate) fn is_entropy_detector(detector_id: &str) -> bool {
detector_id == ENTROPY || detector_id.starts_with(ENTROPY_PREFIX)
}
#[inline]
pub(crate) fn is_private_key_fallback(detector_id: &str) -> bool {
detector_id == PRIVATE_KEY
}
#[inline]
#[cfg(test)]
pub(crate) fn is_structural_password_slot_detector(detector_id: &str) -> bool {
keyhog_core::detector_spec_by_id(detector_id).is_some_and(|spec| spec.structural_password_slot)
}
#[inline]
pub(crate) fn is_generic_or_entropy_detector(detector_id: &str) -> bool {
is_generic_detector(detector_id) || is_entropy_detector(detector_id)
}
#[inline]
pub(crate) fn is_service_anchored_detector(detector_id: &str) -> bool {
keyhog_core::detector_spec_by_id(detector_id).map_or_else(
|| {
!is_generic_detector(detector_id)
&& !is_entropy_detector(detector_id)
&& !is_private_key_fallback(detector_id)
},
|detector| {
detector.kind != keyhog_core::DetectorKind::Phase2Generic && !detector.private_key_block
},
)
}
#[inline]
pub(crate) fn is_private_key_block_detector(detector_id: &str) -> bool {
keyhog_core::detector_spec_by_id(detector_id).is_some_and(|spec| spec.private_key_block)
}
#[cfg(test)]
#[path = "../tests/unit/detector_id_corpus_guard.rs"]
mod detector_id_corpus_guard;