aboutsummaryrefslogtreecommitdiff
path: root/pkg/types/ascii_test.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/ascii_test.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/ascii_test.go')
-rw-r--r--pkg/types/ascii_test.go438
1 files changed, 0 insertions, 438 deletions
diff --git a/pkg/types/ascii_test.go b/pkg/types/ascii_test.go
deleted file mode 100644
index fc3f486..0000000
--- a/pkg/types/ascii_test.go
+++ /dev/null
@@ -1,438 +0,0 @@
-package types
-
-import (
- "bytes"
- "fmt"
- "io"
- "reflect"
- "testing"
-)
-
-/*
- *
- * MessageASCII methods and helpers
- *
- */
-func TestNewMessageASCII(t *testing.T) {
- for _, table := range []struct {
- description string
- input io.Reader
- wantErr bool
- wantMap map[string][]string
- }{
- {
- description: "invalid: not enough lines",
- input: bytes.NewBufferString(""),
- wantErr: true,
- },
- {
- description: "invalid: lines must end with new line",
- input: bytes.NewBufferString("k1=v1\nk2=v2"),
- wantErr: true,
- },
- {
- description: "invalid: lines must not be empty",
- input: bytes.NewBufferString("k1=v1\n\nk2=v2\n"),
- wantErr: true,
- },
- {
- description: "invalid: wrong number of fields",
- input: bytes.NewBufferString("k1=v1\n"),
- wantErr: true,
- },
- {
- description: "valid",
- input: bytes.NewBufferString("k1=v1\nk2=v2\nk2=v3=4\n"),
- wantMap: map[string][]string{
- "k1": []string{"v1"},
- "k2": []string{"v2", "v3=4"},
- },
- },
- } {
- msg, err := NewMessageASCII(table.input, len(table.wantMap))
- if got, want := err != nil, table.wantErr; got != want {
- t.Errorf("got error %v but wanted %v in test %q: %v", got, want, table.description, err)
- }
- if err != nil {
- continue
- }
- if got, want := msg.m, table.wantMap; !reflect.DeepEqual(got, want) {
- t.Errorf("got\n\t%v\nbut wanted\n\t%v\nin test %q", got, want, table.description)
- }
- }
-}
-
-func TestNumField(t *testing.T) {}
-func TestGetStrings(t *testing.T) {}
-func TestGetString(t *testing.T) {}
-func TestGetUint64(t *testing.T) {}
-func TestGetHash(t *testing.T) {}
-func TestGetSignature(t *testing.T) {}
-func TestGetVerificationKey(t *testing.T) {}
-func TestDecodeHex(t *testing.T) {}
-
-/*
- *
- * MarshalASCII methods and helpers
- *
- */
-func TestLeafMarshalASCII(t *testing.T) {
- description := "valid: two leaves"
- leafList := []*Leaf{
- &Leaf{
- Message: Message{
- ShardHint: 123,
- Checksum: testBuffer32,
- },
- SigIdent: SigIdent{
- Signature: testBuffer64,
- KeyHash: testBuffer32,
- },
- },
- &Leaf{
- Message: Message{
- ShardHint: 456,
- Checksum: testBuffer32,
- },
- SigIdent: SigIdent{
- Signature: testBuffer64,
- KeyHash: testBuffer32,
- },
- },
- }
- wantBuf := bytes.NewBufferString(fmt.Sprintf(
- "%s%s%d%s"+"%s%s%x%s"+"%s%s%x%s"+"%s%s%x%s"+
- "%s%s%d%s"+"%s%s%x%s"+"%s%s%x%s"+"%s%s%x%s",
- // Leaf 1
- ShardHint, Delim, 123, EOL,
- Checksum, Delim, testBuffer32[:], EOL,
- Signature, Delim, testBuffer64[:], EOL,
- KeyHash, Delim, testBuffer32[:], EOL,
- // Leaf 2
- ShardHint, Delim, 456, EOL,
- Checksum, Delim, testBuffer32[:], EOL,
- Signature, Delim, testBuffer64[:], EOL,
- KeyHash, Delim, testBuffer32[:], EOL,
- ))
- buf := bytes.NewBuffer(nil)
- for _, leaf := range leafList {
- if err := leaf.MarshalASCII(buf); err != nil {
- t.Errorf("expected error %v but got %v in test %q: %v", false, true, description, err)
- return
- }
- }
- if got, want := buf.Bytes(), wantBuf.Bytes(); !bytes.Equal(got, want) {
- t.Errorf("got\n\t%v\nbut wanted\n\t%v\nin test %q", string(got), string(want), description)
- }
-}
-
-func TestSignedTreeHeadMarshalASCII(t *testing.T) {
- description := "valid"
- sth := &SignedTreeHead{
- TreeHead: TreeHead{
- Timestamp: 123,
- TreeSize: 456,
- RootHash: testBuffer32,
- },
- Signature: testBuffer64,
- }
- wantBuf := bytes.NewBufferString(fmt.Sprintf(
- "%s%s%d%s"+"%s%s%d%s"+"%s%s%x%s"+"%s%s%x%s",
- Timestamp, Delim, 123, EOL,
- TreeSize, Delim, 456, EOL,
- RootHash, Delim, testBuffer32[:], EOL,
- Signature, Delim, testBuffer64[:], EOL,
- ))
- buf := bytes.NewBuffer(nil)
- if err := sth.MarshalASCII(buf); err != nil {
- t.Errorf("expected error %v but got %v in test %q", false, true, description)
- return
- }
- if got, want := buf.Bytes(), wantBuf.Bytes(); !bytes.Equal(got, want) {
- t.Errorf("got\n\t%v\nbut wanted\n\t%v\nin test %q", string(got), string(want), description)
- }
-}
-
-func TestInclusionProofMarshalASCII(t *testing.T) {
- description := "valid"
- proof := InclusionProof{
- TreeSize: 321,
- LeafIndex: 123,
- Path: []*[HashSize]byte{
- testBuffer32,
- testBuffer32,
- },
- }
- wantBuf := bytes.NewBufferString(fmt.Sprintf(
- "%s%s%d%s"+"%s%s%x%s"+"%s%s%x%s",
- LeafIndex, Delim, 123, EOL,
- InclusionPath, Delim, testBuffer32[:], EOL,
- InclusionPath, Delim, testBuffer32[:], EOL,
- ))
- buf := bytes.NewBuffer(nil)
- if err := proof.MarshalASCII(buf); err != nil {
- t.Errorf("expected error %v but got %v in test %q", false, true, description)
- return
- }
- if got, want := buf.Bytes(), wantBuf.Bytes(); !bytes.Equal(got, want) {
- t.Errorf("got\n\t%v\nbut wanted\n\t%v\nin test %q", string(got), string(want), description)
- }
-}
-
-func TestConsistencyProofMarshalASCII(t *testing.T) {
- description := "valid"
- proof := ConsistencyProof{
- NewSize: 321,
- OldSize: 123,
- Path: []*[HashSize]byte{
- testBuffer32,
- testBuffer32,
- },
- }
- wantBuf := bytes.NewBufferString(fmt.Sprintf(
- "%s%s%x%s"+"%s%s%x%s",
- ConsistencyPath, Delim, testBuffer32[:], EOL,
- ConsistencyPath, Delim, testBuffer32[:], EOL,
- ))
- buf := bytes.NewBuffer(nil)
- if err := proof.MarshalASCII(buf); err != nil {
- t.Errorf("expected error %v but got %v in test %q", false, true, description)
- return
- }
- if got, want := buf.Bytes(), wantBuf.Bytes(); !bytes.Equal(got, want) {
- t.Errorf("got\n\t%v\nbut wanted\n\t%v\nin test %q", string(got), string(want), description)
- }
-}
-
-func TestWriteASCII(t *testing.T) {
-}
-
-/*
- *
- * UnmarshalASCII methods and helpers
- *
- */
-func TestLeafListUnmarshalASCII(t *testing.T) {}
-
-func TestSignedTreeHeadUnmarshalASCII(t *testing.T) {
- for _, table := range []struct {
- description string
- buf io.Reader
- wantErr bool
- wantSth *SignedTreeHead
- }{
- {
- description: "valid",
- buf: bytes.NewBufferString(fmt.Sprintf(
- "%s%s%d%s"+"%s%s%d%s"+"%s%s%x%s"+"%s%s%x%s",
- Timestamp, Delim, 123, EOL,
- TreeSize, Delim, 456, EOL,
- RootHash, Delim, testBuffer32[:], EOL,
- Signature, Delim, testBuffer64[:], EOL,
- )),
- wantSth: &SignedTreeHead{
- TreeHead: TreeHead{
- Timestamp: 123,
- TreeSize: 456,
- RootHash: testBuffer32,
- },
- Signature: testBuffer64,
- },
- },
- } {
- var sth SignedTreeHead
- err := sth.UnmarshalASCII(table.buf)
- if got, want := err != nil, table.wantErr; got != want {
- t.Errorf("got error %v but wanted %v in test %q: %v", got, want, table.description, err)
- }
- if err != nil {
- continue
- }
- if got, want := &sth, table.wantSth; !reflect.DeepEqual(got, want) {
- t.Errorf("got\n\t%v\nbut wanted\n\t%v\nin test %q", got, want, table.description)
- }
- }
-}
-
-func TestInclusionProofUnmarshalASCII(t *testing.T) {}
-func TestConsistencyProofUnmarshalASCII(t *testing.T) {}
-
-func TestInclusionProofRequestUnmarshalASCII(t *testing.T) {
- for _, table := range []struct {
- description string
- buf io.Reader
- wantErr bool
- wantReq *InclusionProofRequest
- }{
- {
- description: "valid",
- buf: bytes.NewBufferString(fmt.Sprintf(
- "%s%s%x%s"+"%s%s%d%s",
- LeafHash, Delim, testBuffer32[:], EOL,
- TreeSize, Delim, 123, EOL,
- )),
- wantReq: &InclusionProofRequest{
- LeafHash: testBuffer32,
- TreeSize: 123,
- },
- },
- } {
- var req InclusionProofRequest
- err := req.UnmarshalASCII(table.buf)
- if got, want := err != nil, table.wantErr; got != want {
- t.Errorf("got error %v but wanted %v in test %q: %v", got, want, table.description, err)
- }
- if err != nil {
- continue
- }
- if got, want := &req, table.wantReq; !reflect.DeepEqual(got, want) {
- t.Errorf("got\n\t%v\nbut wanted\n\t%v\nin test %q", got, want, table.description)
- }
- }
-}
-
-func TestConsistencyProofRequestUnmarshalASCII(t *testing.T) {
- for _, table := range []struct {
- description string
- buf io.Reader
- wantErr bool
- wantReq *ConsistencyProofRequest
- }{
- {
- description: "valid",
- buf: bytes.NewBufferString(fmt.Sprintf(
- "%s%s%d%s"+"%s%s%d%s",
- NewSize, Delim, 321, EOL,
- OldSize, Delim, 123, EOL,
- )),
- wantReq: &ConsistencyProofRequest{
- NewSize: 321,
- OldSize: 123,
- },
- },
- } {
- var req ConsistencyProofRequest
- err := req.UnmarshalASCII(table.buf)
- if got, want := err != nil, table.wantErr; got != want {
- t.Errorf("got error %v but wanted %v in test %q: %v", got, want, table.description, err)
- }
- if err != nil {
- continue
- }
- if got, want := &req, table.wantReq; !reflect.DeepEqual(got, want) {
- t.Errorf("got\n\t%v\nbut wanted\n\t%v\nin test %q", got, want, table.description)
- }
- }
-}
-
-func TestLeavesRequestUnmarshalASCII(t *testing.T) {
- for _, table := range []struct {
- description string
- buf io.Reader
- wantErr bool
- wantReq *LeavesRequest
- }{
- {
- description: "valid",
- buf: bytes.NewBufferString(fmt.Sprintf(
- "%s%s%d%s"+"%s%s%d%s",
- StartSize, Delim, 123, EOL,
- EndSize, Delim, 456, EOL,
- )),
- wantReq: &LeavesRequest{
- StartSize: 123,
- EndSize: 456,
- },
- },
- } {
- var req LeavesRequest
- err := req.UnmarshalASCII(table.buf)
- if got, want := err != nil, table.wantErr; got != want {
- t.Errorf("got error %v but wanted %v in test %q: %v", got, want, table.description, err)
- }
- if err != nil {
- continue
- }
- if got, want := &req, table.wantReq; !reflect.DeepEqual(got, want) {
- t.Errorf("got\n\t%v\nbut wanted\n\t%v\nin test %q", got, want, table.description)
- }
- }
-}
-
-func TestLeafRequestUnmarshalASCII(t *testing.T) {
- for _, table := range []struct {
- description string
- buf io.Reader
- wantErr bool
- wantReq *LeafRequest
- }{
- {
- description: "valid",
- buf: bytes.NewBufferString(fmt.Sprintf(
- "%s%s%d%s"+"%s%s%x%s"+"%s%s%x%s"+"%s%s%x%s"+"%s%s%s%s",
- ShardHint, Delim, 123, EOL,
- Checksum, Delim, testBuffer32[:], EOL,
- Signature, Delim, testBuffer64[:], EOL,
- VerificationKey, Delim, testBuffer32[:], EOL,
- DomainHint, Delim, "example.com", EOL,
- )),
- wantReq: &LeafRequest{
- Message: Message{
- ShardHint: 123,
- Checksum: testBuffer32,
- },
- Signature: testBuffer64,
- VerificationKey: testBuffer32,
- DomainHint: "example.com",
- },
- },
- } {
- var req LeafRequest
- err := req.UnmarshalASCII(table.buf)
- if got, want := err != nil, table.wantErr; got != want {
- t.Errorf("got error %v but wanted %v in test %q: %v", got, want, table.description, err)
- }
- if err != nil {
- continue
- }
- if got, want := &req, table.wantReq; !reflect.DeepEqual(got, want) {
- t.Errorf("got\n\t%v\nbut wanted\n\t%v\nin test %q", got, want, table.description)
- }
- }
-}
-
-func TestCosignatureRequestUnmarshalASCII(t *testing.T) {
- for _, table := range []struct {
- description string
- buf io.Reader
- wantErr bool
- wantReq *CosignatureRequest
- }{
- {
- description: "valid",
- buf: bytes.NewBufferString(fmt.Sprintf(
- "%s%s%x%s"+"%s%s%x%s",
- Cosignature, Delim, testBuffer64[:], EOL,
- KeyHash, Delim, testBuffer32[:], EOL,
- )),
- wantReq: &CosignatureRequest{
- SigIdent: SigIdent{
- Signature: testBuffer64,
- KeyHash: testBuffer32,
- },
- },
- },
- } {
- var req CosignatureRequest
- err := req.UnmarshalASCII(table.buf)
- if got, want := err != nil, table.wantErr; got != want {
- t.Errorf("got error %v but wanted %v in test %q: %v", got, want, table.description, err)
- }
- if err != nil {
- continue
- }
- if got, want := &req, table.wantReq; !reflect.DeepEqual(got, want) {
- t.Errorf("got\n\t%v\nbut wanted\n\t%v\nin test %q", got, want, table.description)
- }
- }
-}