-
Notifications
You must be signed in to change notification settings - Fork 5
/
certs_test.go
94 lines (80 loc) · 3.62 KB
/
certs_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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
package libICP
import (
"testing"
"github.com/stretchr/testify/assert"
)
func Test_TBSCertificate_SetAppropriateVersion_1(t *testing.T) {
cert := tbs_certificate{}
cert.SetAppropriateVersion()
assert.Equal(t, 0, cert.Version, "The default version MUST be 0 (see RFC3280 Section 4.1 Page 14)")
}
func Test_TBSCertificate_SetAppropriateVersion_2(t *testing.T) {
cert := tbs_certificate{}
cert.IssuerUniqueID.BitLength = 1
cert.SetAppropriateVersion()
assert.Equal(t, 1, cert.Version, "Version MUST be 1 when issuerUniqueID is present (see RFC3280 Section 4.1 Page 14)")
}
func Test_TBSCertificate_SetAppropriateVersion_3(t *testing.T) {
cert := tbs_certificate{}
cert.SubjectUniqueID.BitLength = 1
cert.SetAppropriateVersion()
assert.Equal(t, 1, cert.Version, "Version MUST be 1 when subjectUniqueID is present (see RFC3280 Section 4.1 Page 14)")
}
func Test_TBSCertificate_SetAppropriateVersion_4(t *testing.T) {
cert := tbs_certificate{}
cert.Extensions = make([]extension, 1)
cert.SetAppropriateVersion()
assert.Equal(t, 2, cert.Version, "Version MUST be 2 when extensions is present (see RFC3280 Section 4.1 Page 14)")
}
func Test_TBSCertificate_SetAppropriateVersion_5(t *testing.T) {
cert := tbs_certificate{}
cert.SubjectUniqueID.BitLength = 1
cert.Extensions = make([]extension, 1)
cert.SetAppropriateVersion()
assert.Equal(t, 2, cert.Version, "Version MUST be 2 when extensions is present (see RFC3280 Section 4.1 Page 14)")
}
func Test_TBSCertificate_SetAppropriateVersion_6(t *testing.T) {
cert := tbs_certificate{}
cert.IssuerUniqueID.BitLength = 1
cert.Extensions = make([]extension, 1)
cert.SetAppropriateVersion()
assert.Equal(t, 2, cert.Version, "Version MUST be 2 when extensions is present (see RFC3280 Section 4.1 Page 14)")
}
func Test_TBSCertificate_SetAppropriateVersion_7(t *testing.T) {
cert := tbs_certificate{}
cert.SubjectUniqueID.BitLength = 1
cert.IssuerUniqueID.BitLength = 1
cert.Extensions = make([]extension, 1)
cert.SetAppropriateVersion()
assert.Equal(t, 2, cert.Version, "Version MUST be 2 when extensions is present (see RFC3280 Section 4.1 Page 14)")
}
func Test_TBSCertList_SetAppropriateVersion_1(t *testing.T) {
lcerts := tbs_cert_list{}
lcerts.SetAppropriateVersion()
assert.Equal(t, 0, lcerts.Version, "The default version MUST be 0 in order to be omited when enconding (see RFC3280 Section 5.1 Page 49)")
}
func Test_TBSCertList_SetAppropriateVersion_2(t *testing.T) {
lcerts := tbs_cert_list{}
lcerts.RevokedCertificates = make([]revoked_certificate, 1)
lcerts.SetAppropriateVersion()
assert.Equal(t, 0, lcerts.Version, "The default version MUST be 0 in order to be omited when enconding (see RFC3280 Section 5.1 Page 49)")
}
func Test_TBSCertList_SetAppropriateVersion_3(t *testing.T) {
lcerts := tbs_cert_list{}
lcerts.CRLExtensions = make([]extension, 1)
lcerts.SetAppropriateVersion()
assert.Equal(t, 1, lcerts.Version, "The version MUST be 1 when crlExtensions is present (see RFC3280 Section 5.1 Page 49)")
}
func Test_TBSCertList_SetAppropriateVersion_4(t *testing.T) {
lcerts := tbs_cert_list{}
lcerts.RevokedCertificates = make([]revoked_certificate, 1)
lcerts.RevokedCertificates[0].CRLEntryExtensions = make([]extension, 1)
lcerts.SetAppropriateVersion()
assert.Equal(t, 1, lcerts.Version, "The version MUST be 1 when revokedCertificates.crlEntryExtensions is present (see RFC3280 Section 5.1 Page 49)")
}
func Test_Certificate_Signable(t *testing.T) {
cert := certificate_pack{}
assert.Equal(t, []byte(cert.TBSCertificate.RawContent), cert.GetRawContent())
assert.Equal(t, cert.SignatureAlgorithm, cert.GetSignatureAlgorithm())
assert.Equal(t, cert.Signature.Bytes, cert.GetSignature())
}