From 65c41183088f111aa289d1ea4c51bef7fa971226 Mon Sep 17 00:00:00 2001 From: Rasmus Dahlberg Date: Tue, 23 Feb 2021 12:34:21 +0100 Subject: added proof request types --- types/serialize.go | 16 ++++++++++++++++ types/serialize_test.go | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) diff --git a/types/serialize.go b/types/serialize.go index da4bd9f..af0a1ed 100644 --- a/types/serialize.go +++ b/types/serialize.go @@ -6,6 +6,22 @@ import ( "github.com/google/certificate-transparency-go/tls" ) +const ( + HashSizeV1 = 32 +) + +// GetProofByHashV1 is a serializable get-proof-by-hash request +type GetProofByHashV1 struct { + Hash [HashSizeV1]byte + TreeSize uint64 +} + +// GetConsistencyProofV1 is a serializable get-consistency-proof request +type GetConsistencyProofV1 struct { + First uint64 + Second uint64 +} + // Marshal marshals a TLS-encodable structure func Marshal(item interface{}) ([]byte, error) { serialized, err := tls.Marshal(item) diff --git a/types/serialize_test.go b/types/serialize_test.go index e835ad2..ed51c2c 100644 --- a/types/serialize_test.go +++ b/types/serialize_test.go @@ -33,6 +33,7 @@ func TestMarshalUnmarshal(t *testing.T) { tests = append(tests, test_cases_sigv1(t)...) tests = append(tests, test_cases_namespace(t)...) tests = append(tests, test_cases_ed25519v1(t)...) + tests = append(tests, test_cases_requests(t)...) for _, table := range tests { b, err := Marshal(table.item) if got, want := err != nil, table.wantErr; got != want { @@ -85,6 +86,12 @@ func TestMarshalUnmarshal(t *testing.T) { case Ed25519V1: var item Ed25519V1 err = Unmarshal(b, &item) + case GetProofByHashV1: + var item GetProofByHashV1 + err = Unmarshal(b, &item) + case GetConsistencyProofV1: + var item GetConsistencyProofV1 + err = Unmarshal(b, &item) default: t.Errorf("unhandled type in test %q", table.description) } @@ -481,6 +488,34 @@ func test_cases_ed25519v1(t *testing.T) []testCaseSerialize { } } +// test_cases_requests returns test cases for proof request types +func test_cases_requests(t *testing.T) []testCaseSerialize { + return []testCaseSerialize{ + { + description: "valid: GetProofByHashV1", + item: GetProofByHashV1{ + Hash: [HashSizeV1]byte{}, + TreeSize: 16909060, + }, + wantBytes: bytes.Join([][]byte{ + make([]byte, 32), // hash + []byte{0x00, 0x00, 0x00, 0x00, 0x1, 0x2, 0x3, 0x4}, // tree size + }, nil), + }, + { + description: "valid: GetConsistencyProofV1", + item: GetConsistencyProofV1{ + First: 0, + Second: 16909060, + }, + wantBytes: bytes.Join([][]byte{ + make([]byte, 8), // first + []byte{0x00, 0x00, 0x00, 0x00, 0x1, 0x2, 0x3, 0x4}, // second + }, nil), + }, + } +} + var ( // StItemList testStItemList = StItemList{ -- cgit v1.2.3