From c86844a39a191937e0426a373fd3d487134688c9 Mon Sep 17 00:00:00 2001 From: bunnie Date: Sat, 4 Oct 2025 18:51:34 +0800 Subject: [PATCH] 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. --- libs/bao1x-api/src/signatures.rs | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/libs/bao1x-api/src/signatures.rs b/libs/bao1x-api/src/signatures.rs index c3b187bab..07ebe052d 100644 --- a/libs/bao1x-api/src/signatures.rs +++ b/libs/bao1x-api/src/signatures.rs @@ -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)]