pub struct Token(/* private fields */);Expand description
A bearer token, as configured.
Deserialises from a plain string. It has no accessor: the only thing anything may do with a configured token is ask whether a presented one equals it, and that comparison lives here so it cannot be written a second, sloppier time somewhere else.
Implementations§
Source§impl Token
impl Token
Sourcepub fn new(token: impl Into<String>) -> Self
pub fn new(token: impl Into<String>) -> Self
A token from a string, for constructing a server in code.
Sourcepub fn matches(&self, presented: &str) -> bool
pub fn matches(&self, presented: &str) -> bool
Whether presented is this token.
The byte comparison does not stop at the first difference, so the
time it takes does not reveal how much of a guess was right. What it
does still reveal is the length — a presented token of a different
length is rejected after fewer XORs — and that is accepted
deliberately: a token’s length is fixed by whoever issued it, is not
the secret, and is bounded below by MIN_TOKEN_LEN anyway.
Trait Implementations§
Source§impl Debug for Token
Redacted, and the mistake AGENTS.md names: a derived Debug over a
credential is how three store crates shipped printing their tokens. Not
even the length, which would narrow a guess for nothing in return.
impl Debug for Token
Redacted, and the mistake AGENTS.md names: a derived Debug over a
credential is how three store crates shipped printing their tokens. Not
even the length, which would narrow a guess for nothing in return.