pub trait SelectKey<'a> {
// Required methods
fn get_key_count(&self) -> Result<(), ErrorCode>;
fn select_key(&self, index: usize) -> Result<(), ErrorCode>;
fn set_client(&self, client: &'a dyn SelectKeyClient);
}
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
, without gaps. Selecting a key between 0
and
get_key_count()-1
must not fail with ErrorCode::INVAL
.
The stored keys can be public or private keys.
Required Methods§
Sourcefn get_key_count(&self) -> Result<(), ErrorCode>
fn get_key_count(&self) -> Result<(), ErrorCode>
Return the number of keys that the device can switch among.
Each key must be identifiable by a consistent index.
This operation is asynchronous and its completion is signaled by
get_key_count_done()
.
§Return
Ok()
if getting the count has started. Otherwise:
Err(ErrorCode::FAIL)
if the key count could not be started and there will be no callback.
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.