amebazii::types::header

Struct ImageHeader

Source
pub struct ImageHeader {
    pub segment_size: u32,
    pub next_offset: Option<u32>,
    pub img_type: ImageType,
    pub is_encrypt: bool,
    pub serial: u32,
    pub user_key1: DataType<32>,
    pub user_key2: DataType<32>,
}
Expand description

Generic image header.

This struct contains metadata for an image, such as the segment size, offset to the next image header, the image type, encryption flag, and user keys.

Fields§

§segment_size: u32

The size of the image segment in bytes.

This field specifies the size of the image’s data segment, which can be used to determine how much data is associated with the current image header.

§next_offset: Option<u32>

Offset to the next image header.

If there is no next image header, this field is set to None. Otherwise, it holds the byte offset to the next image header.

§img_type: ImageType

The type of the image.

This field stores the image type, which can represent different image types such as boot images, partition tables, etc.

§is_encrypt: bool

Flag indicating whether the image is encrypted.

This boolean flag indicates whether the image is encrypted (true) or not (false).

§serial: u32

The serial number associated with the image. (version number)

This field stores the image’s serial number. It is initialized to 0xFFFF_FFFF by default.

§user_key1: DataType<32>

User key 1, used for encryption

§user_key2: DataType<32>

User key 2, used for encryption

Implementations§

Source§

impl ImageHeader

Source

pub fn is_key1_valid(&self) -> bool

Checks if the first user key (user_key1) is valid.

§Returns
  • true if user_key1 is valid (i.e., not all bytes are 0xFF).
  • false if user_key1 is invalid (i.e., all bytes are 0xFF).
Source

pub fn is_key2_valid(&self) -> bool

Checks if the second user key (user_key2) is valid.

§Returns
  • true if user_key2 is valid (i.e., not all bytes are 0xFF).
  • false if user_key2 is invalid (i.e., all bytes are 0xFF).
Source

pub fn has_next(&self) -> bool

Checks if there is a next image header.

The next_offset field indicates the offset to the next image header. If the value is 0xFFFF_FFFF, it means there is no next image. This method returns true if the next_offset is not 0xFFFF_FFFF, indicating there is a next image header.

§Returns
  • true if there is a next image (i.e., next_offset is not 0xFFFF_FFFF).
  • false if there is no next image (i.e., next_offset is 0xFFFF_FFFF).
Source

pub fn get_user_key1(&self) -> DataRefType<'_, 32>

Gets the first user key (user_key1).

§Returns

A reference to the user_key1 array (32 bytes).

Source

pub fn get_user_key2(&self) -> DataRefType<'_, 32>

Gets the second user key (user_key2).

§Returns

A reference to the user_key2 array (32 bytes).

Source

pub fn set_user_key1(&mut self, key: DataType<32>)

Sets the first user key (user_key1) in the image header.

§Arguments
  • key - A DataType<32> representing the new value for user_key1.
Source

pub fn set_user_key2(&mut self, key: DataType<32>)

Sets the second user key (user_key2) in the image header.

§Arguments
  • key - A DataType<32> representing the new value for user_key2.

Trait Implementations§

Source§

impl BinarySize for ImageHeader

Source§

fn binary_size() -> usize

Returns the binary size of the ImageHeader in bytes.

Source§

impl Debug for ImageHeader

Source§

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

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

impl Default for ImageHeader

Source§

fn default() -> Self

Creates a default ImageHeader instance with the following default values:

  • segment_size: 0 (default size is zero)
  • next_offset: 0xFFFF_FFFF (indicating no next header) == None
  • img_type: ImageType::Parttab (default is partition table)
  • is_encrypt: false (default is no encryption)
  • serial: 0xFFFF_FFFF (default invalid serial number)
  • user_key1: [0xFF; 32] (default invalid key)
  • user_key2: [0xFF; 32] (default invalid key)
§Returns
  • A new ImageHeader with the default values.
Source§

impl FromStream for ImageHeader

Source§

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

Reads an ImageHeader from a stream, populating its fields.

§Parameters
  • reader: A mutable reference to a reader that implements both io::Read and io::Seek. This is used to read the raw byte data representing the ImageHeader.
§Returns
  • Ok(()): If the header is successfully read from the stream and all fields are populated.
  • Err(Error): If any errors occur while reading the data from the stream.
Source§

impl ToStream for ImageHeader

Source§

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

Serializes the ImageHeader struct to a stream.

§Parameters
  • writer: A mutable reference to a type that implements the std::io::Write trait. The data will be written to this stream.
§Returns
  • Ok(()): If the data is written successfully.
  • Err(Error): If there is an issue writing the data to the stream.

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.