-
Notifications
You must be signed in to change notification settings - Fork 0
/
encode_test.go
71 lines (54 loc) · 1.43 KB
/
encode_test.go
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package qrsecrets_test
import (
"bytes"
"testing"
"github.com/go-compile/qrsecrets"
"github.com/go-compile/rome/p256"
)
func TestNewContainer(t *testing.T) {
secret := "Hello this is my secret"
hash := qrsecrets.HashSHA256
private, err := p256.Generate()
if err != nil {
t.Fatal(err)
}
c, err := qrsecrets.NewContainer(private.Public().Name(), hash, []byte(secret), 64-int32(len(secret)))
if err != nil {
t.Fatal(err)
}
if c.HashID != hash {
t.Fatal("new container hash does not match input option")
}
if c.Curve != qrsecrets.CurveP256 {
t.Fatal("new container curve does not match input option")
}
if len(c.MetaData.Salt) != 32 {
t.Fatal("salt is not 32 bytes long")
}
if bytes.Equal(c.MetaData.Salt, make([]byte, 32)) {
t.Fatal("salt is a empty 32 byte slice")
}
if !bytes.Equal(c.CipherText.Plaintext, []byte(secret)) {
t.Fatal("plain text does not match input")
}
if len(c.CipherText.Padding) != 64-len(secret) {
t.Fatal("salt is not 32 bytes long")
}
}
func TestEncode(t *testing.T) {
secret := "Hello this is my secret"
hash := qrsecrets.HashSHA256
key := "Password123"
private, err := p256.Generate()
if err != nil {
t.Fatal(err)
}
c, err := qrsecrets.NewContainer(private.Public().Name(), hash, []byte(secret), 64-int32(len(secret)))
if err != nil {
t.Fatal(err)
}
buf := bytes.NewBuffer(nil)
if err := c.Encode(buf, private.Public(), []byte(key)); err != nil {
t.Fatal(err)
}
}