-
Notifications
You must be signed in to change notification settings - Fork 0
/
keyusage_test.go
55 lines (50 loc) · 1.5 KB
/
keyusage_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
package pcert
import (
"crypto/x509"
"testing"
)
func TestKeyUsageToString(t *testing.T) {
tests := []struct {
keyUsage x509.KeyUsage
expected string
}{
{x509.KeyUsageKeyEncipherment | x509.KeyUsageCertSign | x509.KeyUsageDecipherOnly, "CertSign,DecipherOnly,KeyEncipherment"},
{x509.KeyUsageDigitalSignature | x509.KeyUsageDataEncipherment, "DataEncipherment,DigitalSignature"},
{x509.KeyUsage(0), ""},
}
for _, test := range tests {
got := KeyUsageToString(test.keyUsage)
want := test.expected
if got != want {
t.Errorf("got=%s want=%s", got, want)
}
}
}
func TestExtKeyUsageToString(t *testing.T) {
tests := []struct {
keyUsage []x509.ExtKeyUsage
expected string
}{
{[]x509.ExtKeyUsage{
x509.ExtKeyUsageMicrosoftServerGatedCrypto,
x509.ExtKeyUsageMicrosoftCommercialCodeSigning,
}, "MicrosoftCommercialCodeSigning,MicrosoftServerGatedCrypto"},
{[]x509.ExtKeyUsage{
x509.ExtKeyUsageMicrosoftCommercialCodeSigning,
x509.ExtKeyUsageMicrosoftServerGatedCrypto,
}, "MicrosoftCommercialCodeSigning,MicrosoftServerGatedCrypto"},
{[]x509.ExtKeyUsage{
x509.ExtKeyUsageMicrosoftCommercialCodeSigning,
x509.ExtKeyUsageMicrosoftServerGatedCrypto,
x509.ExtKeyUsageMicrosoftCommercialCodeSigning,
x509.ExtKeyUsageMicrosoftServerGatedCrypto,
}, "MicrosoftCommercialCodeSigning,MicrosoftServerGatedCrypto"},
}
for _, test := range tests {
got := ExtKeyUsageToString(test.keyUsage)
want := test.expected
if got != want {
t.Errorf("got=%s want=%s", got, want)
}
}
}