pub struct PublicIdentity { /* private fields */ }Expand description
A device’s public identity: it names the device and verifies its signatures.
This is the public half of a device’s identity, safe to share and distribute. A gateway holds the public identities of the devices it trusts and uses them to check that each signed payload is authentic and unaltered.
Implementations§
Source§impl PublicIdentity
impl PublicIdentity
Sourcepub fn from_bytes(bytes: &[u8; 32]) -> Result<Self>
pub fn from_bytes(bytes: &[u8; 32]) -> Result<Self>
Reconstructs a public identity from its 32-byte form.
§Arguments
bytes- the 32-byte encoded public key.
§Returns
The public identity.
§Errors
Returns Error::Auth if bytes is not a valid
public key.
Sourcepub fn fingerprint(&self) -> String
pub fn fingerprint(&self) -> String
Returns a short hex fingerprint of this identity for logs and displays.
The fingerprint is the first eight bytes of the public key in hex. It is a convenient label, not a substitute for the full key when checking trust.
§Returns
A 16-character lowercase hex string.
Sourcepub fn verify(&self, payload: &[u8], signature: &Signature) -> Result<()>
pub fn verify(&self, payload: &[u8], signature: &Signature) -> Result<()>
Verifies that signature covers payload and was made by this identity.
§Arguments
payload- the bytes the signature is expected to cover.signature- the signature to check.
§Returns
Ok(()) if the signature is authentic for payload.
§Errors
Returns Error::Auth if the signature does not
match, which means the payload was altered or was not signed by this device.
Sourcepub fn verify_message<'a>(&self, message: &'a [u8]) -> Result<&'a [u8]>
pub fn verify_message<'a>(&self, message: &'a [u8]) -> Result<&'a [u8]>
Verifies a message built by sign_message and returns the payload it carries.
The signature travels with the payload, so a caller sends one message and gets
one payload back instead of tracking two byte strings and splitting them by hand.
The payload is borrowed from message, and is only returned once the signature
over it has been checked.
§Arguments
message- the signature followed by the payload, assign_messagewrote it.
§Returns
The payload, authentic and unaltered.
§Errors
Returns Error::Auth if message is shorter than a
signature or the signature does not match the payload, which means the message was
altered or was not signed by this device.
Trait Implementations§
Source§impl Clone for PublicIdentity
impl Clone for PublicIdentity
Source§fn clone(&self) -> PublicIdentity
fn clone(&self) -> PublicIdentity
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreimpl Copy for PublicIdentity
Source§impl Debug for PublicIdentity
impl Debug for PublicIdentity
impl Eq for PublicIdentity
Source§impl PartialEq for PublicIdentity
impl PartialEq for PublicIdentity
Source§fn eq(&self, other: &PublicIdentity) -> bool
fn eq(&self, other: &PublicIdentity) -> bool
self and other values to be equal, and is used by ==.