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
impl PartitionTableImage
Sourcepub fn get_hash(&self) -> &[u8; 32]
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.
Sourcepub fn create_signature<R>(
&self,
reader: &mut R,
key: &[u8],
) -> Result<Vec<u8>, Error>
pub fn create_signature<R>( &self, reader: &mut R, key: &[u8], ) -> Result<Vec<u8>, Error>
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 implementsstd::io::Read
andstd::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
impl AsImage for PartitionTableImage
Source§fn build_segment_size(&self) -> u32
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>
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])
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)
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
impl Debug for PartitionTableImage
Source§impl Default for PartitionTableImage
impl Default for PartitionTableImage
Source§fn default() -> Self
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
impl FromStream for PartitionTableImage
Source§impl ToStream for PartitionTableImage
impl ToStream for PartitionTableImage
Source§fn write_to<W>(&self, writer: &mut W) -> Result<(), Error>
fn write_to<W>(&self, writer: &mut W) -> Result<(), Error>
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 thestd::io::Write
andstd::io::Seek
traits.
§Returns:
Ok(())
if the write operation is successful.Err(Error)
if there is an error during the write operation.