pub trait KeyStore: Send + Sync {
// Required methods
fn capabilities(&self) -> KeyStoreCapabilities;
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 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 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;
// Provided methods
fn generate<'life0, 'async_trait>(
&'life0 self,
spec: KeySpec,
) -> Pin<Box<dyn Future<Output = Result<KeyId, KeyStoreError>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait { ... }
fn delete<'life0, 'life1, 'async_trait>(
&'life0 self,
key: &'life1 KeyId,
) -> Pin<Box<dyn Future<Output = Result<(), KeyStoreError>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait { ... }
}Expand description
A backend holding private keys.
This is the crate’s key extension point: a KMS, an HSM or a software store implements it,
and everything that signs takes a &dyn KeyStore (usually through KeySigner). The
contract, which testsuite checks, is:
capabilitiesis truthful: every listed algorithm signs;generateanddeletereturnKeyStoreError::Unsupportedunless advertised.public_jwkreturns a key without private parameters, withalgset to the key’s algorithm when the backend knows it.signtakes the raw signing input (the backend hashes) and returns the JWS form of the signature: 64 bytes for EdDSA, rawr || sfor ECDSA, the modulus-sized octet string for RSA. A key signs only with its own algorithm; any otheralgisKeyStoreError::AlgorithmMismatch.- An unknown key is
KeyStoreError::NotFoundfrom every operation butexists, which returnsfalse.
generate and delete have default implementations returning
KeyStoreError::Unsupported, for backends whose keys are provisioned out of band.
Required Methods§
Sourcefn capabilities(&self) -> KeyStoreCapabilities
fn capabilities(&self) -> KeyStoreCapabilities
What this store can do.
Sourcefn 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.
§Errors
KeyStoreError::NotFound when there is no such key.
Sourcefn 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,
Signs data with key under alg, returning the signature in its JWS form.
§Errors
KeyStoreError::NotFound when there is no such key and
KeyStoreError::AlgorithmMismatch when alg is not the key’s algorithm.
Provided Methods§
Sourcefn generate<'life0, 'async_trait>(
&'life0 self,
spec: KeySpec,
) -> Pin<Box<dyn Future<Output = Result<KeyId, KeyStoreError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn generate<'life0, 'async_trait>(
&'life0 self,
spec: KeySpec,
) -> Pin<Box<dyn Future<Output = Result<KeyId, KeyStoreError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Generates a key as spec describes and returns its id.
§Errors
KeyStoreError::Unsupported when the store does not generate keys (the default),
KeyStoreError::InvalidSpec when the algorithm does not fit the key type,
KeyStoreError::UnsupportedKeyType or KeyStoreError::UnsupportedAlgorithm when the
store cannot make such a key, and KeyStoreError::AlreadyExists when the label names
an existing key.
Sourcefn delete<'life0, 'life1, 'async_trait>(
&'life0 self,
key: &'life1 KeyId,
) -> Pin<Box<dyn Future<Output = Result<(), KeyStoreError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn delete<'life0, 'life1, 'async_trait>(
&'life0 self,
key: &'life1 KeyId,
) -> Pin<Box<dyn Future<Output = Result<(), KeyStoreError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Deletes key.
§Errors
KeyStoreError::Unsupported when the store does not delete keys (the default) and
KeyStoreError::NotFound when there is no such key.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".
Implementations on Foreign Types§
Source§impl<T: KeyStore + ?Sized> KeyStore for &T
impl<T: KeyStore + ?Sized> KeyStore for &T
fn capabilities(&self) -> KeyStoreCapabilities
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 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 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 generate<'life0, 'async_trait>(
&'life0 self,
spec: KeySpec,
) -> Pin<Box<dyn Future<Output = Result<KeyId, KeyStoreError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn delete<'life0, 'life1, 'async_trait>(
&'life0 self,
key: &'life1 KeyId,
) -> Pin<Box<dyn Future<Output = Result<(), KeyStoreError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Source§impl<T: KeyStore + ?Sized> KeyStore for Arc<T>
impl<T: KeyStore + ?Sized> KeyStore for Arc<T>
fn capabilities(&self) -> KeyStoreCapabilities
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 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 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 generate<'life0, 'async_trait>(
&'life0 self,
spec: KeySpec,
) -> Pin<Box<dyn Future<Output = Result<KeyId, KeyStoreError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn delete<'life0, 'life1, 'async_trait>(
&'life0 self,
key: &'life1 KeyId,
) -> Pin<Box<dyn Future<Output = Result<(), KeyStoreError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Source§impl<T: KeyStore + ?Sized> KeyStore for Box<T>
impl<T: KeyStore + ?Sized> KeyStore for Box<T>
fn capabilities(&self) -> KeyStoreCapabilities
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 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 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 generate<'life0, 'async_trait>(
&'life0 self,
spec: KeySpec,
) -> Pin<Box<dyn Future<Output = Result<KeyId, KeyStoreError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn delete<'life0, 'life1, 'async_trait>(
&'life0 self,
key: &'life1 KeyId,
) -> Pin<Box<dyn Future<Output = Result<(), KeyStoreError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Implementors§
impl KeyStore for InMemoryKeyStore
in-memory only.impl KeyStore for Pkcs11KeyStore
pkcs11 only.impl KeyStore for SoftwareKeyStore
software only.