Skip to main content

LocalKeyProvider

Struct LocalKeyProvider 

Source
pub struct LocalKeyProvider { /* private fields */ }
Available on crate feature local-keys only.
Expand description

Key provider that holds ML-KEM seeds in process memory.

Suitable for development, Celld embedding, and simple deployments. Private keys are never written to object storage by this crate.

§Examples

use pq_objectstore::key::{KeyId, LocalKeyProvider};

let id = KeyId::new("workspace-a-v1").unwrap();
let provider = LocalKeyProvider::generate(id).unwrap();

Implementations§

Source§

impl LocalKeyProvider

Source

pub fn new() -> Self

Create an empty provider.

Source

pub fn generate(key_id: KeyId) -> Result<Self>

Generate a fresh keypair under key_id.

Source

pub fn insert_generated(&self, key_id: KeyId) -> Result<PublicKey>

Insert a newly generated keypair for key_id.

Source

pub fn insert( &self, key_id: KeyId, secret: SecretKey, public: PublicKey, ) -> Result<()>

Insert an existing seed and public key.

Source

pub fn insert_public(&self, key_id: KeyId, public: PublicKey) -> Result<()>

Insert a public encapsulation key with no private key.

The provider can encrypt to key_id. Decapsulation fails until a private key is inserted for the same id on a machine that holds the seed.

Source

pub fn insert_seed(&self, key_id: KeyId, seed: &[u8]) -> Result<PublicKey>

Insert a key from a 64-byte seed, deriving the public key.

Source

pub fn get_public_key(&self, key_id: &KeyId) -> Result<PublicKey>

Fetch the public key for key_id (sync).

Source

pub fn get_secret_key(&self, key_id: &KeyId) -> Result<SecretKey>

Borrow the secret seed for key_id by cloning into a new SecretKey.

Source

pub fn decapsulate_sync( &self, key_id: &KeyId, ciphertext: &[u8], ) -> Result<SharedSecret>

Decapsulate with the secret for key_id (sync).

Source

pub fn key_ids(&self) -> Result<Vec<KeyId>>

List known key IDs.

Source

pub fn save_key(&self, key_id: &KeyId, path: impl AsRef<Path>) -> Result<()>

Available on non-WebAssembly only.

Persist a single key to path.

Unavailable on wasm32 (no filesystem).

Source

pub fn save_recipient( &self, key_id: &KeyId, path: impl AsRef<Path>, ) -> Result<()>

Available on non-WebAssembly only.

Write a recipient file containing key_id and the public key only.

Copy this file to a backup host. That host can encrypt with Self::load_recipient. The 64-byte seed stays in the key file from Self::save_key on the machine that decrypts.

§Errors

Returns Error::UnknownKey if key_id is not loaded, or Error::Io if the file cannot be written.

Source

pub fn load_recipient(&self, path: impl AsRef<Path>) -> Result<KeyId>

Available on non-WebAssembly only.

Load a recipient file written by Self::save_recipient.

The loaded key can encapsulate (encrypt). It cannot decapsulate.

§Errors

Returns Error::InvalidHeader if the file is not a recipient file, or Error::Config if the key id is already present.

Source

pub fn load_key(&self, path: impl AsRef<Path>) -> Result<KeyId>

Available on non-WebAssembly only.

Load a key file previously written by Self::save_key.

Trait Implementations§

Source§

impl Debug for LocalKeyProvider

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for LocalKeyProvider

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl KeyProvider for LocalKeyProvider

Source§

fn public_key<'life0, 'life1, 'async_trait>( &'life0 self, key_id: &'life1 KeyId, ) -> Pin<Box<dyn Future<Output = Result<PublicKeyMaterial>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Available on crate feature store only.
Fetch the public encapsulation key for key_id. Read more
Source§

fn decapsulate<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, key_id: &'life1 KeyId, ciphertext: &'life2 [u8], ) -> Pin<Box<dyn Future<Output = Result<SharedSecret>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Available on crate feature store only.
Decapsulate an ML-KEM ciphertext for key_id. 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<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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<Unshared, Shared> IntoShared<Shared> for Unshared
where Shared: FromUnshared<Unshared>,

Source§

fn into_shared(self) -> Shared

Creates a shared type from an unshared type.
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<S, T> Upcast<T> for S
where T: UpcastFrom<S> + ?Sized, S: ?Sized,

Source§

fn upcast(&self) -> &T
where Self: ErasableGeneric, T: Sized + ErasableGeneric<Repr = Self::Repr>,

Perform a zero-cost type-safe upcast to a wider ref type within the Wasm bindgen generics type system. Read more
Source§

fn upcast_into(self) -> T
where Self: Sized + ErasableGeneric, T: Sized + ErasableGeneric<Repr = Self::Repr>,

Perform a zero-cost type-safe upcast to a wider type within the Wasm bindgen generics type system. Read more
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