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
impl ImageHeader
Sourcepub fn is_key1_valid(&self) -> bool
pub fn is_key1_valid(&self) -> bool
Checks if the first user key (user_key1
) is valid.
§Returns
true
ifuser_key1
is valid (i.e., not all bytes are0xFF
).false
ifuser_key1
is invalid (i.e., all bytes are0xFF
).
Sourcepub fn is_key2_valid(&self) -> bool
pub fn is_key2_valid(&self) -> bool
Checks if the second user key (user_key2
) is valid.
§Returns
true
ifuser_key2
is valid (i.e., not all bytes are0xFF
).false
ifuser_key2
is invalid (i.e., all bytes are0xFF
).
Sourcepub fn has_next(&self) -> bool
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 not0xFFFF_FFFF
).false
if there is no next image (i.e.,next_offset
is0xFFFF_FFFF
).
Sourcepub fn get_user_key1(&self) -> DataRefType<'_, 32>
pub fn get_user_key1(&self) -> DataRefType<'_, 32>
Sourcepub fn get_user_key2(&self) -> DataRefType<'_, 32>
pub fn get_user_key2(&self) -> DataRefType<'_, 32>
Sourcepub fn set_user_key1(&mut self, key: DataType<32>)
pub fn set_user_key1(&mut self, key: DataType<32>)
Sets the first user key (user_key1
) in the image header.
§Arguments
key
- ADataType<32>
representing the new value foruser_key1
.
Sourcepub fn set_user_key2(&mut self, key: DataType<32>)
pub fn set_user_key2(&mut self, key: DataType<32>)
Sets the second user key (user_key2
) in the image header.
§Arguments
key
- ADataType<32>
representing the new value foruser_key2
.
Trait Implementations§
Source§impl BinarySize for ImageHeader
impl BinarySize for ImageHeader
Source§fn binary_size() -> usize
fn binary_size() -> usize
Returns the binary size of the ImageHeader
in bytes.
Source§impl Debug for ImageHeader
impl Debug for ImageHeader
Source§impl Default for ImageHeader
impl Default for ImageHeader
Source§fn default() -> Self
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) == Noneimg_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
impl FromStream for ImageHeader
Source§fn read_from<R>(&mut self, reader: &mut R) -> Result<(), Error>
fn read_from<R>(&mut self, reader: &mut R) -> Result<(), Error>
Reads an ImageHeader
from a stream, populating its fields.
§Parameters
reader
: A mutable reference to a reader that implements bothio::Read
andio::Seek
. This is used to read the raw byte data representing theImageHeader
.
§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.