pub trait PubKey {
// Required methods
fn import_public_key(
&self,
public_key: &'static [u8],
) -> Result<(), (ErrorCode, &'static [u8])>;
fn pub_key(&self) -> Result<&'static [u8], ErrorCode>;
fn len(&self) -> usize;
}
Expand description
An internal representation of an asymmetric Public key.
This trait is useful for managing keys internally in Tock.
PubKey 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_public_key(
&self,
public_key: &'static [u8],
) -> Result<(), (ErrorCode, &'static [u8])>
fn import_public_key( &self, public_key: &'static [u8], ) -> Result<(), (ErrorCode, &'static [u8])>
Import an existing public key.
The reference to the public_key
is stored internally and can be
retrieved with the pub_key()
function.
The public_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 pub_key(&self) -> Result<&'static [u8], ErrorCode>
fn pub_key(&self) -> Result<&'static [u8], ErrorCode>
Return the public key supplied by import_public_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