aboutsummaryrefslogtreecommitdiff
path: root/pkg/types/crypto_test.go
blob: 491823ab84e9378f4f040145db20c2926c6283fc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package types

import (
	"crypto"
	"crypto/ed25519"
	"crypto/rand"
	"testing"

	"git.sigsum.org/sigsum-go/pkg/merkle"
)

func newKeyPair(t *testing.T) (crypto.Signer, PublicKey) {
	vk, sk, err := ed25519.GenerateKey(rand.Reader)
	if err != nil {
		t.Fatal(err)
	}

	var pub PublicKey
	copy(pub[:], vk[:])
	return sk, pub
}

func newHashBufferInc(t *testing.T) *merkle.Hash {
	t.Helper()

	var buf merkle.Hash
	for i := 0; i < len(buf); i++ {
		buf[i] = byte(i)
	}
	return &buf
}

func newSigBufferInc(t *testing.T) *Signature {
	t.Helper()

	var buf Signature
	for i := 0; i < len(buf); i++ {
		buf[i] = byte(i)
	}
	return &buf
}

func newPubBufferInc(t *testing.T) *PublicKey {
	t.Helper()

	var buf PublicKey
	for i := 0; i < len(buf); i++ {
		buf[i] = byte(i)
	}
	return &buf
}