Skip to main content

AuditEntry

Struct AuditEntry 

Source
pub struct AuditEntry { /* private fields */ }
Expand description

Audit trail entry with hash chain integrity

Fixed 80-byte structure as specified in RFC-0002 Section 5.4. All integers are little-endian. Layout is #[repr(C)] for deterministic serialization.

§Memory Layout

Offset  Size  Field
------  ----  -----
0       8     timestamp
8       8     author_id
16      2     action_code
18      6     reserved1
24      8     details_offset
32      4     details_length
36      4     reserved2
40      32    previous_hash
72      8     reserved3
------  ----
Total:  80 bytes

§Examples

use aion_context::audit::{AuditEntry, ActionCode};
use aion_context::types::AuthorId;

let entry = AuditEntry::new(
    1_700_000_000_000_000_000,
    AuthorId(1001),
    ActionCode::CommitVersion,
    100,
    27,
    [0u8; 32],
);

// Verify size
assert_eq!(std::mem::size_of_val(&entry), 80);

// Access fields
assert_eq!(entry.action_code().unwrap(), ActionCode::CommitVersion);
assert_eq!(entry.author_id(), AuthorId(1001));

Implementations§

Source§

impl AuditEntry

Source

pub const fn new( timestamp: u64, author_id: AuthorId, action_code: ActionCode, details_offset: u64, details_length: u32, previous_hash: [u8; 32], ) -> Self

Create a new audit entry

§Arguments
  • timestamp - Nanoseconds since Unix epoch (use SystemTime::now())
  • author_id - Author performing the action
  • action_code - Type of operation (see ActionCode)
  • details_offset - Byte offset in string table
  • details_length - Length of details string (excluding null)
  • previous_hash - BLAKE3 hash of previous entry (all zeros for genesis)
§Examples
use aion_context::audit::{AuditEntry, ActionCode};
use aion_context::types::AuthorId;

let entry = AuditEntry::new(
    1_700_000_000_000_000_000,
    AuthorId(1001),
    ActionCode::Verify,
    200,
    42,
    [0xAB; 32],
);
Source

pub const fn timestamp(&self) -> u64

Get the timestamp in nanoseconds

Source

pub const fn author_id(&self) -> AuthorId

Get the author ID

Source

pub const fn action_code(&self) -> Result<ActionCode>

Get the action code

§Errors

Returns an error if the action code is not a valid enum variant

Source

pub const fn action_code_raw(&self) -> u16

Get the action code as raw u16 (no validation)

Source

pub const fn details_offset(&self) -> u64

Get the details offset in string table

Source

pub const fn details_length(&self) -> u32

Get the details string length (bytes, excluding null terminator)

Source

pub const fn previous_hash(&self) -> &[u8; 32]

Get the previous entry hash

Source

pub fn is_genesis(&self) -> bool

Check if this is a genesis entry (first in chain)

Genesis entries have an all-zero previous hash.

Source

pub fn compute_hash(&self) -> [u8; 32]

Compute BLAKE3 hash of this entry

The hash includes all 80 bytes of the entry. This hash becomes the previous_hash value for the next entry in the chain.

§Examples
use aion_context::audit::{AuditEntry, ActionCode};
use aion_context::types::AuthorId;

let entry = AuditEntry::new(
    1_700_000_000_000_000_000,
    AuthorId(1001),
    ActionCode::CreateGenesis,
    0,
    10,
    [0u8; 32],
);

let entry_hash = entry.compute_hash();
assert_eq!(entry_hash.len(), 32);
Source

pub const fn as_bytes(&self) -> &[u8]

Serialize entry to bytes (little-endian)

Returns exactly 80 bytes in RFC-0002 specified format.

§Safety

This function is safe because:

  1. AuditEntry has #[repr(C)] for deterministic layout
  2. All fields are plain-old-data (POD) types
  3. The lifetime of the returned slice is tied to self
  4. The size is compile-time verified to be 80 bytes
Source

pub fn from_bytes(bytes: &[u8]) -> Result<Self>

Deserialize entry from bytes

§Errors

Returns an error if the input is not exactly 80 bytes.

§Safety

This function is safe because:

  1. Length is validated to be exactly 80 bytes
  2. AuditEntry is #[repr(C)] with POD fields
  3. All bit patterns are valid for the field types
  4. No references or complex types that need initialization

Note: Callers should validate field values (e.g., action_code) after deserialization.

Source

pub fn validate_chain(&self, previous_entry: &Self) -> Result<()>

Validate this entry against the previous entry

Checks that:

  1. The previous_hash matches the hash of previous_entry
  2. The timestamp is not before the previous entry
  3. Reserved fields are zero
§Errors

Returns an error if validation fails.

§Examples
use aion_context::audit::{AuditEntry, ActionCode};
use aion_context::types::AuthorId;

let genesis = AuditEntry::new(
    1_700_000_000_000_000_000,
    AuthorId(1001),
    ActionCode::CreateGenesis,
    0,
    10,
    [0u8; 32],
);

let genesis_hash = genesis.compute_hash();

let entry2 = AuditEntry::new(
    1_700_000_001_000_000_000,
    AuthorId(1002),
    ActionCode::CommitVersion,
    10,
    15,
    genesis_hash,
);

assert!(entry2.validate_chain(&genesis).is_ok());

Trait Implementations§

Source§

impl Clone for AuditEntry

Source§

fn clone(&self) -> AuditEntry

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for AuditEntry

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl PartialEq for AuditEntry

Source§

fn eq(&self, other: &AuditEntry) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Copy for AuditEntry

Source§

impl Eq for AuditEntry

Source§

impl StructuralPartialEq for AuditEntry

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more