Signet Forge 0.1.0
C++20 Parquet library with AI-native extensions
DEMO
Loading...
Searching...
No Matches
signet::forge::AuditChainWriter Class Reference

Builds SHA-256 hash chains during Parquet writes. More...

#include <audit_chain.hpp>

Public Member Functions

 AuditChainWriter ()
 Construct a new writer with an empty chain.
 
HashChainEntry append (const uint8_t *record_data, size_t record_size, int64_t timestamp_ns)
 Append a record to the chain with an explicit timestamp.
 
HashChainEntry append (const uint8_t *record_data, size_t record_size)
 Append a record with auto-generated timestamp from the system clock.
 
int64_t length () const
 Return the number of entries in the chain.
 
std::array< uint8_t, 32 > last_hash () const
 Return the entry_hash of the last entry in the chain.
 
const std::vector< HashChainEntry > & entries () const
 Return a const reference to the internal entry list.
 
std::vector< uint8_t > serialize_chain () const
 Serialize the entire chain to bytes.
 
void reset (std::array< uint8_t, 32 > initial_prev_hash={}, int64_t initial_seq=0)
 Clear the chain and optionally set an initial prev_hash.
 

Detailed Description

Builds SHA-256 hash chains during Parquet writes.

for (const auto& record : records) {
auto bytes = serialize_record(record);
auto entry = writer.append(bytes.data(), bytes.size());
}
auto chain_bytes = writer.serialize_chain();
// Store chain_bytes in Parquet metadata or a sidecar file
Builds SHA-256 hash chains during Parquet writes.
std::vector< uint8_t > serialize_chain() const
Serialize the entire chain to bytes.
HashChainEntry append(const uint8_t *record_data, size_t record_size, int64_t timestamp_ns)
Append a record to the chain with an explicit timestamp.

To continue a chain across files, save last_hash() from the previous file and pass it to the new writer's reset():

writer2.reset(previous_writer.last_hash());
void reset(std::array< uint8_t, 32 > initial_prev_hash={}, int64_t initial_seq=0)
Clear the chain and optionally set an initial prev_hash.
Note
NOT thread-safe. Callers must synchronize externally if appending from multiple threads.

Definition at line 408 of file audit_chain.hpp.

Constructor & Destructor Documentation

◆ AuditChainWriter()

signet::forge::AuditChainWriter::AuditChainWriter ( )
inline

Construct a new writer with an empty chain.

The first entry's prev_hash will be all zeros.

Exceptions
std::runtime_errorif the commercial license is required but missing.

Definition at line 413 of file audit_chain.hpp.

Member Function Documentation

◆ append() [1/2]

HashChainEntry signet::forge::AuditChainWriter::append ( const uint8_t *  record_data,
size_t  record_size 
)
inline

Append a record with auto-generated timestamp from the system clock.

Parameters
record_dataRaw bytes of the record being audited.
record_sizeSize of record_data in bytes.
Returns
The newly created HashChainEntry (by value).
See also
append(const uint8_t*, size_t, int64_t) for explicit timestamps.

Definition at line 453 of file audit_chain.hpp.

◆ append() [2/2]

HashChainEntry signet::forge::AuditChainWriter::append ( const uint8_t *  record_data,
size_t  record_size,
int64_t  timestamp_ns 
)
inline

Append a record to the chain with an explicit timestamp.

Hashes record_data to produce data_hash, sets prev_hash from the last entry (or zeros for the first), computes entry_hash, and appends the new entry to the internal list.

Parameters
record_dataRaw bytes of the record being audited.
record_sizeSize of record_data in bytes.
timestamp_nsNanosecond timestamp for this entry.
Returns
The newly created HashChainEntry (by value).

Definition at line 430 of file audit_chain.hpp.

◆ entries()

const std::vector< HashChainEntry > & signet::forge::AuditChainWriter::entries ( ) const
inline

Return a const reference to the internal entry list.

Definition at line 470 of file audit_chain.hpp.

◆ last_hash()

std::array< uint8_t, 32 > signet::forge::AuditChainWriter::last_hash ( ) const
inline

Return the entry_hash of the last entry in the chain.

If the chain is empty, returns all zeros (or the initial prev_hash if set via reset()).

Definition at line 465 of file audit_chain.hpp.

◆ length()

int64_t signet::forge::AuditChainWriter::length ( ) const
inline

Return the number of entries in the chain.

Definition at line 458 of file audit_chain.hpp.

◆ reset()

void signet::forge::AuditChainWriter::reset ( std::array< uint8_t, 32 >  initial_prev_hash = {},
int64_t  initial_seq = 0 
)
inline

Clear the chain and optionally set an initial prev_hash.

Call this to start a new chain. If initial_prev_hash is provided, the first entry's prev_hash will be set to that value instead of all zeros. This is used to continue a chain from a previous file.

Parameters
initial_prev_hashThe prev_hash for the next appended entry (default: all zeros).

Definition at line 511 of file audit_chain.hpp.

◆ serialize_chain()

std::vector< uint8_t > signet::forge::AuditChainWriter::serialize_chain ( ) const
inline

Serialize the entire chain to bytes.

Format: 4-byte entry count (uint32_t LE) followed by N * 112-byte entries. Total size = 4 + N * 112 bytes.

Returns
The serialized chain as a byte vector.

Definition at line 480 of file audit_chain.hpp.


The documentation for this class was generated from the following file: