forked from jasonmccampbell/GoSodium
-
Notifications
You must be signed in to change notification settings - Fork 2
/
gosodium_test.go
29 lines (23 loc) · 878 Bytes
/
gosodium_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
package gosodium
import "testing"
import "bytes"
import "github.com/neuegram/GoSodium/sodium"
// TestKeyGeneration verifies only that the public/secret keys are not the same (ie, not all zeros)
// and that they can be successfully passed to the lower-level functions. No other checks are made.
func TestKeyGeneration(t *testing.T) {
allocSize := 15 + sodium.BoxZeroBytes()
msg := make([]byte, allocSize)
ct := make([]byte, allocSize)
pk1, sk1 := NewKeyPair()
nonce := NewBoxNonce()
if bytes.equal(pk1, sk1) {
t.Fatail("Somehow pk1 and sk1 are the same?!")
}
sodium.MemZero(msg[:sodium.BoxZeroBytes()])
// This just verifies that we can pass the generated keys to the lower level functions directly.
r1 := sodium.Box(ct, msg, nonce, pk1, sk1)
if r1 != 0 {
t.Fatal("Crypto box encrypt failed, got ", r1, " expected 0")
}
t.Log("TestKeyGeneration passed")
}