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§
Sourcefn import_key(
&self,
kind: KeyKind,
bytes: &[u8],
) -> Result<KeyHandle, BackendError>
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.
Sourcefn generate_key(&self, kind: KeyKind) -> Result<KeyHandle, BackendError>
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.
Sourcefn compute_kcv(&self, h: &KeyHandle) -> Result<[u8; 3], BackendError>
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.
Sourcefn random_bytes(&self, out: &mut [u8]) -> Result<(), BackendError>
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.
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".