aboutsummaryrefslogtreecommitdiff
path: root/types/stitem.go
diff options
context:
space:
mode:
authorRasmus Dahlberg <rasmus.dahlberg@kau.se>2021-02-25 14:36:35 +0100
committerRasmus Dahlberg <rasmus.dahlberg@kau.se>2021-02-25 14:36:35 +0100
commitc05c22ddbc771e7713849cae40f9d91bfafa0503 (patch)
treeb97d11ab2a914806e6f671f9aff1cab9767b2eab /types/stitem.go
parentc9b4b43654f0ff26207cc63449f13298cd3c56e8 (diff)
major refactor based on README.md and TODOs
Updated types, improved units tests, isolated most test data to have it in one place, renamed and created new files to improve readability, and fixed a bunch of minor TODOs.
Diffstat (limited to 'types/stitem.go')
-rw-r--r--types/stitem.go71
1 files changed, 71 insertions, 0 deletions
diff --git a/types/stitem.go b/types/stitem.go
index b214082..447cad0 100644
--- a/types/stitem.go
+++ b/types/stitem.go
@@ -119,3 +119,74 @@ func (i StItem) String() string {
return fmt.Sprintf("unknown StItem: %v", i.Format)
}
}
+
+func NewSignedTreeHeadV1(th *TreeHeadV1, sig *SignatureV1) *StItem {
+ return &StItem{
+ Format: StFormatSignedTreeHeadV1,
+ SignedTreeHeadV1: &SignedTreeHeadV1{
+ TreeHead: *th,
+ Signature: *sig,
+ },
+ }
+}
+
+func NewCosignedTreeHeadV1(sth *SignedTreeHeadV1, cosig []SignatureV1) *StItem {
+ if cosig == nil {
+ cosig = make([]SignatureV1, 0)
+ }
+ return &StItem{
+ Format: StFormatCosignedTreeHeadV1,
+ CosignedTreeHeadV1: &CosignedTreeHeadV1{
+ SignedTreeHead: *sth,
+ Cosignatures: cosig,
+ },
+ }
+}
+
+func NewConsistencyProofV1(id *Namespace, size1, size2 uint64, path []NodeHash) *StItem {
+ return &StItem{
+ Format: StFormatConsistencyProofV1,
+ ConsistencyProofV1: &ConsistencyProofV1{
+ LogId: *id,
+ TreeSize1: size1,
+ TreeSize2: size2,
+ ConsistencyPath: path,
+ },
+ }
+}
+
+func NewInclusionProofV1(id *Namespace, size, index uint64, path []NodeHash) *StItem {
+ return &StItem{
+ Format: StFormatInclusionProofV1,
+ InclusionProofV1: &InclusionProofV1{
+ LogId: *id,
+ TreeSize: size,
+ LeafIndex: index,
+ InclusionPath: path,
+ },
+ }
+}
+
+func NewSignedChecksumV1(data *ChecksumV1, sig *SignatureV1) *StItem {
+ return &StItem{
+ Format: StFormatSignedChecksumV1,
+ SignedChecksumV1: &SignedChecksumV1{
+ Data: *data,
+ Signature: *sig,
+ },
+ }
+}
+
+func NewTreeHeadV1(timestamp, size uint64, hash, extension []byte) *TreeHeadV1 {
+ if extension == nil {
+ extension = make([]byte, 0)
+ }
+ return &TreeHeadV1{
+ Timestamp: timestamp,
+ TreeSize: size,
+ RootHash: NodeHash{
+ Data: hash,
+ },
+ Extension: extension,
+ }
+}