amebazii::types::image::pt

Struct PartitionTableImage

Source
pub struct PartitionTableImage {
    pub keyblock: KeyBlock,
    pub header: ImageHeader,
    pub pt: EncryptedOr<PartTab>,
    /* private fields */
}
Expand description

§===================================================================================== Partition Table Image (PartitionTableImage)

The PartitionTableImage struct represents a complete partition table image, including the key block, header, partition table, and a hash value. It provides methods to read the image from a stream, retrieve the hash, and generate its signature.

Fields§

§keyblock: KeyBlock§header: ImageHeader§pt: EncryptedOr<PartTab>

Implementations§

Source§

impl PartitionTableImage

Source

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

Returns a reference to the 32-byte hash value of the partition table image.

§Returns:
  • A reference to the 32-byte hash array.
Source

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

Creates a signature for the partition table image using HMAC-SHA256.

This function generates a signature by using the HMAC (Hash-based Message Authentication Code) algorithm with SHA-256. It takes a key and the partition table image data (excluding the hash field) as inputs, and returns the resulting signature as a vector of bytes.

§Arguments:
  • reader: A mutable reference to a reader that implements std::io::Read and std::io::Seek.
  • key: The key to be used in the HMAC algorithm, which should be a byte slice.
§Returns:
  • Ok(Vec<u8>) containing the cryptographic signature.
  • Err(Error) if an error occurs during reading or signature generation.
§Example:
let signature = pt_image.create_signature(&mut reader, &key).unwrap();

Trait Implementations§

Source§

impl AsImage for PartitionTableImage

Source§

fn build_segment_size(&self) -> u32

Computes the segment size for the partition table image.

The segment size includes the sizes of the keyblock, header, partition table records, and the user binary data.

§Returns:
  • u32: The computed segment size.
Source§

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

Computes the signature for the partition table image.

This method generates the HMAC SHA-256 signature for the image using the provided key.

§Arguments:
  • key: The key used to compute the HMAC SHA-256 signature.
§Returns:
  • Result<Vec<u8>, crate::error::Error>: The computed signature as a vector of bytes.
Source§

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

Sets the signature for the partition table image.

This method sets the signature in the image, typically after it has been calculated.

§Arguments:
  • signature: The signature to set in the image.
Source§

fn set_segment_size(&mut self, size: u32)

Sets the segment size for the partition table image.

This method allows setting the segment size manually.

§Arguments:
  • size: The segment size to set.
Source§

impl Debug for PartitionTableImage

Source§

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

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

impl Default for PartitionTableImage

Source§

fn default() -> Self

Returns a default PartitionTableImage with default values for all fields.

The keyblock, header, and pt are initialized with their respective defaults, and the hash field is set to an array of 0xFF bytes (representing an uninitialized hash).

§Returns:
  • A PartitionTableImage with all fields set to their default values.
§Example:
let default_pt_image = PartitionTableImage::default();
Source§

impl FromStream for PartitionTableImage

Source§

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

Parses a PartitionTableImage from a binary stream.

§Arguments:
  • reader: A mutable reference to a reader that implements std::io::Read and std::io::Seek.
§Returns:
  • Ok(()) if the partition table image was successfully parsed.
  • Err(Error) if there was an issue reading from the stream.
Source§

impl ToStream for PartitionTableImage

Source§

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

Writes a PartitionTableImage to a binary stream.

Note that this method does not check for valid segment size or hash values, and the padding is applied automatically as part of the partition table write process.

§Arguments:
  • writer: A mutable reference to a writer that implements the std::io::Write and std::io::Seek traits.
§Returns:
  • Ok(()) if the write operation is successful.
  • Err(Error) if there is an error during the write operation.

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.