pub struct AuditEntry {
pub id: String,
pub timestamp: DateTime<Utc>,
pub event_type: String,
pub actor: String,
pub resource: Option<String>,
pub action: String,
pub outcome: AuditOutcome,
pub metadata: Value,
pub hmac_signature: Option<String>,
pub previous_hmac: Option<String>,
}Expand description
Audit log entry.
Fields§
§id: StringUnique entry ID.
timestamp: DateTime<Utc>Timestamp of the event.
event_type: StringEvent type.
actor: StringActor (user or system).
resource: Option<String>Resource affected.
action: StringAction taken.
outcome: AuditOutcomeOutcome (success/failure).
metadata: ValueAdditional metadata.
hmac_signature: Option<String>HMAC signature of this entry (hex-encoded).
Computed as: HMAC-SHA256(key, id || timestamp || event_type || action || previous_hmac)
previous_hmac: Option<String>HMAC of the previous entry in the chain (hex-encoded).
First entry in chain has previous_hmac = “genesis”.
Implementations§
Source§impl AuditEntry
impl AuditEntry
Sourcepub fn new(event_type: impl Into<String>, action: impl Into<String>) -> Self
pub fn new(event_type: impl Into<String>, action: impl Into<String>) -> Self
Creates a new audit entry for the current time.
Sourcepub fn canonical_string(&self, previous_hmac: &str) -> String
pub fn canonical_string(&self, previous_hmac: &str) -> String
Computes the canonical string for HMAC signing.
Format: id|timestamp|event_type|action|previous_hmac
Sourcepub fn compute_hmac(&self, key: &[u8], previous_hmac: &str) -> Option<String>
pub fn compute_hmac(&self, key: &[u8], previous_hmac: &str) -> Option<String>
Computes the HMAC signature for this entry.
Returns None if the HMAC key is invalid (should not happen with valid 32-byte keys).
Sourcepub fn sign(&mut self, key: &[u8], previous_hmac: &str) -> bool
pub fn sign(&mut self, key: &[u8], previous_hmac: &str) -> bool
Signs this entry with HMAC, setting both signature and previous hash.
Returns false if the HMAC key is invalid.
Sourcepub fn verify(&self, key: &[u8]) -> bool
pub fn verify(&self, key: &[u8]) -> bool
Verifies this entry’s HMAC signature.
Returns true if the signature is valid, false otherwise.
Sourcepub fn with_actor(self, actor: impl Into<String>) -> Self
pub fn with_actor(self, actor: impl Into<String>) -> Self
Sets the actor.
Sourcepub fn with_resource(self, resource: impl Into<String>) -> Self
pub fn with_resource(self, resource: impl Into<String>) -> Self
Sets the resource.
Sourcepub const fn with_outcome(self, outcome: AuditOutcome) -> Self
pub const fn with_outcome(self, outcome: AuditOutcome) -> Self
Sets the outcome.
Sourcepub fn with_metadata(self, metadata: Value) -> Self
pub fn with_metadata(self, metadata: Value) -> Self
Sets metadata.
Trait Implementations§
Source§impl Clone for AuditEntry
impl Clone for AuditEntry
Source§fn clone(&self) -> AuditEntry
fn clone(&self) -> AuditEntry
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for AuditEntry
impl Debug for AuditEntry
Source§impl<'de> Deserialize<'de> for AuditEntry
impl<'de> Deserialize<'de> for AuditEntry
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>,
Auto Trait Implementations§
impl Freeze for AuditEntry
impl RefUnwindSafe for AuditEntry
impl Send for AuditEntry
impl Sync for AuditEntry
impl Unpin for AuditEntry
impl UnwindSafe for AuditEntry
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> FutureExt for T
impl<T> FutureExt for T
§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§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§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request§impl<L> LayerExt<L> for L
impl<L> LayerExt<L> for L
§fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
Layered].