Skip to main content

KeyStore

Struct KeyStore 

Source
pub struct KeyStore { /* private fields */ }
Expand description

The key store: one SQLite connection, serialised behind a mutex.

Verification is one indexed lookup per request — trivial next to the whole-graph load every query already performs — and reading the store on every request is what makes runtime issuance, rotation, and revocation visible without a restart or an invalidation protocol. The database runs in WAL mode with a busy timeout so the admin subcommand can write while the server reads.

Implementations§

Source§

impl KeyStore

Source

pub fn open(path: &Path) -> Result<Self, ApiError>

Opens (creating if needed) the key store database at path.

Source

pub fn parse(contents: &str) -> Self

Builds a store from legacy flat-file contents.

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. Imported keys are active and carry plan SELF_HOSTED_PLAN. Building an in-memory SQLite database cannot fail in any way a caller could act on, so this keeps the infallible signature the original parser had.

Source

pub fn import_legacy_file(&self, path: &Path) -> Result<usize, ApiError>

Imports a legacy flat keys file into this store.

Keys already present (by key_id) are left untouched — an import must never resurrect a revoked key or overwrite a rotated secret. Returns how many keys were newly imported.

The import refuses the whole file, before importing anything, when any entry carries DOCUMENTED_EXAMPLE_SECRET — the example credential the README quickstart used to print. That value is published, so importing it would provision a key whose secret every reader of the old README knows (gate F-3). Failing the whole import, rather than skipping the one entry, keeps the refusal loud: a half-imported file that boots with fewer keys than the operator wrote is a quieter failure than not booting.

Source

pub fn issue(&self, key_id: &str, plan: &str) -> Result<String, ApiError>

Issues a new key and returns its secret — the only time the secret exists outside the caller’s hands, so the caller must record it now. Fails if key_id is already taken or is unusable in a bearer token (empty, or containing : or whitespace).

Source

pub fn rotate(&self, key_id: &str) -> Result<String, ApiError>

Replaces a key’s secret and returns the new one. The old secret stops verifying with this call. The key’s plan, status, and creation time are unchanged. A revoked key cannot be rotated back to life — issue a new key instead.

Source

pub fn revoke(&self, key_id: &str) -> Result<(), ApiError>

Revokes a key: it stops verifying immediately. Idempotent for an already-revoked key; an unknown key_id is an error, so a typo in an admin command cannot look like a successful revocation.

Source

pub fn list(&self) -> Result<Vec<KeySummary>, ApiError>

Every key’s summary, ordered by key_id.

Source

pub fn len(&self) -> usize

Number of provisioned keys, in any status.

Source

pub fn is_empty(&self) -> bool

True when no key is provisioned at all.

Source

pub fn active_len(&self) -> usize

Number of keys that can authenticate right now.

Source

pub fn verify( &self, key_id: &str, secret: &str, ) -> Result<VerifiedKey, ApiError>

Checks a presented token and returns the key’s identity and plan.

An unknown key_id, a wrong secret, and a revoked key are all the same 401, and the work done in each case is roughly equal (an unknown key still burns a hash and a comparison), so the response does not reveal which keys exist or why one failed.

Trait Implementations§

Source§

impl Debug for KeyStore

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<A, B, T> HttpServerConnExec<A, B> for T
where B: Body,

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more