aboutsummaryrefslogtreecommitdiff
path: root/pkg/types/trunnel.go
diff options
context:
space:
mode:
authorRasmus Dahlberg <rasmus@mullvad.net>2021-12-20 19:53:54 +0100
committerRasmus Dahlberg <rasmus@mullvad.net>2021-12-20 19:53:54 +0100
commitdda238b9fc105219f220f0ec3b341b0c81b71301 (patch)
treeedbbb787ccd1c1816edfa44caf749c8be68b7bf9 /pkg/types/trunnel.go
parent5ba4a77233549819440cc41a02503f3a85213e24 (diff)
types: Start using sigsum-lib-go
This commit does not change the way in which the log behaves externally. In other words, all changes are internal and involves renaming and code restructuring. Most notably picking up the refactored sigsum-lib-go.
Diffstat (limited to 'pkg/types/trunnel.go')
-rw-r--r--pkg/types/trunnel.go63
1 files changed, 0 insertions, 63 deletions
diff --git a/pkg/types/trunnel.go b/pkg/types/trunnel.go
deleted file mode 100644
index 5350c5b..0000000
--- a/pkg/types/trunnel.go
+++ /dev/null
@@ -1,63 +0,0 @@
-package types
-
-import (
- "encoding/binary"
- "fmt"
-)
-
-const (
- // MessageSize is the number of bytes in a Trunnel-encoded leaf message
- MessageSize = 8 + HashSize
- // LeafSize is the number of bytes in a Trunnel-encoded leaf
- LeafSize = MessageSize + SignatureSize + HashSize
- // TreeHeadSize is the number of bytes in a Trunnel-encoded tree head
- TreeHeadSize = 8 + 8 + HashSize + HashSize
-)
-
-// Marshal returns a Trunnel-encoded message
-func (m *Message) Marshal() []byte {
- buf := make([]byte, MessageSize)
- binary.BigEndian.PutUint64(buf, m.ShardHint)
- copy(buf[8:], m.Checksum[:])
- return buf
-}
-
-// Marshal returns a Trunnel-encoded leaf
-func (l *Leaf) Marshal() []byte {
- buf := l.Message.Marshal()
- buf = append(buf, l.SigIdent.Signature[:]...)
- buf = append(buf, l.SigIdent.KeyHash[:]...)
- return buf
-}
-
-// Marshal returns a Trunnel-encoded tree head
-func (th *TreeHead) Marshal() []byte {
- buf := make([]byte, TreeHeadSize)
- binary.BigEndian.PutUint64(buf[0:8], th.Timestamp)
- binary.BigEndian.PutUint64(buf[8:16], th.TreeSize)
- copy(buf[16:16+HashSize], th.RootHash[:])
- copy(buf[16+HashSize:], th.KeyHash[:])
- return buf
-}
-
-// Unmarshal parses the Trunnel-encoded buffer as a leaf
-func (l *Leaf) Unmarshal(buf []byte) error {
- if len(buf) != LeafSize {
- return fmt.Errorf("invalid leaf size: %v", len(buf))
- }
- // Shard hint
- l.ShardHint = binary.BigEndian.Uint64(buf)
- offset := 8
- // Checksum
- l.Checksum = &[HashSize]byte{}
- copy(l.Checksum[:], buf[offset:offset+HashSize])
- offset += HashSize
- // Signature
- l.Signature = &[SignatureSize]byte{}
- copy(l.Signature[:], buf[offset:offset+SignatureSize])
- offset += SignatureSize
- // KeyHash
- l.KeyHash = &[HashSize]byte{}
- copy(l.KeyHash[:], buf[offset:])
- return nil
-}