pub struct InMemoryKeyStore { /* private fields */ }Available on crate feature
in-memory only.Expand description
A KeyStore holding its keys in memory.
Signs EdDSA, ES256 and (feature secp256k1) ES256K; generates and deletes. Keys are lost
when the store is dropped, and zeroized then. Meant for tests, examples and development, not
for production keys.
InMemoryKeyStore::with_seed makes key generation deterministic, so that a fixture’s keys,
key ids and (for EdDSA and the RFC 6979 ECDSA signatures) signatures are stable across runs.
A seeded store must never hold production keys: anyone with the seed has them.
The key id of a generated key is the spec’s label when set, the RFC 7638 thumbprint of its public key otherwise.
§Examples
use identity_kit::jose::{JwsAlgorithm, KeyType};
use identity_kit::keys::{InMemoryKeyStore, KeySpec, KeyStore};
let store = InMemoryKeyStore::with_seed([7; 32]);
let key = store.generate(KeySpec::new(KeyType::Ed25519, JwsAlgorithm::EdDSA)).await?;
let signature = store.sign(&key, JwsAlgorithm::EdDSA, b"payload").await?;
assert_eq!(signature.len(), 64);
// The same seed gives the same key.
let again = InMemoryKeyStore::with_seed([7; 32]);
assert_eq!(again.generate(KeySpec::new(KeyType::Ed25519, JwsAlgorithm::EdDSA)).await?, key);Implementations§
Trait Implementations§
Source§impl Debug for InMemoryKeyStore
impl Debug for InMemoryKeyStore
Source§impl Default for InMemoryKeyStore
impl Default for InMemoryKeyStore
Source§impl KeyStore for InMemoryKeyStore
impl KeyStore for InMemoryKeyStore
Source§fn capabilities(&self) -> KeyStoreCapabilities
fn capabilities(&self) -> KeyStoreCapabilities
What this store can do.
Source§fn public_jwk<'life0, 'life1, 'async_trait>(
&'life0 self,
key: &'life1 KeyId,
) -> Pin<Box<dyn Future<Output = Result<Jwk, KeyStoreError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn public_jwk<'life0, 'life1, 'async_trait>(
&'life0 self,
key: &'life1 KeyId,
) -> Pin<Box<dyn Future<Output = Result<Jwk, KeyStoreError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
The public key of
key, without private parameters. Read moreSource§fn sign<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
key: &'life1 KeyId,
alg: JwsAlgorithm,
data: &'life2 [u8],
) -> Pin<Box<dyn Future<Output = Result<Vec<u8>, KeyStoreError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn sign<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
key: &'life1 KeyId,
alg: JwsAlgorithm,
data: &'life2 [u8],
) -> Pin<Box<dyn Future<Output = Result<Vec<u8>, KeyStoreError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Source§fn exists<'life0, 'life1, 'async_trait>(
&'life0 self,
key: &'life1 KeyId,
) -> Pin<Box<dyn Future<Output = Result<bool, KeyStoreError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn exists<'life0, 'life1, 'async_trait>(
&'life0 self,
key: &'life1 KeyId,
) -> Pin<Box<dyn Future<Output = Result<bool, KeyStoreError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Whether
key exists. Read moreAuto Trait Implementations§
impl !Freeze for InMemoryKeyStore
impl RefUnwindSafe for InMemoryKeyStore
impl Send for InMemoryKeyStore
impl Sync for InMemoryKeyStore
impl Unpin for InMemoryKeyStore
impl UnsafeUnpin for InMemoryKeyStore
impl UnwindSafe for InMemoryKeyStore
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
Mutably borrows from an owned value. Read more