Trait kernel::hil::public_key_crypto::keys::PubPrivKeyMut

source ·
pub trait PubPrivKeyMut: PubKeyMut {
    // Required methods
    fn import_private_key(
        private_key: &'static mut [u8],
    ) -> Result<(), (ErrorCode, &'static mut [u8])>;
    fn priv_key(&self) -> Result<&'static mut [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§


fn import_private_key( &self, private_key: &'static mut [u8], ) -> Result<(), (ErrorCode, &'static mut [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.


fn priv_key(&self) -> Result<&'static mut [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


fn len(&self) -> usize

Report the length of the private key in bytes, as returned from priv_key(). A value of 0 indicates that the key does not exist.