From c05c22ddbc771e7713849cae40f9d91bfafa0503 Mon Sep 17 00:00:00 2001 From: Rasmus Dahlberg Date: Thu, 25 Feb 2021 14:36:35 +0100 Subject: 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. --- types/namespace_test.go | 3 +-- types/stitem.go | 71 +++++++++++++++++++++++++++++++++++++++++++++++++ types/stitem_test.go | 24 +++++++++++++++++ 3 files changed, 96 insertions(+), 2 deletions(-) (limited to 'types') diff --git a/types/namespace_test.go b/types/namespace_test.go index c38d295..a5847ef 100644 --- a/types/namespace_test.go +++ b/types/namespace_test.go @@ -146,8 +146,7 @@ func test_cases_verify(t *testing.T) []testCaseNamespace { // test_cases_verify_ed25519v1 returns ed25519_v1 Namespace.Verify() tests func test_cases_verify_ed25519v1(t *testing.T) []testCaseNamespace { testEd25519Sk := [64]byte{230, 122, 195, 152, 194, 195, 147, 153, 80, 120, 153, 79, 102, 27, 52, 187, 136, 218, 150, 234, 107, 9, 167, 4, 92, 21, 11, 113, 42, 29, 129, 69, 75, 60, 249, 150, 229, 93, 75, 32, 103, 126, 244, 37, 53, 182, 68, 82, 249, 109, 49, 94, 10, 19, 146, 244, 58, 191, 169, 107, 78, 37, 45, 210} - testEd25519Vk := [32]byte{75, 60, 249, 150, 229, 93, 75, 32, 103, 126, 244, 37, 53, 182, 68, 82, 249, 109, 49, 94, 10, 19, 146, 244, 58, 191, 169, 107, 78, - 37, 45, 210} + testEd25519Vk := [32]byte{75, 60, 249, 150, 229, 93, 75, 32, 103, 126, 244, 37, 53, 182, 68, 82, 249, 109, 49, 94, 10, 19, 146, 244, 58, 191, 169, 107, 78, 37, 45, 210} return []testCaseNamespace{ { description: "test_cases_verify_ed25519v1: invalid: sk signed message, but vk is not for sk", 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, + } +} diff --git a/types/stitem_test.go b/types/stitem_test.go index c6e413a..90d6808 100644 --- a/types/stitem_test.go +++ b/types/stitem_test.go @@ -38,3 +38,27 @@ func TestStItemString(t *testing.T) { } } } + +// TODO: TestNewSignedTreeHeadV1 +func TestNewSignedTreeHeadV1(t *testing.T) { +} + +// TODO: TestNewCosignedTreeHeadV1 +func TestNewCosignedTreeHeadV1(t *testing.T) { +} + +// TODO: TestNewConsistencyProofV1 +func TestNewConsistencyProofV1(t *testing.T) { +} + +// TODO: TestNewInclusionProofV1 +func TestNewInclusionProofV1(t *testing.T) { +} + +// TODO: TestNewSignedChecksumV1 +func TestNewSignedChecksumV1(t *testing.T) { +} + +// TODO: TestNewTreeHeadV1 +func TestNewTreeHeadV1(t *testing.T) { +} -- cgit v1.2.3