pub struct PublicContext(/* private fields */);Expand description
Type-safe wrapper for public-facing error contexts.
§Trust Boundary Enforcement
This newtype prevents InternalContextField from being accidentally displayed
externally. The type system ensures only PublicContextField variants can be
wrapped here, and the Display implementation is the sole external rendering path.
§Construction
lie(): Always available for deceptive public messagestruth(): Only available withexternal_signalingfeature enabled
§Safety Properties
- Cannot be constructed from
InternalContext - Cannot implicitly convert to string (must use
as_str()orDisplay) - Implements
ZeroizeOnDropfor owned string data
§No Clone/Copy Policy
Single-owner semantics prevent duplicate public messages from existing simultaneously, reducing risk of inconsistent external responses.
Implementations§
Source§impl PublicContext
impl PublicContext
Sourcepub fn lie(message: impl Into<Cow<'static, str>>) -> Self
pub fn lie(message: impl Into<Cow<'static, str>>) -> Self
Create a deceptive public context for external display.
§Use Case
Default constructor for honeypot deployments. Deceptive messages are explicitly labeled and auditable in internal logs.
§Performance
Accepts Cow<'static, str> to allow zero-allocation when passed string
literals: PublicContext::lie("error") allocates nothing.
Sourcepub fn truth(message: impl Into<Cow<'static, str>>) -> Self
pub fn truth(message: impl Into<Cow<'static, str>>) -> Self
Create a truthful public context for external display.
§Availability
This method only exists when external_signaling feature is enabled.
Without this feature, all public contexts must be deceptive, enforcing
operational security at compile time rather than runtime configuration.
§Use Case
For honeypots that intentionally signal some authentic errors to appear more legitimate (e.g., benign input validation failures).
Sourcepub const fn classification(&self) -> &'static str
pub const fn classification(&self) -> &'static str
Trait Implementations§
Source§impl Debug for PublicContext
impl Debug for PublicContext
Source§fn fmt(&self, f: &mut Formatter<'_>) -> Result
fn fmt(&self, f: &mut Formatter<'_>) -> Result
Debug representation for internal logging and diagnostics.
§Redaction Strategy
Deceptive payloads are redacted in debug output to prevent lies from being aggregated as factual data in log analysis systems that may:
- Export logs to external SIEMs
- Send logs to cloud providers
- Aggregate metrics across trust boundaries
This prevents deceptive error messages from polluting statistical analysis.
Source§impl Display for PublicContext
impl Display for PublicContext
Source§fn fmt(&self, f: &mut Formatter<'_>) -> Result
fn fmt(&self, f: &mut Formatter<'_>) -> Result
Render public context for external display.
This is the primary interface for converting error contexts into externally-visible strings (HTTP responses, external APIs, etc.).
§Security Note
This implementation is intentionally simple and does not check context
classification. The type system guarantees only PublicContextField
variants can be wrapped in this type, so all outputs are safe by construction.