Skip to main content

Delegation

Struct Delegation 

Source
pub struct Delegation {
    pub epoch: u64,
    pub release_key: [u8; 32],
    pub expires: u64,
}
Expand description

A statement, signed by a device’s trust anchor, naming the key that may sign its updates.

§Examples

use pamoja_security::DeviceIdentity;
use pamoja_update::{Delegation, DELEGATION_MAX};

let anchor = DeviceIdentity::from_seed(&[1u8; 32]);
let release = DeviceIdentity::from_seed(&[2u8; 32]);

let delegation = Delegation {
    epoch: 1,
    release_key: release.public().to_bytes(),
    expires: 0,
};

let mut buf = [0u8; DELEGATION_MAX];
let written = delegation.sign(&anchor, &mut buf).unwrap();

let adopted = Delegation::open(&buf[..written], &anchor.public()).unwrap();
assert_eq!(adopted, delegation);

Fields§

§epoch: u64

Rises with every rotation. A device refuses a delegation not above the one it holds, so a retired key cannot be reinstated by replaying the statement that once authorised it.

§release_key: [u8; 32]

The public key that may sign manifests while this delegation stands.

§expires: u64

When this delegation stops being honoured, in seconds since the Unix epoch, or 0 to never expire. Setting one requires the device to have a clock.

Implementations§

Source§

impl Delegation

Source

pub fn encode(&self, buf: &mut [u8]) -> Result<usize>

Encodes the delegation body, which is the part a signature covers.

§Arguments
  • buf - the destination.
§Returns

How many bytes were written.

§Errors

Returns Refusal::Malformed if buf is too small.

Source

pub fn decode(bytes: &[u8]) -> Result<Self>

Decodes a delegation body.

§Arguments
  • bytes - an encoded delegation body.
§Returns

The delegation.

§Errors

Returns Refusal::Malformed if the encoding is not a well-formed delegation with its keys in order.

Source

pub fn sign(&self, anchor: &DeviceIdentity, buf: &mut [u8]) -> Result<usize>

Encodes the delegation and signs it with the trust anchor.

§Arguments
  • anchor - the trust anchor’s identity, which alone may delegate.
  • buf - the destination, at least DELEGATION_MAX bytes.
§Returns

How many bytes of buf the envelope occupies.

§Errors

Returns Refusal::Malformed if buf is too small.

Source

pub fn open(envelope: &[u8], anchor: &PublicIdentity) -> Result<Self>

Checks a delegation envelope against a trust anchor and reads it.

§Arguments
  • envelope - the signed delegation.
  • anchor - the key the device anchors its trust in.
§Returns

The delegation, now known to be from the anchor and unaltered.

§Errors

Returns Refusal::Signature if it is not the anchor’s, or a decoding refusal if the body is not a valid delegation.

Source

pub fn signer(&self) -> Result<PublicIdentity>

Returns the release key as an identity that can check a manifest.

§Returns

The delegated public key.

§Errors

Returns Refusal::Signature if the delegated bytes are not a usable public key, so a malformed delegation cannot leave a device trusting nothing while believing it trusts something.

Trait Implementations§

Source§

impl Clone for Delegation

Source§

fn clone(&self) -> Delegation

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for Delegation

Source§

impl Debug for Delegation

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for Delegation

Source§

impl PartialEq for Delegation

Source§

fn eq(&self, other: &Delegation) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for Delegation

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.