Skip to main content

ImageVerifier

Struct ImageVerifier 

Source
pub struct ImageVerifier { /* private fields */ }
Expand description

Hashes an image as it arrives and checks it against a manifest.

§Examples

use pamoja_update::{ImageVerifier, Manifest, PayloadFormat, STRUCTURE_VERSION};
use sha2::{Digest, Sha256};

let image = b"firmware bytes";
let manifest = Manifest {
    structure_version: STRUCTURE_VERSION,
    sequence: 1,
    vendor_id: [0; 16],
    class_id: [0; 16],
    format: PayloadFormat::Raw,
    storage: 0,
    digest: Sha256::digest(image).into(),
    size: image.len() as u32,
    expires: 0,
};

let mut verifier = ImageVerifier::new(&manifest);
for chunk in image.chunks(4) {
    verifier.update(chunk).unwrap();
}
assert!(verifier.finish().is_ok());

Implementations§

Source§

impl ImageVerifier

Source

pub fn new(manifest: &Manifest) -> Self

Starts verifying an image against manifest.

§Arguments
  • manifest - the manifest whose digest and size the image must match.
§Returns

A verifier awaiting the image.

Source

pub fn update(&mut self, chunk: &[u8]) -> Result<()>

Folds the next chunk of the image in.

§Arguments
  • chunk - the next bytes of the image, in order.
§Returns

Ok(()) once the chunk is hashed.

§Errors

Returns Refusal::Size as soon as more bytes arrive than the manifest declared, so an oversized payload is stopped while it is arriving rather than after it has filled the slot.

Source

pub fn finish(self) -> Result<Verified>

Finishes the check and reports whether the image is the one described.

§Returns

A Verified receipt when the image is exactly the length and content the manifest committed to.

§Errors

Returns Refusal::Size if fewer bytes arrived than declared, or Refusal::Digest if the content does not hash to the manifest’s digest.

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> 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, 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.