pub struct AuditEnvelope<T: Serialize> { /* private fields */ }Expand description
A signed wrapper around any serializable payload.
The envelope carries the payload plus a chain of signatures. Each signature in the chain signs the canonical bytes of the payload AND all previous signatures, creating a tamper-evident chain:
sig[0] = sign(canonical(payload))
sig[1] = sign(canonical(payload) + sig[0].signature_bytes)
sig[2] = sign(canonical(payload) + sig[0].signature_bytes + sig[1].signature_bytes)Removing or reordering any signature invalidates all subsequent signatures.
§Security note
Fields are pub for serialization compatibility. Mutating any signed field
(payload, subject, timestamp, agent_id, signatures) invalidates
status without detection. Always call verify_chain() after
deserialization or if the envelope may have been modified. For defense in
depth, prefer reading via accessor methods and treat status as advisory
until re-verified.
Implementations§
Source§impl<T: Serialize> AuditEnvelope<T>
impl<T: Serialize> AuditEnvelope<T>
Sourcepub fn unsigned(payload: T, subject: &str, agent_id: &str) -> Self
pub fn unsigned(payload: T, subject: &str, agent_id: &str) -> Self
Create an unsigned envelope (dev mode / legacy).
Sourcepub async fn signed(
payload: T,
subject: &str,
agent_id: &str,
signer: &dyn AuditSigner,
) -> Result<Self, CryptoError>
pub async fn signed( payload: T, subject: &str, agent_id: &str, signer: &dyn AuditSigner, ) -> Result<Self, CryptoError>
Create a signed envelope with a single author signature.
Sourcepub async fn co_sign(
&mut self,
signer: &dyn AuditSigner,
role: SignerRole,
signer_id: &str,
) -> Result<(), CryptoError>
pub async fn co_sign( &mut self, signer: &dyn AuditSigner, role: SignerRole, signer_id: &str, ) -> Result<(), CryptoError>
Add a co-signature to the chain. The new signer signs the payload canonical bytes + all existing signatures, creating an ordered chain.
Sourcepub fn verify_chain(
&mut self,
registry: &VerifierRegistry,
) -> Result<bool, CryptoError>
pub fn verify_chain( &mut self, registry: &VerifierRegistry, ) -> Result<bool, CryptoError>
Verify the entire signature chain using a verifier registry.
Each signature is verified against the payload canonical bytes + all prior signatures. If any signature fails, the chain is invalid.
Sourcepub fn verify(
&mut self,
registry: &VerifierRegistry,
) -> Result<bool, CryptoError>
pub fn verify( &mut self, registry: &VerifierRegistry, ) -> Result<bool, CryptoError>
Backward-compatible verify (legacy single-signature envelopes).
Delegates to verify_chain.
Sourcepub fn signature_count(&self) -> usize
pub fn signature_count(&self) -> usize
Number of signatures in the chain.
Sourcepub fn has_role(&self, role: &SignerRole) -> bool
pub fn has_role(&self, role: &SignerRole) -> bool
Check if the chain contains a signature with the given role.
Sourcepub fn status(&self) -> &SignatureStatus
pub fn status(&self) -> &SignatureStatus
Current verification status. Advisory only — always call
verify_chain() after deserialization or if the envelope may have been
modified externally.
Sourcepub fn signatures(&self) -> &[EnvelopeSignature]
pub fn signatures(&self) -> &[EnvelopeSignature]
Read-only access to the signature chain.
Sourcepub fn invalidate(&mut self)
pub fn invalidate(&mut self)
Explicitly invalidate the cached verification status. Call this after any mutation to signed fields.
Trait Implementations§
Source§impl<T: Clone + Serialize> Clone for AuditEnvelope<T>
impl<T: Clone + Serialize> Clone for AuditEnvelope<T>
Source§fn clone(&self) -> AuditEnvelope<T>
fn clone(&self) -> AuditEnvelope<T>
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more