28 lines
616 B
Go
28 lines
616 B
Go
package domain
|
|
|
|
import "crypto/sha256"
|
|
|
|
type RequestHash [sha256.Size]byte
|
|
|
|
func HashImmutableRequest(canonical []byte) RequestHash { return sha256.Sum256(canonical) }
|
|
|
|
type ReplayDecision uint8
|
|
|
|
const (
|
|
ReplayNew ReplayDecision = iota
|
|
ReplayExact
|
|
ReplayConflict
|
|
)
|
|
|
|
// ClassifyReplay compares a canonical immutable request against durable state.
|
|
// A nil stored hash means no mutation with this request UUID exists.
|
|
func ClassifyReplay(stored *RequestHash, incoming RequestHash) ReplayDecision {
|
|
if stored == nil {
|
|
return ReplayNew
|
|
}
|
|
if *stored == incoming {
|
|
return ReplayExact
|
|
}
|
|
return ReplayConflict
|
|
}
|