pub struct PrivateSecret { /* private fields */ }Expand description
A per-run shared secret. Never printed; compare with verify only.
Implementations§
Source§impl PrivateSecret
impl PrivateSecret
Sourcepub fn generate() -> Result<Self, SecretError>
pub fn generate() -> Result<Self, SecretError>
A fresh secret from the OS random source.
Sourcepub fn from_hex(text: &str) -> Result<Self, SecretError>
pub fn from_hex(text: &str) -> Result<Self, SecretError>
Parse the text form (exactly SECRET_HEX_LEN lowercase hex digits; no surrounding
whitespace).
Sourcepub fn expose(&self) -> &str
pub fn expose(&self) -> &str
The text form, for putting in a frame or on a pipe. Do not log it.
Sourcepub fn verify(&self, presented: &str) -> bool
pub fn verify(&self, presented: &str) -> bool
Constant-time check of a presented secret. The comparison always runs over the full fixed-length buffer, and a presented value of the wrong length fails without an early return, so neither content nor length-prefix match leaks through timing.
Sourcepub fn read_from(reader: &mut impl BufRead) -> Result<Self, SecretError>
pub fn read_from(reader: &mut impl BufRead) -> Result<Self, SecretError>
Read the secret from the first line of reader, at most SECRET_HEX_LEN plus a line
ending long. For the child’s stdin; the generic form exists for tests.
Sourcepub fn read_from_stdin() -> Result<Self, SecretError>
pub fn read_from_stdin() -> Result<Self, SecretError>
Read the secret from this process’s stdin. Call it once, first, before anything else
reads stdin; later reads (see watch_stdin_eof) continue after the secret line.