aboutsummaryrefslogtreecommitdiff
path: root/sth.go
diff options
context:
space:
mode:
authorRasmus Dahlberg <rasmus.dahlberg@kau.se>2021-02-18 17:51:05 +0100
committerRasmus Dahlberg <rasmus.dahlberg@kau.se>2021-02-18 17:51:05 +0100
commit55a0a1c9c2a6df4f05d539f0fc67a8c7052a338f (patch)
tree7a3608849a876338d2c4ed445bd0cda7182654ef /sth.go
parent86573a8daaa9c0972c088e8b2ddec6fdb95d86d2 (diff)
fixed unexpected reflect behavior
After tls.Unmarshal() an empty slice is not assigned the nil value, but rather a slice of zero length. It is in contrast to NewTreeHeadV1(), which assigns a nil value. Therefore, reflect.DeepEqual() considers them to be different. Fixed by assigning an empty tree head extension as `make([]byte, 0)`, and not looking for nil values but rather zero-length values with len(). Further read: "Note that a non-nil empty slice and a nil slice [...] are not deeply equal." (https://golang.org/pkg/reflect/#DeepEqual).
Diffstat (limited to 'sth.go')
-rw-r--r--sth.go14
1 files changed, 1 insertions, 13 deletions
diff --git a/sth.go b/sth.go
index e251b98..5cf3413 100644
--- a/sth.go
+++ b/sth.go
@@ -1,7 +1,6 @@
package stfe
import (
- "bytes"
"context"
"fmt"
"reflect"
@@ -91,21 +90,10 @@ func (s *ActiveSthSource) Cosigned(_ context.Context) (*StItem, error) {
return s.currSth, nil
}
-func (a *SignedTreeHeadV1) Equals(b *SignedTreeHeadV1) bool {
- return bytes.Equal(a.LogId, b.LogId) &&
- bytes.Equal(a.Signature, b.Signature) &&
- a.TreeHead.Timestamp == b.TreeHead.Timestamp &&
- a.TreeHead.TreeSize == b.TreeHead.TreeSize &&
- bytes.Equal(a.TreeHead.RootHash.Data, b.TreeHead.RootHash.Data) &&
- bytes.Equal(a.TreeHead.Extension, b.TreeHead.Extension)
- // TODO: why reflect.DeepEqual(a, b) gives a different result? Fixme.
-}
-
func (s *ActiveSthSource) AddCosignature(_ context.Context, costh *StItem) error {
s.mutex.Lock()
defer s.mutex.Unlock()
- //if !reflect.DeepEqual(s.nextSth.CosignedTreeHeadV1.SignedTreeHeadV1, costh.CosignedTreeHeadV1.SignedTreeHeadV1) {
- if !(&s.nextSth.CosignedTreeHeadV1.SignedTreeHeadV1).Equals(&costh.CosignedTreeHeadV1.SignedTreeHeadV1) {
+ if !reflect.DeepEqual(s.nextSth.CosignedTreeHeadV1.SignedTreeHeadV1, costh.CosignedTreeHeadV1.SignedTreeHeadV1) {
return fmt.Errorf("cosignature covers a different tree head")
}
witness := costh.CosignedTreeHeadV1.SignatureV1[0].Namespace.String()