Skip to main content

krabka_audit/
ids.rs

1//! Domain newtypes for the audit crate.
2//!
3//! These types wrap the same-typed primitives that recur across the hash-chain,
4//! the spool, and the verifier. A transposed call site, for example
5//! `set_depth(bytes, count)`, is then a compile error and not a silent
6//! corruption. See the [newtype guidance] in the style guide.
7//!
8//! [newtype guidance]: ../../../docs/style_guides/code_style_guide.md
9
10use {
11    derive_more::{Add, AddAssign, Display, From, Into},
12    krabka_macros::PrimitiveCmp,
13};
14
15/// Per-broker hash-chain sequence number in each record's `seq` header.
16#[derive(
17    Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord, Display, From, Into, PrimitiveCmp,
18)]
19pub struct Seq(pub u64);
20
21/// Epoch-millisecond timestamp for the checkpoint `time` and the OCSF `time`.
22#[derive(
23    Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord, Display, From, Into, PrimitiveCmp,
24)]
25pub struct EpochMs(pub i64);
26
27/// Count of chained data records.
28#[derive(
29    Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord, Display, From, Into, PrimitiveCmp,
30)]
31pub struct RecordCount(pub u64);
32
33/// Count of signed checkpoints.
34#[derive(
35    Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord, Display, From, Into, PrimitiveCmp,
36)]
37pub struct CheckpointCount(pub u64);
38
39/// Number of bytes currently held in the spool.
40#[derive(
41    Debug,
42    Clone,
43    Copy,
44    PartialEq,
45    Eq,
46    Hash,
47    PartialOrd,
48    Ord,
49    Display,
50    From,
51    Into,
52    Add,
53    AddAssign,
54    PrimitiveCmp,
55)]
56pub struct SpoolBytes(pub u64);
57
58/// Configured upper bound on spool size in bytes.
59#[derive(
60    Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord, Display, From, Into, PrimitiveCmp,
61)]
62pub struct MaxSpoolBytes(pub u64);