-
Notifications
You must be signed in to change notification settings - Fork 15
/
apis_test.go
73 lines (65 loc) · 1.75 KB
/
apis_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
72
73
package libdisco
import (
"os"
"testing"
)
func TestCreationKeys(t *testing.T) {
// temporary files
discoKeyPairFile := "./discoKeyPairFile"
defer func() {
if err := os.Remove(discoKeyPairFile); err != nil {
panic(err)
}
}()
rootPrivateKeyFile := "./rootPrivateKeyFile"
defer os.Remove(rootPrivateKeyFile)
rootPublicKeyFile := "./rootPublicKeyFile"
defer os.Remove(rootPublicKeyFile)
// Generate Disco Key pair
keyPair, err := GenerateAndSaveDiscoKeyPair(discoKeyPairFile, "")
if err != nil {
t.Error("Disco key pair couldn't be written on disk")
return
}
// Load Disco Key pair
keyPairTemp, err := LoadDiscoKeyPair(discoKeyPairFile, "")
if err != nil {
t.Error("Disco key pair couldn't be loaded from disk")
return
}
// compare
for i := 0; i < 32; i++ {
if keyPair.PublicKey[i] != keyPairTemp.PublicKey[i] ||
keyPair.PrivateKey[i] != keyPairTemp.PrivateKey[i] {
t.Error("Disco key pair generated and loaded are different")
return
}
}
// generate root key
err = GenerateAndSaveDiscoRootKeyPair(rootPrivateKeyFile, rootPublicKeyFile)
if err != nil {
t.Error("Disco key pair couldn't be written on disk")
return
}
// load private root key
rootPriv, err := LoadDiscoRootPrivateKey(rootPrivateKeyFile)
if err != nil {
t.Error("Disco root private key couldn't be loaded from disk")
return
}
// load public root key
rootPub, err := LoadDiscoRootPublicKey(rootPublicKeyFile)
if err != nil {
t.Error("Disco root public key couldn't be loaded from disk")
return
}
// create a proof
proof := CreateStaticPublicKeyProof(rootPriv, keyPair.PublicKey[:])
// verify the proof
verifior := CreatePublicKeyVerifier(rootPub)
if !verifior(keyPair.PublicKey[:], proof) {
t.Error("cannot verify proof")
return
}
// end
}