Skip to main content

KeyStore

Trait KeyStore 

Source
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:

  • capabilities is truthful: every listed algorithm signs; generate and delete return KeyStoreError::Unsupported unless advertised.
  • public_jwk returns a key without private parameters, with alg set to the key’s algorithm when the backend knows it.
  • sign takes the raw signing input (the backend hashes) and returns the JWS form of the signature: 64 bytes for EdDSA, raw r || s for ECDSA, the modulus-sized octet string for RSA. A key signs only with its own algorithm; any other alg is KeyStoreError::AlgorithmMismatch.
  • An unknown key is KeyStoreError::NotFound from every operation but exists, which returns false.

generate and delete have default implementations returning KeyStoreError::Unsupported, for backends whose keys are provisioned out of band.

Required Methods§

Source

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,

The public key of key, without private parameters.

§Errors

KeyStoreError::NotFound when there is no such key.

Source

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.

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,

Whether key exists.

§Errors

Only when the backend cannot answer.

Provided Methods§

Source

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.

Source

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

Source§

fn capabilities(&self) -> KeyStoreCapabilities

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,

Source§

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,

Source§

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,

Source§

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>

Source§

fn capabilities(&self) -> KeyStoreCapabilities

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,

Source§

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,

Source§

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,

Source§

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>

Source§

fn capabilities(&self) -> KeyStoreCapabilities

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,

Source§

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,

Source§

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,

Source§

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§

Source§

impl KeyStore for InMemoryKeyStore

Available on crate feature in-memory only.
Source§

impl KeyStore for Pkcs11KeyStore

Available on crate feature pkcs11 only.
Source§

impl KeyStore for SoftwareKeyStore

Available on crate feature software only.