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
impl ImageVerifier
Sourcepub fn update(&mut self, chunk: &[u8]) -> Result<()>
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.
Sourcepub fn finish(self) -> Result<Verified>
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§
impl Freeze for ImageVerifier
impl RefUnwindSafe for ImageVerifier
impl Send for ImageVerifier
impl Sync for ImageVerifier
impl Unpin for ImageVerifier
impl UnsafeUnpin for ImageVerifier
impl UnwindSafe for ImageVerifier
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more