pub struct AuditEvent {
pub id: u64,
pub timestamp: i64,
pub principal: String,
pub action: AuditAction,
pub resource: String,
pub decision: AuditDecision,
pub source_ip: Option<String>,
pub request_id: Option<String>,
pub metadata: HashMap<String, String>,
pub prev_hash: Option<String>,
pub event_hash: Option<String>,
}Expand description
A structured audit event capturing a security-relevant operation.
Events carry a SHA-256 hash chain — each event’s event_hash
covers prev_hash || canonical_payload, making log tampering detectable
by verifying the chain with verify_hash_chain.
Fields§
§id: u64Monotonically increasing event ID.
timestamp: i64Nanosecond timestamp.
principal: StringThe principal (user / service) that performed the action.
action: AuditActionThe action performed.
resource: StringThe resource targeted (measurement, series, etc.).
decision: AuditDecisionAuthorization decision.
source_ip: Option<String>Source IP address (if available).
request_id: Option<String>Request ID for correlation.
metadata: HashMap<String, String>Additional context (e.g., deny reasons, error details).
prev_hash: Option<String>Hex SHA-256 hash of the previous event (or None for the
first event in the chain).
event_hash: Option<String>Hex SHA-256 hash of prev_hash || canonical_payload.
Implementations§
Source§impl AuditEvent
impl AuditEvent
Sourcepub fn new(
principal: impl Into<String>,
action: AuditAction,
resource: impl Into<String>,
decision: AuditDecision,
) -> Self
pub fn new( principal: impl Into<String>, action: AuditAction, resource: impl Into<String>, decision: AuditDecision, ) -> Self
Create a new audit event builder.
Sourcepub fn with_source_ip(self, ip: impl Into<String>) -> Self
pub fn with_source_ip(self, ip: impl Into<String>) -> Self
Set the source IP.
Sourcepub fn with_request_id(self, id: impl Into<String>) -> Self
pub fn with_request_id(self, id: impl Into<String>) -> Self
Set the request ID.
Sourcepub fn with_metadata(
self,
key: impl Into<String>,
value: impl Into<String>,
) -> Self
pub fn with_metadata( self, key: impl Into<String>, value: impl Into<String>, ) -> Self
Add a metadata key-value pair.
Sourcepub fn with_timestamp(self, ts: i64) -> Self
pub fn with_timestamp(self, ts: i64) -> Self
Set the timestamp explicitly (for tests).
Source§impl AuditEvent
impl AuditEvent
Sourcepub fn seal(&mut self, prev_hash: Option<&str>)
pub fn seal(&mut self, prev_hash: Option<&str>)
Compute HMAC-SHA-256 of prev_hash || canonical_payload and set
self.prev_hash and self.event_hash.
Uses HMAC with a secret key instead of plain SHA-256, so an attacker with database write access cannot recompute the chain. Falls back to plain SHA-256 if no key is provided (backward compat).
Trait Implementations§
Source§impl Clone for AuditEvent
impl Clone for AuditEvent
Source§fn clone(&self) -> AuditEvent
fn clone(&self) -> AuditEvent
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for AuditEvent
impl Debug for AuditEvent
Source§impl<'de> Deserialize<'de> for AuditEvent
impl<'de> Deserialize<'de> for AuditEvent
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl Display for AuditEvent
impl Display for AuditEvent
Auto Trait Implementations§
impl Freeze for AuditEvent
impl RefUnwindSafe for AuditEvent
impl Send for AuditEvent
impl Sync for AuditEvent
impl Unpin for AuditEvent
impl UnsafeUnpin for AuditEvent
impl UnwindSafe for AuditEvent
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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