pub struct TerminalRedactionPolicy {
pub enabled: bool,
pub replacement: String,
pub max_text_bytes: usize,
pub rules: Vec<TerminalRedactionRule>,
}Expand description
Policy for byte limiting, literal rules, and secret-like key redaction.
Self::redact_text first truncates the input at a UTF-8 boundary, then,
when enabled, applies explicit rules in order followed by case-insensitive
heuristics for password, passwd, token, secret, api_key, apikey,
authorization, and bearer. Heuristic values end at whitespace or one of
;&,)]. This is a best-effort scrubber, not a complete secret detector.
§Examples
use ailloli_ui_terminal_core::TerminalRedactionPolicy;
let policy = TerminalRedactionPolicy::default();
assert_eq!(policy.redact_text("token=abc; ok"), "token=[redacted]; ok");Fields§
§enabled: boolWhether literal and heuristic replacement is active.
replacement: StringReplacement used by heuristic rules; empty strings remove matched values.
max_text_bytes: usizeMaximum source byte count retained by Self::redact_text.
A "...[truncated]" suffix is appended after limiting, so the returned
string can exceed this value. 0 returns only that suffix for non-empty input.
rules: Vec<TerminalRedactionRule>Ordered literal replacement rules applied before heuristics.
Implementations§
Source§impl TerminalRedactionPolicy
impl TerminalRedactionPolicy
Sourcepub fn disabled() -> Self
pub fn disabled() -> Self
Returns a policy that limits text but performs no secret replacement.
§Examples
use ailloli_ui_terminal_core::TerminalRedactionPolicy;
let policy = TerminalRedactionPolicy::disabled();
assert_eq!(policy.redact_text("token=visible"), "token=visible");
assert_eq!(policy.max_text_bytes, 8_192);Sourcepub fn redact_text(&self, text: &str) -> String
pub fn redact_text(&self, text: &str) -> String
Limits and, when enabled, redacts a UTF-8 string.
Empty literal patterns are ignored. Non-empty explicit rules are applied sequentially, so a replacement produced by one rule can be matched by a later rule. Truncation occurs before replacement and preserves a UTF-8 boundary, but the truncation suffix is additional to the byte limit.
§Examples
use ailloli_ui_terminal_core::{TerminalRedactionPolicy, TerminalRedactionRule};
let mut policy = TerminalRedactionPolicy::default();
policy.rules.push(TerminalRedactionRule::exact("host", "internal.example"));
assert_eq!(
policy.redact_text("host=internal.example password=hunter2"),
"host=[redacted] password=[redacted]",
);Sourcepub fn redact_bytes(
&self,
bytes: &[u8],
max_bytes: usize,
) -> (Vec<u8>, bool, bool)
pub fn redact_bytes( &self, bytes: &[u8], max_bytes: usize, ) -> (Vec<u8>, bool, bool)
Limits and optionally redacts an arbitrary byte payload.
The returned tuple is (bytes, changed_by_redaction, truncated_by_max_bytes).
With redaction disabled, retained bytes are returned exactly, including
invalid UTF-8. With redaction enabled, retained bytes are decoded lossily,
then passed through Self::redact_text; consequently invalid UTF-8 or
the policy’s independent text limit can make the second flag true.
max_bytes == 0 retains no input bytes.
§Examples
use ailloli_ui_terminal_core::TerminalRedactionPolicy;
let policy = TerminalRedactionPolicy::default();
let (bytes, changed, truncated) = policy.redact_bytes(b"token=secret", 64);
assert_eq!(bytes, b"token=[redacted]");
assert!(changed);
assert!(!truncated);Trait Implementations§
Source§impl Clone for TerminalRedactionPolicy
impl Clone for TerminalRedactionPolicy
Source§fn clone(&self) -> TerminalRedactionPolicy
fn clone(&self) -> TerminalRedactionPolicy
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for TerminalRedactionPolicy
impl Debug for TerminalRedactionPolicy
Source§impl Default for TerminalRedactionPolicy
impl Default for TerminalRedactionPolicy
Source§fn default() -> Self
fn default() -> Self
Enables heuristic redaction with an 8,192-byte text limit.
§Examples
use ailloli_ui_terminal_core::TerminalRedactionPolicy;
let policy = TerminalRedactionPolicy::default();
assert!(policy.enabled);
assert_eq!(policy.replacement, "[redacted]");
assert!(policy.rules.is_empty());