#[non_exhaustive]pub enum TriggerSource {
Reveal,
WithValue,
Registry,
Serialize,
Custom(&'static str),
}Expand description
The source that triggered access to a canary token.
TriggerSource describes which instrumented API path observed access to a
canary value. It is metadata only and must never contain the canary value
itself.
§Built-in sources
use canarytrap::TriggerSource;
assert_eq!(TriggerSource::Reveal.to_string(), "reveal");
assert_eq!(TriggerSource::WithValue.to_string(), "with-value");
assert_eq!(TriggerSource::Registry.to_string(), "registry");
assert_eq!(TriggerSource::Serialize.to_string(), "serialize");§Custom sources
Custom sources borrow a 'static string and are serialized with a custom:
prefix:
use canarytrap::TriggerSource;
let source = TriggerSource::custom("serde");
assert_eq!(source.to_string(), "custom:serde");§Parsing
Because TriggerSource::Custom stores a 'static string, parsing is
provided for static input through TriggerSource::from_static and
TryFrom<&'static str>. This avoids leaking
dynamically allocated strings.
use canarytrap::TriggerSource;
assert_eq!(
TriggerSource::from_static("reveal"),
Ok(TriggerSource::Reveal)
);
assert_eq!(
TriggerSource::from_static("custom:serde"),
Ok(TriggerSource::Custom("serde"))
);
assert!(TriggerSource::from_static("unknown-source").is_err());Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
Reveal
The canary value was accessed through an explicit reveal API.
WithValue
The canary value was accessed through a closure-based API.
Registry
The canary value was accessed through a registry lookup or dispatch.
Serialize
The canary value was accessed during serialization.
Custom(&'static str)
A user-defined trigger source.
Custom sources are serialized as custom:<name>.
Implementations§
Source§impl TriggerSource
impl TriggerSource
Sourcepub const BUILT_IN: &'static [TriggerSource]
pub const BUILT_IN: &'static [TriggerSource]
Built-in trigger sources supported by this version of the crate.
This list does not include TriggerSource::Custom.
use canarytrap::TriggerSource;
assert!(!TriggerSource::BUILT_IN.is_empty());
assert!(TriggerSource::BUILT_IN.iter().all(TriggerSource::is_builtin));Sourcepub fn custom(name: &'static str) -> Self
pub fn custom(name: &'static str) -> Self
Creates a user-defined trigger source.
The name should be a stable identifier. It is serialized with a
custom: prefix by the Display implementation.
use canarytrap::TriggerSource;
let source = TriggerSource::custom("serde");
assert_eq!(source.to_string(), "custom:serde");Sourcepub fn from_static(input: &'static str) -> Result<Self, ParseTriggerSourceError>
pub fn from_static(input: &'static str) -> Result<Self, ParseTriggerSourceError>
Parses a trigger source from a static string.
Built-in sources are parsed case-insensitively and accept common
aliases. Custom sources must use the custom: prefix.
use canarytrap::TriggerSource;
assert_eq!(
TriggerSource::from_static("with-value"),
Ok(TriggerSource::WithValue)
);
assert_eq!(
TriggerSource::from_static("CUSTOM:serde"),
Ok(TriggerSource::Custom("serde"))
);
assert!(TriggerSource::from_static("not-a-source").is_err());Sourcepub fn as_builtin_str(&self) -> Option<&'static str>
pub fn as_builtin_str(&self) -> Option<&'static str>
Returns the canonical string representation for built-in sources.
Returns None for TriggerSource::Custom.
use canarytrap::TriggerSource;
assert_eq!(TriggerSource::Reveal.as_builtin_str(), Some("reveal"));
assert_eq!(TriggerSource::custom("serde").as_builtin_str(), None);Sourcepub fn as_custom_str(&self) -> Option<&'static str>
pub fn as_custom_str(&self) -> Option<&'static str>
Returns the custom source name if this is a custom trigger source.
use canarytrap::TriggerSource;
assert_eq!(TriggerSource::custom("serde").as_custom_str(), Some("serde"));
assert_eq!(TriggerSource::Reveal.as_custom_str(), None);Sourcepub fn is_builtin(&self) -> bool
pub fn is_builtin(&self) -> bool
Returns true if this is a built-in trigger source.
use canarytrap::TriggerSource;
assert!(TriggerSource::Registry.is_builtin());
assert!(!TriggerSource::custom("serde").is_builtin());