-
Notifications
You must be signed in to change notification settings - Fork 25
/
tlock_age_test.go
51 lines (41 loc) · 1.01 KB
/
tlock_age_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
package tlock
import (
"bytes"
"crypto/rand"
"testing"
"time"
"github.com/drand/tlock/networks/http"
)
const (
testnetHost = "http://pl-us.testnet.drand.sh/"
testnetChainHash = "7672797f548f3f4748ac4bf3352fc6c6b6468c9ad40ad456a397545c6e2df5bf"
)
func Test_WrapUnwrap(t *testing.T) {
network, err := http.NewNetwork(testnetHost, testnetChainHash)
if err != nil {
t.Fatalf("network error %s", err)
}
recipient := Recipient{
roundNumber: network.RoundNumber(time.Now()),
network: network,
}
// 16 is the constant fileKeySize
fileKey := make([]byte, 16)
if _, err := rand.Read(fileKey); err != nil {
t.Fatalf("rand read filekey: %s", err)
}
stanza, err := recipient.Wrap(fileKey)
if err != nil {
t.Fatalf("wrap error %s", err)
}
identity := Identity{
network: network,
}
b, err := identity.Unwrap(stanza)
if err != nil {
t.Fatalf("unwrap error %s", err)
}
if !bytes.Equal(b, fileKey) {
t.Fatalf("decrypted filekey is invalid; expected %d; got %d", len(b), len(fileKey))
}
}