-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcryptokey_test.go
48 lines (38 loc) · 1.03 KB
/
cryptokey_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
package cryptokey
import (
"fmt"
"testing"
"github.com/cyphrme/coze"
)
// BenchmarkNSV (New, Sign, Verify) will generate a new CryptoKey, sign a
// message with that key, and verify the signature.
// go test -bench=.
func BenchmarkNSV(b *testing.B) {
var passCount = 0
msg := []byte("Test message.")
var algs = []coze.SigAlg{coze.ES224, coze.ES256, coze.ES384, coze.ES512, coze.Ed25519}
for j := 0; j < b.N; j++ {
for i := 0; i < len(algs); i++ {
cryptoKey, err := NewCryptoKey(coze.SEAlg(algs[i]))
if err != nil {
panic("Could not generate a new valid Crypto Key.")
}
sig, err := cryptoKey.SignMsg(msg)
if err != nil {
panic(err)
}
valid := cryptoKey.VerifyMsg(msg, sig)
if !valid {
panic("The signature was invalid")
}
// Test VerifyDigest
msgDigest := coze.Hash(coze.SigAlg(algs[i]).Hash(), msg)
valid = cryptoKey.Verify(msgDigest, sig)
if !valid {
panic("The signature was invalid")
}
passCount++
}
}
fmt.Printf("TestCryptoKeyNSV Pass Count: %+v \n", passCount)
}