use bytemuck::{Pod, Zeroable};
pub use super::infinity_format::{RuleFlags, SectionOffsets};
#[repr(C)]
#[derive(Debug, Clone, Copy, Pod, Zeroable)]
pub struct BinaryRule {
pub rule_id: u16,
pub category: u8,
pub priority: u8,
pub pattern: u32,
pub description: u32,
}
impl BinaryRule {
pub fn new(rule_id: u16, category: u8, priority: u8, pattern: u32, description: u32) -> Self {
Self {
rule_id,
category,
priority,
pattern,
description,
}
}
pub const fn size() -> usize {
std::mem::size_of::<Self>()
}
}
#[repr(C)]
#[derive(Debug, Clone, Copy, Pod, Zeroable)]
pub struct BinaryStep {
pub step_id: u16,
pub action_count: u16,
pub name: u32,
pub description: u32,
pub condition: u32,
pub _reserved: u32,
}
impl BinaryStep {
pub fn new(step_id: u16, name: u32, description: u32) -> Self {
Self {
step_id,
action_count: 0,
name,
description,
condition: 0,
_reserved: 0,
}
}
pub const fn size() -> usize {
std::mem::size_of::<Self>()
}
}
#[repr(C)]
#[derive(Debug, Clone, Copy, Pod, Zeroable)]
pub struct BinaryPersona {
pub name: u32,
pub role: u32,
pub identity: u32,
pub style: u32,
pub expertise_level: u8,
pub trait_count: u8,
pub principle_count: u8,
pub behavior_flags: u8,
}
impl BinaryPersona {
pub const fn size() -> usize {
std::mem::size_of::<Self>()
}
}
#[repr(C)]
#[derive(Debug, Clone, Copy, Pod, Zeroable)]
pub struct BinaryStandardsHeader {
pub rule_count: u16,
pub category_table_offset: u16,
pub priority_index_offset: u32,
}
impl BinaryStandardsHeader {
pub const fn size() -> usize {
std::mem::size_of::<Self>()
}
}
#[repr(C)]
#[derive(Debug, Clone, Copy, Pod, Zeroable)]
pub struct BinaryContext {
pub include_count: u16,
pub exclude_count: u16,
pub focus_count: u16,
pub _reserved: u16,
}
impl BinaryContext {
pub const fn size() -> usize {
std::mem::size_of::<Self>()
}
}
#[repr(C)]
#[derive(Debug, Clone, Copy, Pod, Zeroable)]
pub struct BinarySignature {
pub algorithm: u8,
pub _reserved: [u8; 3],
pub public_key: [u8; 32],
pub signature: [u8; 64],
}
impl BinarySignature {
pub const ED25519: u8 = 1;
pub const fn size() -> usize {
std::mem::size_of::<Self>()
}
pub fn empty() -> Self {
Self {
algorithm: 0,
_reserved: [0; 3],
public_key: [0; 32],
signature: [0; 64],
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_binary_rule_size() {
assert_eq!(BinaryRule::size(), 12);
}
#[test]
fn test_binary_step_size() {
assert_eq!(BinaryStep::size(), 20);
}
#[test]
fn test_binary_persona_size() {
assert_eq!(BinaryPersona::size(), 20);
}
#[test]
fn test_binary_signature_size() {
assert!(BinarySignature::size() >= 100);
}
}