Documentation
¶
Overview ¶
Package hash_chain provides hash chain validation with Merkle tree integration.
This package implements a cryptographic hash chain system that provides:
- Feed history integrity validation
- Tamper detection mechanisms
- Merkle tree integration for efficient verification
- Audit logging for compliance
- Integration with threat intel packages
The hash chain validation system is designed to work with feed-specific trust domains in AegisGate v0.19.0.
Index ¶
- type Hash
- type HashChain
- func (hc *HashChain) AddEntry(data []byte) (*HashChainEntry, error)
- func (hc *HashChain) GetAuditLog() []*HashChainEntry
- func (hc *HashChain) GetChainLength() int
- func (hc *HashChain) GetChainVerificationReport() string
- func (hc *HashChain) GetEntry(seqNum uint64) (*HashChainEntry, bool)
- func (hc *HashChain) GetEntryByHash(hash Hash) (*HashChainEntry, bool)
- func (hc *HashChain) GetEntryRange(start, end uint64) ([]*HashChainEntry, error)
- func (hc *HashChain) GetLastEntry() (*HashChainEntry, bool)
- func (hc *HashChain) GetMerkleRoot() Hash
- func (hc *HashChain) GetProof(entry *HashChainEntry) ([]Hash, error)
- func (hc *HashChain) IsValidChain() bool
- func (hc *HashChain) VerifyChain() (bool, error)
- func (hc *HashChain) VerifyChainFixed() (bool, error)
- func (hc *HashChain) VerifyEntry(entry *HashChainEntry) (bool, error)
- func (hc *HashChain) VerifyEntryFixed(entry *HashChainEntry) (bool, error)
- func (hc *HashChain) VerifyProof(entryHash Hash, proof []Hash, root Hash) (bool, error)
- type HashChainEntry
- type HashStore
- type HashType
- type MemoryHashStore
- func (mhs *MemoryHashStore) DeleteFeedHashes(feedID string) error
- func (mhs *MemoryHashStore) GetChain(feedID string) (string, error)
- func (mhs *MemoryHashStore) GetChainHashes(feedID string) ([]string, error)
- func (mhs *MemoryHashStore) StoreHash(feedID, hash, previousHash string) error
- func (mhs *MemoryHashStore) VerifyChain(feedID string) (bool, error)
- func (mhs *MemoryHashStore) VerifyHash(feedID, hash, previousHash string) (bool, error)
- type ValidationError
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type HashChain ¶
type HashChain struct {
Entries []*HashChainEntry
MerkleTree []*merkleNode
// contains filtered or unexported fields
}
HashChain represents a hash chain for a specific feed
func NewHashChain ¶
NewHashChain creates a new hash chain for a feed
func (*HashChain) AddEntry ¶
func (hc *HashChain) AddEntry(data []byte) (*HashChainEntry, error)
AddEntry adds a new entry to the hash chain
func (*HashChain) GetAuditLog ¶
func (hc *HashChain) GetAuditLog() []*HashChainEntry
GetAuditLog returns the audit log entries
func (*HashChain) GetChainLength ¶
GetChainLength returns the number of entries in the chain
func (*HashChain) GetChainVerificationReport ¶
GetChainVerificationReport returns a verification report
func (*HashChain) GetEntry ¶
func (hc *HashChain) GetEntry(seqNum uint64) (*HashChainEntry, bool)
GetEntry retrieves an entry by sequence number
func (*HashChain) GetEntryByHash ¶
func (hc *HashChain) GetEntryByHash(hash Hash) (*HashChainEntry, bool)
GetEntryByHash retrieves an entry by its hash
func (*HashChain) GetEntryRange ¶
func (hc *HashChain) GetEntryRange(start, end uint64) ([]*HashChainEntry, error)
GetEntryRange returns a range of entries
func (*HashChain) GetLastEntry ¶
func (hc *HashChain) GetLastEntry() (*HashChainEntry, bool)
GetLastEntry returns the last entry in the chain
func (*HashChain) GetMerkleRoot ¶
GetMerkleRoot returns the Merkle root hash
func (*HashChain) GetProof ¶
func (hc *HashChain) GetProof(entry *HashChainEntry) ([]Hash, error)
GetProof generates a Merkle proof for an entry
func (*HashChain) IsValidChain ¶
IsValidChain is a convenience method
func (*HashChain) VerifyChain ¶
VerifyChain verifies the entire hash chain FIXED: Uses correct verification logic
func (*HashChain) VerifyChainFixed ¶
VerifyChainFixed is an alias for VerifyChain (for backward compatibility)
func (*HashChain) VerifyEntry ¶
func (hc *HashChain) VerifyEntry(entry *HashChainEntry) (bool, error)
VerifyEntry verifies a single entry in the hash chain This is the correct implementation with proper locking
func (*HashChain) VerifyEntryFixed ¶
func (hc *HashChain) VerifyEntryFixed(entry *HashChainEntry) (bool, error)
VerifyEntryFixed is an alias for VerifyEntry (for backward compatibility)
type HashChainEntry ¶
type HashChainEntry struct {
Hash Hash // Hash of the entry (computed from PayloadHash + PreviousHash + etc)
PayloadHash Hash // Hash of the original data payload
PreviousHash Hash // Hash of the previous entry
SequenceNum uint64 // Sequence number of this entry
Operation string // Operation performed
Timestamp time.Time // Timestamp of the entry
}
HashChainEntry represents a single entry in the hash chain
type HashStore ¶
type HashStore interface {
// GetChain returns a hash chain for a feed
GetChain(feedID string) (*HashChain, error)
// StoreHash stores a hash in the chain
StoreHash(feedID string, hash string, previousHash string) error
// VerifyHash verifies a hash in the chain
VerifyHash(feedID string, hash string, previousHash string) (bool, error)
// GetChainHashes returns all hashes for a feed
GetChainHashes(feedID string) ([]string, error)
// DeleteFeedHashes deletes all hashes for a feed
DeleteFeedHashes(feedID string) error
// VerifyChain verifies the integrity of a hash chain
VerifyChain(feedID string) (bool, error)
}
HashStore defines the interface for hash storage
type MemoryHashStore ¶
type MemoryHashStore struct {
// contains filtered or unexported fields
}
MemoryHashStore provides in-memory storage for hash chains
func NewMemoryHashStore ¶
func NewMemoryHashStore() *MemoryHashStore
NewMemoryHashStore creates a new memory hash store
func (*MemoryHashStore) DeleteFeedHashes ¶
func (mhs *MemoryHashStore) DeleteFeedHashes(feedID string) error
DeleteFeedHashes deletes all hashes for a feed
func (*MemoryHashStore) GetChain ¶
func (mhs *MemoryHashStore) GetChain(feedID string) (string, error)
GetChain retrieves hashes for a feed
func (*MemoryHashStore) GetChainHashes ¶
func (mhs *MemoryHashStore) GetChainHashes(feedID string) ([]string, error)
GetChainHashes returns all hashes for a feed
func (*MemoryHashStore) StoreHash ¶
func (mhs *MemoryHashStore) StoreHash(feedID, hash, previousHash string) error
StoreHash stores a hash in the store
func (*MemoryHashStore) VerifyChain ¶
func (mhs *MemoryHashStore) VerifyChain(feedID string) (bool, error)
VerifyChain verifies a chain in the store
func (*MemoryHashStore) VerifyHash ¶
func (mhs *MemoryHashStore) VerifyHash(feedID, hash, previousHash string) (bool, error)
VerifyHash verifies a hash exists in the store
type ValidationError ¶
ValidationError represents an error during chain verification
func (*ValidationError) Error ¶
func (e *ValidationError) Error() string