pub struct Token(/* private fields */);Expand description
A bearer token for the control API.
Deliberately neither Debug nor Display. A token that can be formatted is a token
that ends up in a log line eventually; the only way out is Token::as_str, which
reads as the deliberate act it is.
Implementations§
Source§impl Token
impl Token
pub fn generate() -> Result<Self>
Sourcepub fn from_hex(s: &str) -> Self
pub fn from_hex(s: &str) -> Self
Reconstruct a token generated elsewhere, such as one read back from disk.
pub fn as_str(&self) -> &str
Sourcepub fn matches(&self, presented: &str) -> bool
pub fn matches(&self, presented: &str) -> bool
Compare in constant time.
A short-circuiting == leaks the token one byte at a time to anything that can
time the response, and on loopback that is every process on the machine. The
length is allowed to leak because it is a compile-time constant.
Sourcepub fn write_to_disk(&self) -> Option<PathBuf>
pub fn write_to_disk(&self) -> Option<PathBuf>
Write the token where a local tool can find it, returning where it went.
Best effort. A daemon that cannot write the file still works, because the token is printed at startup as well, and refusing to start over this would be worse than the inconvenience it avoids.