pub struct LocalKeyProvider { /* private fields */ }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
impl LocalKeyProvider
Sourcepub fn insert_generated(&self, key_id: KeyId) -> Result<PublicKey>
pub fn insert_generated(&self, key_id: KeyId) -> Result<PublicKey>
Insert a newly generated keypair for key_id.
Sourcepub fn insert(
&self,
key_id: KeyId,
secret: SecretKey,
public: PublicKey,
) -> Result<()>
pub fn insert( &self, key_id: KeyId, secret: SecretKey, public: PublicKey, ) -> Result<()>
Insert an existing seed and public key.
Sourcepub fn insert_public(&self, key_id: KeyId, public: PublicKey) -> Result<()>
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.
Sourcepub fn insert_seed(&self, key_id: KeyId, seed: &[u8]) -> Result<PublicKey>
pub fn insert_seed(&self, key_id: KeyId, seed: &[u8]) -> Result<PublicKey>
Insert a key from a 64-byte seed, deriving the public key.
Sourcepub fn get_public_key(&self, key_id: &KeyId) -> Result<PublicKey>
pub fn get_public_key(&self, key_id: &KeyId) -> Result<PublicKey>
Fetch the public key for key_id (sync).
Sourcepub fn get_secret_key(&self, key_id: &KeyId) -> Result<SecretKey>
pub fn get_secret_key(&self, key_id: &KeyId) -> Result<SecretKey>
Borrow the secret seed for key_id by cloning into a new SecretKey.
Sourcepub fn decapsulate_sync(
&self,
key_id: &KeyId,
ciphertext: &[u8],
) -> Result<SharedSecret>
pub fn decapsulate_sync( &self, key_id: &KeyId, ciphertext: &[u8], ) -> Result<SharedSecret>
Decapsulate with the secret for key_id (sync).
Sourcepub fn save_key(&self, key_id: &KeyId, path: impl AsRef<Path>) -> Result<()>
Available on non-WebAssembly only.
pub fn save_key(&self, key_id: &KeyId, path: impl AsRef<Path>) -> Result<()>
Persist a single key to path.
Unavailable on wasm32 (no filesystem).
Sourcepub fn save_recipient(
&self,
key_id: &KeyId,
path: impl AsRef<Path>,
) -> Result<()>
Available on non-WebAssembly only.
pub fn save_recipient( &self, key_id: &KeyId, path: impl AsRef<Path>, ) -> Result<()>
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.
Sourcepub fn load_recipient(&self, path: impl AsRef<Path>) -> Result<KeyId>
Available on non-WebAssembly only.
pub fn load_recipient(&self, path: impl AsRef<Path>) -> Result<KeyId>
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.
Trait Implementations§
Source§impl Debug for LocalKeyProvider
impl Debug for LocalKeyProvider
Source§impl Default for LocalKeyProvider
impl Default for LocalKeyProvider
Source§impl KeyProvider for LocalKeyProvider
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,
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,
store only.key_id. Read moreSource§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,
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,
store only.key_id. Read moreAuto Trait Implementations§
impl !Freeze for LocalKeyProvider
impl RefUnwindSafe for LocalKeyProvider
impl Send for LocalKeyProvider
impl Sync for LocalKeyProvider
impl Unpin for LocalKeyProvider
impl UnsafeUnpin for LocalKeyProvider
impl UnwindSafe for LocalKeyProvider
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
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