Skip to main content

SecretString

Struct SecretString 

Source
pub struct SecretString { /* private fields */ }
Expand description

A resolved secret value, held briefly in process memory.

Construct via SecretString::new; read via SecretString::expose. Zeroes its buffer on drop. Has no Debug / Display / Serialize implementations; printing one through any of those paths produces <redacted>.

Implementations§

Source§

impl SecretString

Source

pub fn new(value: String) -> Self

Wrap a UTF-8 string as a secret. Takes ownership of the input bytes so the caller can’t keep a parallel handle.

Source

pub fn from_bytes(bytes: Vec<u8>) -> Self

Wrap an arbitrary byte slice (for binary secrets — keys, etc.).

Source

pub fn expose(&self) -> Result<&str, Utf8Error>

Borrow the secret as &str. Returns an error if the bytes aren’t valid UTF-8 — the value-injection path requires UTF-8. Whole-file deploy uses SecretString::expose_bytes instead.

Source

pub fn expose_bytes(&self) -> &[u8]

Borrow the secret as raw bytes. For whole-file flows where UTF-8 isn’t a guarantee.

Source

pub fn len(&self) -> usize

Length of the secret in bytes. Safe to log.

Source

pub fn is_empty(&self) -> bool

True iff the secret is empty.

Source

pub fn contains_newline(&self) -> bool

True iff the secret value contains at least one newline. Used by §3.4’s multi-line refusal: value-injection requires single-line values, and this check is the gate. Reading this flag does not expose the bytes anywhere — it’s a property of the value, not the value itself.

Trait Implementations§

Source§

impl Debug for SecretString

Source§

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

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

impl Drop for SecretString

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> Same for T

Source§

type Output = T

Should always be Self
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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more