pub trait KeySelect<'a> {
// Required methods
fn get_key_count(&self) -> usize;
fn select_key(&self, index: usize) -> Result<(), ErrorCode>;
fn set_client(&self, client: &'a dyn KeySelectClient);
}
Expand description
Interface for selecting an active key among the number of available keys.
This interface allows for the implementer to maintain an opaque internal representation of keys. They may be stored in memory, flash, or in secure element (where the actual key may not be accessible). Users of this interface can select which key is active for cryptographic operations. There is no assumption for implementers of this interface that keys can be added or changed or that keys can be specified by their actual bytes in a slice.
Selecting a key is asynchronous as it may require communication over a bus or waiting for an interrupt.
Keys are specified by an index starting at zero and going to
get_key_count()-1
.
The stored keys can be public or private keys.
Required Methods§
Sourcefn get_key_count(&self) -> usize
fn get_key_count(&self) -> usize
Return the number of keys that the device can switch among.
Each key must be identifiable by a consistent index.
Sourcefn select_key(&self, index: usize) -> Result<(), ErrorCode>
fn select_key(&self, index: usize) -> Result<(), ErrorCode>
Set the key identified by its index as the active key.
Indices start at 0 and go to get_key_count() - 1
.
This operation is asynchronous and its completion is signaled by
select_key_done()
.
§Return
Ok()
if the key select operation was accepted. Otherwise:
Err(ErrorCode::INVAL)
if the index is not valid.Err(ErrorCode::ALREADY)
if the key is already selected.