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
impl SubImage
Sourcepub fn get_hash(&self) -> &[u8; 32]
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.
Sourcepub fn get_sections(&self) -> &[Section]
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.
Sourcepub fn get_sections_mut(&mut self) -> &mut [Section]
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.
Sourcepub fn add_section(&mut self, section: Section)
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.
Sourcepub fn rem_section_at(&mut self, index: usize)
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.
Sourcepub fn get_section(&self, index: usize) -> Option<&Section>
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, orNone
if the index is out of bounds.
Sourcepub fn get_section_mut(&mut self, index: usize) -> Option<&mut Section>
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, orNone
if the index is out of bounds.
Sourcepub fn signature_from_stream<R>(
&self,
reader: &mut R,
algo: HashAlgo,
key: Option<&[u8]>,
) -> Result<Vec<u8>, Error>
pub fn signature_from_stream<R>( &self, reader: &mut R, algo: HashAlgo, key: Option<&[u8]>, ) -> Result<Vec<u8>, Error>
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 bothio::Read
andio::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 beNone
.
§Returns:
Result<Vec<u8>, Error>
: Returns the computed signature as aVec<u8>
if successful, or anError
if there is an issue reading the data or computing the hash.
Trait Implementations§
Source§impl AsImage for SubImage
impl AsImage for SubImage
Source§fn set_signature(&mut self, signature: &[u8])
fn set_signature(&mut self, signature: &[u8])
Source§fn set_segment_size(&mut self, size: u32)
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
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>
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 Default for SubImage
impl Default for SubImage
Source§fn default() -> Self
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 ofImageHeader
. - The
fst
is initialized with the default value ofFST
. - The
sections
is an empty vector. - The
hash
is set to an array of 320xFF
bytes (indicating an uninitialized or invalid hash).