Skip to main content

KeyStoreBackend

Trait KeyStoreBackend 

Source
pub trait KeyStoreBackend: Backend {
    // Required methods
    fn generate_key(
        &mut self,
        spec: KeySpec,
    ) -> Result<KeyMetadata, BackendError>;
    fn import_key(
        &mut self,
        spec: KeySpec,
        key_bytes: &[u8],
        passphrase: Option<&[u8]>,
    ) -> Result<KeyMetadata, BackendError>;
    fn export_public_key(
        &self,
        key_id: &KeyId,
    ) -> Result<PublicKeyDer, BackendError>;
    fn list_keys(&self) -> Result<Vec<KeyMetadata>, BackendError>;
    fn delete_key(&mut self, key_id: &KeyId) -> Result<(), BackendError>;
}
Expand description

Key generation and storage operations.

Backends implementing this trait can generate, import, and manage cryptographic keys.

Required Methods§

Source

fn generate_key(&mut self, spec: KeySpec) -> Result<KeyMetadata, BackendError>

Generate a new key.

The backend owns the key and returns metadata including an opaque KeyId reference. For hardware backends, the private key never leaves the device.

Source

fn import_key( &mut self, spec: KeySpec, key_bytes: &[u8], passphrase: Option<&[u8]>, ) -> Result<KeyMetadata, BackendError>

Import an existing key from material the caller holds.

spec.algorithm says how to read key_bytes, because nothing in the bytes distinguishes a 32-byte secret from any other 32 bytes: a symmetric algorithm takes the raw key, every other one takes a private key, as PKCS#8 DER or as PEM. The metadata that comes back carries a check value in the first case and a public key in the second, which is the identity each kind has.

passphrase opens a private key that is encrypted, in any encoding the backend reads. Material that needs one and is given none is refused by name, and so is a passphrase given for material that is not encrypted: a passphrase the transcript says was used has to have been used.

Only supported by backends that allow key import (software, some HSMs). Hardware security modules may reject it for security reasons, and a device that holds only one kind of key refuses the other by name.

Source

fn export_public_key( &self, key_id: &KeyId, ) -> Result<PublicKeyDer, BackendError>

Export the public key for key_id.

Source

fn list_keys(&self) -> Result<Vec<KeyMetadata>, BackendError>

List all keys managed by this backend.

Source

fn delete_key(&mut self, key_id: &KeyId) -> Result<(), BackendError>

Delete a key permanently.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§