From 3279459be226de7f11214cd2791285b5f10514ea Mon Sep 17 00:00:00 2001 From: Andrew Ayer Date: Mon, 16 Jun 2025 14:24:26 -0400 Subject: [PATCH] Add Compare to LogID and merkletree.Hash --- cttypes/logid.go | 5 +++++ merkletree/hash.go | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/cttypes/logid.go b/cttypes/logid.go index 5df8c7b..9e44aaa 100644 --- a/cttypes/logid.go +++ b/cttypes/logid.go @@ -10,6 +10,7 @@ package cttypes import ( + "bytes" "encoding/base64" "fmt" "golang.org/x/crypto/cryptobyte" @@ -17,6 +18,10 @@ import ( type LogID [32]byte +func (id LogID) Compare(other LogID) int { + return bytes.Compare(id[:], other[:]) +} + func (v *LogID) Unmarshal(s *cryptobyte.String) bool { return s.CopyBytes((*v)[:]) } diff --git a/merkletree/hash.go b/merkletree/hash.go index 4ddf9a2..2666ba0 100644 --- a/merkletree/hash.go +++ b/merkletree/hash.go @@ -10,6 +10,7 @@ package merkletree import ( + "bytes" "crypto/sha256" "encoding/base64" "encoding/json" @@ -20,6 +21,10 @@ const HashLen = 32 type Hash [HashLen]byte +func (h Hash) Compare(other Hash) int { + return bytes.Compare(h[:], other[:]) +} + func (h Hash) Base64String() string { return base64.StdEncoding.EncodeToString(h[:]) }