pub trait PubPrivKey: PubKey {
// Required methods
fn import_private_key(
&self,
private_key: &'static [u8],
) -> Result<(), (ErrorCode, &'static [u8])>;
fn priv_key(&self) -> Result<&'static [u8], ErrorCode>;
fn len(&self) -> usize;
}Expand description
An internal representation of a asymetric Public and Private key.
This trait is useful for managing keys internally in Tock.
PubPrivKey is designed for fixed length keys. That is an implementation should support only a single key length, for example RSA 2048. Note that we don’t use const generics here though. That is because even within a single key length implementation, there can be different length inputs, for examples compressed or uncompressed keys.
Required Methods§
Sourcefn import_private_key(
&self,
private_key: &'static [u8],
) -> Result<(), (ErrorCode, &'static [u8])>
fn import_private_key( &self, private_key: &'static [u8], ) -> Result<(), (ErrorCode, &'static [u8])>
Import an existing private key.
The reference to the private_key is stored internally and can be
retrieved with the priv_key() function.
The private_key can be either a mutable static or an immutable static,
depending on where the key is stored (flash or memory).
The possible ErrorCodes are:
- BUSY: A key is already imported or in the process of being
generated.
- INVAL: An invalid key was supplied.
- SIZE: An invalid key size was supplied.
Sourcefn priv_key(&self) -> Result<&'static [u8], ErrorCode>
fn priv_key(&self) -> Result<&'static [u8], ErrorCode>
Return the private key supplied by import_private_key() or
generate().
On success the return value is Ok(()) with the buffer that was
originally passed in to hold the key.
On failure the possible ErrorCodes are:
- NODEVICE: The key does not exist