diff options
author | Rasmus Dahlberg <rasmus.dahlberg@kau.se> | 2020-10-28 14:56:11 +0100 |
---|---|---|
committer | Rasmus Dahlberg <rasmus.dahlberg@kau.se> | 2020-10-28 14:56:11 +0100 |
commit | caca215c9516e8dc236a8510a6a5467c267d2331 (patch) | |
tree | b4d0ee37f09e525e9402c5d2bdcbed72ef0cd483 /type.go | |
parent | d752d967335e1418f27e03e0389b01178b28f232 (diff) |
added consistency-proof code path
Diffstat (limited to 'type.go')
-rw-r--r-- | type.go | 37 |
1 files changed, 36 insertions, 1 deletions
@@ -28,11 +28,18 @@ type StItem struct { Format StFormat `tls:"maxval:65535"` SignedTreeHeadV1 *SignedTreeHeadV1 `tls:"selector:Format,val:1"` SignedDebugInfoV1 *SignedDebugInfoV1 `tls:"selector:Format,val:2"` - // TODO: add consistency proof + ConsistencyProofV1 *ConsistencyProofV1 `tls:"selector:Format,val:3"` InclusionProofV1 *InclusionProofV1 `tls:"selector:Format,val:4"` ChecksumV1 *ChecksumV1 `tls:"selector:Format,val:5"` } +type ConsistencyProofV1 struct { + LogId []byte `tls:"minlen:2,maxlen:127"` + TreeSize1 uint64 + TreeSize2 uint64 + ConsistencyPath []NodeHash `tls:"minlen:1,maxlen:65535"` +} + type SignedTreeHeadV1 struct { LogId []byte `tls:"minlen:2,maxlen:127"` TreeHead TreeHeadV1 `tls:minlen:0, maxlen:65535` // what should maxlen be? @@ -137,6 +144,23 @@ func NewInclusionProofV1(logID []byte, treeSize uint64, proof *trillian.Proof) S } } +func NewConsistencyProofV1(logId []byte, first, second int64, proof *trillian.Proof) StItem { + path := make([]NodeHash, 0, len(proof.Hashes)) + for _, hash := range proof.Hashes { + path = append(path, NodeHash{Data: hash}) + } + + return StItem{ + Format: StFormatConsistencyProofV1, + ConsistencyProofV1: &ConsistencyProofV1{ + LogId: logId, + TreeSize1: uint64(first), + TreeSize2: uint64(second), + ConsistencyPath: path, + }, + } +} + func (f StFormat) String() string { switch f { case StFormatReserved: @@ -160,6 +184,8 @@ func (i StItem) String() string { switch i.Format { case StFormatChecksumV1: return fmt.Sprintf("Format(%s): %s", i.Format, *i.ChecksumV1) + case StFormatConsistencyProofV1: + return fmt.Sprintf("Format(%s): %s", i.Format, *i.ConsistencyProofV1) case StFormatInclusionProofV1: return fmt.Sprintf("Format(%s): %s", i.Format, *i.InclusionProofV1) case StFormatSignedDebugInfoV1: @@ -196,6 +222,15 @@ func (i InclusionProofV1) String() string { return fmt.Sprintf("LogID(%s) TreeSize(%d) LeafIndex(%d) AuditPath(%v)", base64.StdEncoding.EncodeToString(i.LogID), i.TreeSize, i.LeafIndex, path) } +func (i ConsistencyProofV1) String() string { + path := make([]string, 0, len(i.ConsistencyPath)) + for _, hash := range i.ConsistencyPath { + path = append(path, base64.StdEncoding.EncodeToString(hash.Data)) + } + + return fmt.Sprintf("LogID(%s) TreeSize1(%d) TreeSize2(%d) ConsistencyPath(%v)", base64.StdEncoding.EncodeToString(i.LogId), i.TreeSize1, i.TreeSize2, path) +} + // StItemFromB64 creates an StItem from a serialized and base64-encoded string func StItemFromB64(s string) (StItem, error) { b, err := base64.StdEncoding.DecodeString(s) |