Documentation
¶
Overview ¶
Package diff provides comparison utilities for evidence packs.
Index ¶
Constants ¶
const ( // ContentIdentical means both artifacts have the same content. ContentIdentical ContentStatus = iota // ContentDifferent means the artifacts exist in both packs but have different content. ContentDifferent // ContentOnlyInPack1 means the artifact only exists in pack 1. ContentOnlyInPack1 // ContentOnlyInPack2 means the artifact only exists in pack 2. ContentOnlyInPack2 // ContentNotFound means the artifact doesn't exist in either pack. ContentNotFound // ContentIntegrityError means reading the artifact failed due to integrity check // (digest mismatch, size mismatch). This is a SECURITY-CRITICAL status that // indicates the pack may have been tampered with. ContentIntegrityError // JSON change types JSONAdded JSONChangeType = iota JSONRemoved JSONChanged // Line diff types LineEqual LineDiffType = iota LineAdded LineRemoved )
const MaxDiffLines = 10000
MaxDiffLines is the maximum number of lines supported for text diff. Prevents quadratic memory/time DoS attacks via large inputs. For larger files, use external diff tools.
const MaxDiffMemoryBytes = 100 * 1024 * 1024
MaxDiffMemoryBytes is the maximum memory allowed for LCS table (100 MB).
Variables ¶
This section is empty.
Functions ¶
func FormatJSONValue ¶
func FormatJSONValue(v interface{}) string
FormatJSONValue formats a JSON value for display.
Types ¶
type ContentResult ¶
type ContentResult struct {
Status ContentStatus
// IsJSON indicates whether both artifacts were valid JSON.
IsJSON bool
// JSONChanges contains the structured diff for JSON content.
// Only populated when IsJSON is true and Status is ContentDifferent.
JSONChanges []JSONChange
// TextDiff contains the line-based diff for text content.
// Only populated when IsJSON is false and Status is ContentDifferent.
TextDiff []LineDiff
// IntegrityError contains details about the integrity failure.
// Only populated when Status is ContentIntegrityError.
// SECURITY: This indicates potential pack tampering - do not ignore.
IntegrityError *IntegrityErrorInfo
}
ContentResult contains the result of comparing a specific artifact's content.
func Content ¶
func Content(p1, p2 *pack.Pack, artifactPath string) (*ContentResult, error)
Content compares a specific artifact's content between two packs. SECURITY: If either pack has an integrity error (digest/size mismatch), this returns ContentIntegrityError instead of masking it as "missing".
type ContentStatus ¶
type ContentStatus int
ContentStatus indicates the comparison status of an artifact.
func (ContentStatus) String ¶
func (s ContentStatus) String() string
String returns a human-readable status description.
type ErrDiffTooLarge ¶
ErrDiffTooLarge is returned when input exceeds diff size limits.
func (ErrDiffTooLarge) Error ¶
func (e ErrDiffTooLarge) Error() string
type IntegrityErrorInfo ¶
type IntegrityErrorInfo struct {
// Pack indicates which pack had the integrity error ("pack1" or "pack2" or "both")
Pack string
// Code is the error code (e.g., "digest_mismatch", "size_mismatch")
Code string
// Message is the error message
Message string
}
IntegrityErrorInfo contains details about an integrity verification failure.
type JSONChange ¶
type JSONChange struct {
Type JSONChangeType
Path string // JSON path (e.g., "root.nested.key" or "[0].field")
OldValue interface{} // nil for added
NewValue interface{} // nil for removed
}
JSONChange represents a single change in JSON content.
type JSONChangeType ¶
type JSONChangeType int
JSONChangeType indicates the type of JSON change.
func (JSONChangeType) String ¶
func (t JSONChangeType) String() string
String returns a human-readable change type.
type LineDiff ¶
type LineDiff struct {
Type LineDiffType
Line string
}
LineDiff represents a single line in a text diff.
func ComputeLineDiff ¶
ComputeLineDiff computes a diff between two slices of lines using LCS. Returns an error if input is too large to prevent DoS attacks. For inputs exceeding MaxDiffLines, returns ErrDiffTooLarge.
type Result ¶
type Result struct {
Pack1 PackInfo `json:"pack1"`
Pack2 PackInfo `json:"pack2"`
Added []string `json:"added"` // Paths only in pack2
Removed []string `json:"removed"` // Paths only in pack1
Changed []string `json:"changed"` // Paths in both with different digests
Unchanged []string `json:"unchanged"` // Paths in both with same digest
}
Result contains the differences between two packs.
func (*Result) IsIdentical ¶
IsIdentical returns true if the packs have no differences.