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
impl SecretString
Sourcepub fn new(value: String) -> Self
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.
Sourcepub fn from_bytes(bytes: Vec<u8>) -> Self
pub fn from_bytes(bytes: Vec<u8>) -> Self
Wrap an arbitrary byte slice (for binary secrets — keys, etc.).
Sourcepub fn expose(&self) -> Result<&str, Utf8Error>
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.
Sourcepub fn expose_bytes(&self) -> &[u8] ⓘ
pub fn expose_bytes(&self) -> &[u8] ⓘ
Borrow the secret as raw bytes. For whole-file flows where UTF-8 isn’t a guarantee.
Sourcepub fn contains_newline(&self) -> bool
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.