pub struct Tainted<T>(/* private fields */);Expand description
Caller-controlled value that has not yet crossed a serialization
boundary. Deliberately does not implement fmt::Display;
the only way to project a Tainted<String> into a serialized
surface is Tainted::escape_for.
Implements fmt::Debug (which tracing ?value calls) because
Debug quote-wraps and escapes control bytes, so emitting a
Tainted<String> via ?value is safe in a way %value is not.
The propagation rule is enforced by visibility, not by the type
system: the inner field is pub(crate) so only this crate can
build a Tainted<String>. Downstream crates receive
Tainted<String> from ConnStringSanitizer::parse and cannot
peel it; they must call Tainted::escape_for or
Tainted::expose_secret (the latter named loudly to surface in
review).
Implementations§
Source§impl<T> Tainted<T>
impl<T> Tainted<T>
Sourcepub fn new(value: T) -> Tainted<T>
pub fn new(value: T) -> Tainted<T>
Build a Tainted from a caller-supplied value. This is the
one place the type system loses ground; every site that calls
it should be reviewable.
Sourcepub fn expose_secret(&self) -> &T
pub fn expose_secret(&self) -> &T
Escape hatch for callers that need the raw inner. Named
loudly so a grep / review / lint flags it. Prefer
Tainted::escape_for.
Sourcepub fn into_inner(self) -> T
pub fn into_inner(self) -> T
Consuming variant of Tainted::expose_secret.
Source§impl Tainted<String>
impl Tainted<String>
Sourcepub const MAX_ESCAPED_LEN: usize
pub const MAX_ESCAPED_LEN: usize
Hard cap on the size of any escaped boundary projection.
Mirrors the max_uri_bytes default in crate::conn_string
(8 KiB) so a tainted value that fits the parser also fits the
boundary projection.
Sourcepub fn escape_for(&self, boundary: Boundary) -> Result<EscapedFor, EscapeError>
pub fn escape_for(&self, boundary: Boundary) -> Result<EscapedFor, EscapeError>
Project the tainted value into the named Boundary’s
escape contract. Returns EscapedFor tagged with the
boundary, so a header setter can statically refuse a value
that was escaped for a log line.
Trait Implementations§
Source§impl<T> PartialEq for Tainted<T>where
T: PartialEq,
impl<T> PartialEq for Tainted<T>where
T: PartialEq,
impl<T> Eq for Tainted<T>where
T: Eq,
impl<T> StructuralPartialEq for Tainted<T>
Auto Trait Implementations§
impl<T> Freeze for Tainted<T>where
T: Freeze,
impl<T> RefUnwindSafe for Tainted<T>where
T: RefUnwindSafe,
impl<T> Send for Tainted<T>where
T: Send,
impl<T> Sync for Tainted<T>where
T: Sync,
impl<T> Unpin for Tainted<T>where
T: Unpin,
impl<T> UnsafeUnpin for Tainted<T>where
T: UnsafeUnpin,
impl<T> UnwindSafe for Tainted<T>where
T: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request