Struct TerminalRedactionPolicy

Source
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: bool

Whether literal and heuristic replacement is active.

§replacement: String

Replacement used by heuristic rules; empty strings remove matched values.

§max_text_bytes: usize

Maximum 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

Source

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);
Source

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]",
);
Source

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

Source§

fn clone(&self) -> TerminalRedactionPolicy

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for TerminalRedactionPolicy

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for TerminalRedactionPolicy

Source§

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());
Source§

impl<'de> Deserialize<'de> for TerminalRedactionPolicy

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl PartialEq for TerminalRedactionPolicy

Source§

fn eq(&self, other: &TerminalRedactionPolicy) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for TerminalRedactionPolicy

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl Eq for TerminalRedactionPolicy

Source§

impl StructuralPartialEq for TerminalRedactionPolicy

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,