use crate::HEADER_SIZE;
pub const PKEX_MAGIC: u32 = 0x58454B50;
#[repr(C, packed)]
#[derive(Debug, Clone, Copy)]
pub struct Header {
pub magic: u32,
pub min: [u16; 3],
pub max: [u16; 3],
pub mode: ExecMode,
pub sections: u16,
pub author: [u8; 32],
pub name: [u8; 32],
pub extended: [u8; 42],
}
impl Default for Header {
fn default() -> Self {
Self::new()
}
}
impl Header {
pub fn new() -> Self {
Self {
magic: PKEX_MAGIC,
author: [0u8; 32],
name: [0u8; 32],
..Default::default()
}
}
#[inline]
pub fn validate(&self) -> bool {
self.magic == PKEX_MAGIC
}
#[inline]
pub const fn to_array(&self) -> [u8; HEADER_SIZE] {
unsafe { core::ptr::read(self as *const Self as *const [u8; HEADER_SIZE]) }
}
}
#[repr(C)]
#[derive(Debug, Clone, Copy)]
pub enum ExecMode {
UserApp,
CoreDrv,
}