make signatureinflash structure data

this cleans up one unsafe step where we have to assume an
alignment of the data at the cost of the structure being copied
to stack. I think this is a fine trade-off.
This commit is contained in:
bunnie 2025-10-04 18:51:34 +08:00
parent b91d54c5cf
commit c86844a39a

View file

@ -57,6 +57,22 @@ pub struct SignatureInFlash {
}
unsafe impl Zeroable for SignatureInFlash {}
unsafe impl Pod for SignatureInFlash {}
impl AsRef<[u8]> for SignatureInFlash {
fn as_ref(&self) -> &[u8] { bytemuck::bytes_of(self) }
}
impl AsMut<[u8]> for SignatureInFlash {
fn as_mut(&mut self) -> &mut [u8] { bytemuck::bytes_of_mut(self) }
}
impl Default for SignatureInFlash {
fn default() -> Self {
Self {
_jal_instruction: 0,
signature: [0u8; SIGNATURE_LENGTH],
sealed_data: SealedFields::default(),
padding: [0u8; PADDING_LEN],
}
}
}
#[repr(C)]
#[derive(Copy, Clone, Pod, Zeroable)]
@ -96,6 +112,19 @@ pub struct SealedFields {
impl AsRef<[u8]> for SealedFields {
fn as_ref(&self) -> &[u8] { bytemuck::bytes_of(self) }
}
impl Default for SealedFields {
fn default() -> Self {
Self {
version: 0,
signed_len: 0,
function_code: 0,
reserved: 0,
min_semver: [0u8; 16],
semver: [0u8; 16],
pubkeys: [[0u8; PUBLIC_KEY_LENGTH]; 4],
}
}
}
#[derive(Debug, Clone, Copy, Pod, Zeroable)]
#[repr(C)]