amebazii::types::image::ota

Struct SubImage

Source
pub struct SubImage {
    pub header: ImageHeader,
    pub fst: EncryptedOr<FST>,
    /* private fields */
}
Expand description

Represents a sub-image, including a header, FST (Firmware Security Table), sections, and hash for integrity verification.

This struct provides methods to manipulate sections, retrieve data, and manage the sub-image’s hash.

Fields§

§header: ImageHeader

The header of the sub-image containing general information about the sub-image.

§fst: EncryptedOr<FST>

The Firmware Security Table (FST) associated with the sub-image.

Implementations§

Source§

impl SubImage

Source

pub fn get_hash(&self) -> &[u8; 32]

Returns a reference to the hash of the sub-image.

§Returns:
  • A reference to the 32-byte hash of the sub-image.
Source

pub fn get_sections(&self) -> &[Section]

Returns a reference to the sections in the sub-image.

This method provides access to the sub-image’s sections as an immutable slice.

§Returns:
  • A reference to the Vec<Section> representing the sections in the sub-image.
Source

pub fn get_sections_mut(&mut self) -> &mut [Section]

Returns a mutable reference to the sections in the sub-image.

This method provides access to the sub-image’s sections as a mutable slice, allowing for modification of the sections.

§Returns:
  • A mutable reference to the Vec<Section> representing the sections in the sub-image.
Source

pub fn add_section(&mut self, section: Section)

Adds a new section to the sub-image.

This method appends the provided section to the list of sections in the sub-image.

§Arguments:
  • section: The section to add to the sub-image.
Source

pub fn rem_section_at(&mut self, index: usize)

Removes the section at the specified index from the sub-image.

This method removes the section at the given index from the list of sections. If the index is out of bounds, the method will panic.

§Arguments:
  • index: The index of the section to remove.
Source

pub fn get_section(&self, index: usize) -> Option<&Section>

Returns a reference to the section at the specified index, if it exists.

This method retrieves the section at the specified index. If the index is out of bounds, None is returned.

§Arguments:
  • index: The index of the section to retrieve.
§Returns:
  • Option<&Section>: Some(section) if the section exists, or None if the index is out of bounds.
Source

pub fn get_section_mut(&mut self, index: usize) -> Option<&mut Section>

Returns a mutable reference to the section at the specified index, if it exists.

This method retrieves the section at the specified index. If the index is out of bounds, None is returned.

§Arguments:
  • index: The index of the section to retrieve.
§Returns:
  • Option<&mut Section>: Some(section) if the section exists, or None if the index is out of bounds.
Source

pub fn signature_from_stream<R>( &self, reader: &mut R, algo: HashAlgo, key: Option<&[u8]>, ) -> Result<Vec<u8>, Error>
where R: Read + Seek,

Reads the signature for this SubImage from a binary stream and computes its hash.

This function reads the header and segment data of the SubImage from the given reader, and then computes the hash of the data using the specified hashing algorithm (algo). Optionally, a key can be provided for use by certain hashing algorithms (e.g., HMAC).

§Arguments:
  • reader: A mutable reference to a reader that implements both io::Read and io::Seek.
  • algo: The hash algorithm to use for computing the signature (e.g., SHA-256, HMAC).
  • key: An optional key for algorithms that require one (e.g., HMAC). If no key is needed, this can be None.
§Returns:
  • Result<Vec<u8>, Error>: Returns the computed signature as a Vec<u8> if successful, or an Error if there is an issue reading the data or computing the hash.

Trait Implementations§

Source§

impl AsImage for SubImage

Source§

fn set_signature(&mut self, signature: &[u8])

Set the signature for the SubImage.

§Arguments:
  • signature: A slice containing the signature to set.
Source§

fn set_segment_size(&mut self, size: u32)

Set the segment size for the SubImage.

§Arguments:
  • size: The size to set for the SubImage’s segment.
Source§

fn build_segment_size(&self) -> u32

Build the segment size for the SubImage.

§Returns:

The total segment size, calculated by adding the size of the ImageHeader, the FST, and the aligned sizes of all the sections.

Source§

fn build_signature(&self, key: Option<&[u8]>) -> Result<Vec<u8>, Error>

Build the signature for the SubImage.

This function generates a signature by calculating the hash of the image’s content, including the header, firmware security table (FST), and sections.

§Arguments:
  • key: A byte slice containing the key used to generate the signature.
§Returns:

A Result<Vec<u8>, crate::error::Error> that contains:

  • Ok(Vec<u8>): The signature as a byte vector.
  • Err(Error): An error if signature calculation fails (e.g., unsupported hash algorithm).
Source§

impl Debug for SubImage

Source§

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

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

impl Default for SubImage

Source§

fn default() -> Self

Creates a new SubImage with default values.

The default SubImage is initialized as follows:

  • The header is initialized with the default value of ImageHeader.
  • The fst is initialized with the default value of FST.
  • The sections is an empty vector.
  • The hash is set to an array of 32 0xFF bytes (indicating an uninitialized or invalid hash).
Source§

impl FromStream for SubImage

Source§

fn read_from<R>(&mut self, reader: &mut R) -> Result<(), Error>
where R: Read + Seek,

Reads a SubImage from a binary stream.

§Arguments:
  • reader: The stream from which the data will be read. This must implement std::io::Read and std::io::Seek.
Source§

impl ToStream for SubImage

Source§

fn write_to<W>(&self, writer: &mut W) -> Result<(), Error>
where W: Write + Seek,

Writes a SubImage to a binary stream.

§Arguments:
  • writer: The stream to which the data will be written. This must implement std::io::Write and std::io::Seek.

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