pub struct KeyStore { /* private fields */ }Expand description
An in-memory set of key_id → secret pairs loaded at startup.
Secrets are compared with subtle::ConstantTimeEq so a caller cannot
learn a valid key one byte at a time by measuring how long a rejection
takes. Only the key_id is ever recorded in the metering log.
Implementations§
Source§impl KeyStore
impl KeyStore
Sourcepub fn parse(contents: &str) -> Self
pub fn parse(contents: &str) -> Self
Reads key_id:secret lines, ignoring blank lines and # comments.
A line is split on the first : so a secret may itself contain
colons. Lines without a colon are skipped; they are reported by
KeyStore::load so a malformed file is visible at startup.
Sourcepub fn load(path: &Path) -> Result<Self, ApiError>
pub fn load(path: &Path) -> Result<Self, ApiError>
Loads and parses the keys file at path.
Fails closed (Phase 2 design §4): a missing file, an unreadable file, or
a file that yields no usable key_id:secret line is a startup error.
Starting with zero keys would serve 401 for every request while looking
healthy, which is harder to diagnose than refusing to boot.
Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
True when no key is provisioned, i.e. every request will be rejected.
Sourcepub fn verify(&self, key_id: &str, secret: &str) -> Result<String, ApiError>
pub fn verify(&self, key_id: &str, secret: &str) -> Result<String, ApiError>
Checks a presented token and returns its key_id on success.
Both an unknown key_id and a wrong secret are rejected with the same
error, and the work done in each case is roughly equal, so the response
does not reveal which keys exist.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for KeyStore
impl RefUnwindSafe for KeyStore
impl Send for KeyStore
impl Sync for KeyStore
impl Unpin for KeyStore
impl UnsafeUnpin for KeyStore
impl UnwindSafe for KeyStore
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<A, B, T> HttpServerConnExec<A, B> for Twhere
B: Body,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more