Skip to main content

KeyBackend

Trait KeyBackend 

Source
pub trait KeyBackend:
    Send
    + Sync
    + 'static {
    // Required methods
    fn import_key(
        &self,
        kind: KeyKind,
        bytes: &[u8],
    ) -> Result<KeyHandle, BackendError>;
    fn generate_key(&self, kind: KeyKind) -> Result<KeyHandle, BackendError>;
    fn compute_kcv(&self, h: &KeyHandle) -> Result<[u8; 3], BackendError>;
    fn random_bytes(&self, out: &mut [u8]) -> Result<(), BackendError>;
    fn ct_eq(&self, a: &[u8], b: &[u8]) -> bool;
}
Expand description

Key handles, randomness, KCV, constant-time compare. Required by every backend.

Required Methods§

Source

fn import_key( &self, kind: KeyKind, bytes: &[u8], ) -> Result<KeyHandle, BackendError>

Import raw key bytes of kind, returning an opaque KeyHandle.

§Errors

Returns BackendError::KeyImport if bytes does not match kind, or if the backend’s key-slot table is full.

Source

fn generate_key(&self, kind: KeyKind) -> Result<KeyHandle, BackendError>

Generate a fresh key of kind, returning an opaque KeyHandle.

§Errors

Returns BackendError::KeyGen (or BackendError::Rng) if generation fails or no slot is free.

Source

fn compute_kcv(&self, h: &KeyHandle) -> Result<[u8; 3], BackendError>

Compute the GP Key Check Value (3 bytes) for the referenced key.

§Errors

Returns BackendError::Crypto if h does not refer to a live key, or the KCV computation fails.

Source

fn random_bytes(&self, out: &mut [u8]) -> Result<(), BackendError>

Fill out with cryptographically secure random bytes. The count is out.len() (was the alloc-returning random_bytes(n) -> Vec<u8>).

§Errors

Returns BackendError::Rng if the underlying CSPRNG fails.

Source

fn ct_eq(&self, a: &[u8], b: &[u8]) -> bool

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§