Debian Codegraph @

internal/cryptobyte/asn1_test.go

raw symbols SCIP
1 // Copyright 2017 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
4
5 package cryptobytescip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/
6
7 import (
8 "bytesscip-go gomod github.com/golang/go/src go1.14 bytes/"
9 encoding_asn1scip-go gomod github.com/golang/go/src go1.14 `encoding/asn1`/ "encoding/asn1scip-go gomod github.com/golang/go/src go1.14 `encoding/asn1`/"
10 "math/bigscip-go gomod github.com/golang/go/src go1.14 `math/big`/"
11 "reflectscip-go gomod github.com/golang/go/src go1.14 reflect/"
12 "testingscip-go gomod github.com/golang/go/src go1.14 testing/"
13 "timescip-go gomod github.com/golang/go/src go1.14 time/"
14
15 "github.com/smallstep/pkcs7/internal/cryptobyte/asn1scip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte/asn1`/"
16 )
17
18 type readASN1Testscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/readASN1Test# struct {
19 namescip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/readASN1Test#name. string
20 inscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/readASN1Test#in. []byte
21 tagscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/readASN1Test#tag. asn1scip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte/asn1`/.Tagscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte/asn1`/Tag#
22 okscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/readASN1Test#ok. bool
23 outscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/readASN1Test#out. interface{}
24 }
25
26 var readASN1TestDatascip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/readASN1TestData. = []readASN1Testscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/readASN1Test#{
27 {"valid", []byte{0x30, 2, 1, 2}, 0x30, true, []byte{1, 2}},
28 {"truncated", []byte{0x30, 3, 1, 2}, 0x30, false, nil},
29 {"zero length of length", []byte{0x30, 0x80}, 0x30, false, nil},
30 {"invalid long form length", []byte{0x30, 0x81, 1, 1}, 0x30, false, nil},
31 {"non-minimal length", append([]byte{0x30, 0x82, 0, 0x80}, make([]byte, 0x80)...), 0x30, false, nil},
32 {"invalid tag", []byte{0xa1, 3, 0x4, 1, 1}, 31, false, nil},
33 {"high tag", []byte{0x1f, 0x81, 0x80, 0x01, 2, 1, 2}, 0xff /* actually 0x4001, but tag is uint8 */, false, nil},
34 {"2**31 - 1 length", []byte{0x30, 0x84, 0x7f, 0xff, 0xff, 0xff}, 0x30, false, nil},
35 {"2**32 - 1 length", []byte{0x30, 0x84, 0xff, 0xff, 0xff, 0xff}, 0x30, false, nil},
36 {"2**63 - 1 length", []byte{0x30, 0x88, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}, 0x30, false, nil},
37 {"2**64 - 1 length", []byte{0x30, 0x88, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}, 0x30, false, nil},
38 }
39
40 func TestReadASN1scip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/TestReadASN1().(t *testingscip-go gomod github.com/golang/go/src go1.14 testing/.Tscip-go gomod github.com/golang/go/src go1.14 testing/T#) {
41 for _, test := range readASN1TestDatascip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/readASN1TestData. {
42 t.Runscip-go gomod github.com/golang/go/src go1.14 testing/T#Run().(test.namescip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/readASN1Test#name., func(t *testingscip-go gomod github.com/golang/go/src go1.14 testing/.Tscip-go gomod github.com/golang/go/src go1.14 testing/T#) {
43 var in, out Stringscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/String# = test.inscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/readASN1Test#in., nil
44 ok := in.ReadASN1scip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/String#ReadASN1().(&out, test.tagscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/readASN1Test#tag.)
45 if ok != test.okscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/readASN1Test#ok. || ok && !bytesscip-go gomod github.com/golang/go/src go1.14 bytes/.Equalscip-go gomod github.com/golang/go/src go1.14 bytes/Equal().(out, test.outscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/readASN1Test#out..([]byte)) {
46 t.Errorfscip-go gomod github.com/golang/go/src go1.14 testing/common#Errorf().("in.ReadASN1() = %v, want %v; out = %v, want %v", ok, test.okscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/readASN1Test#ok., out, test.outscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/readASN1Test#out.)
47 }
48 })
49 }
50 }
51
52 func TestReadASN1Optionalscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/TestReadASN1Optional().(t *testingscip-go gomod github.com/golang/go/src go1.14 testing/.Tscip-go gomod github.com/golang/go/src go1.14 testing/T#) {
53 var empty Stringscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/String#
54 var present bool
55 ok := empty.ReadOptionalASN1scip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/String#ReadOptionalASN1().(nil, &present, 0xa0)
56 if !ok || present {
57 t.Errorfscip-go gomod github.com/golang/go/src go1.14 testing/common#Errorf().("empty.ReadOptionalASN1() = %v, want true; present = %v want false", ok, present)
58 }
59
60 var in, out Stringscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/String# = []byte{0xa1, 3, 0x4, 1, 1}, nil
61 ok = in.ReadOptionalASN1scip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/String#ReadOptionalASN1().(&out, &present, 0xa0)
62 if !ok || present {
63 t.Errorfscip-go gomod github.com/golang/go/src go1.14 testing/common#Errorf().("in.ReadOptionalASN1() = %v, want true, present = %v, want false", ok, present)
64 }
65 ok = in.ReadOptionalASN1scip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/String#ReadOptionalASN1().(&out, &present, 0xa1)
66 wantBytes := []byte{4, 1, 1}
67 if !ok || !present || !bytesscip-go gomod github.com/golang/go/src go1.14 bytes/.Equalscip-go gomod github.com/golang/go/src go1.14 bytes/Equal().(out, wantBytes) {
68 t.Errorfscip-go gomod github.com/golang/go/src go1.14 testing/common#Errorf().("in.ReadOptionalASN1() = %v, want true; present = %v, want true; out = %v, want = %v", ok, present, out, wantBytes)
69 }
70 }
71
72 var optionalOctetStringTestDatascip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/optionalOctetStringTestData. = []struct {
73 readASN1Testscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/optionalOctetStringTestData:readASN1Test.
74 presentscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/optionalOctetStringTestData:present. bool
75 }{
76 {readASN1Testscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/readASN1Test#{"empty", []byte{}, 0xa0, true, []byte{}}, false},
77 {readASN1Testscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/readASN1Test#{"invalid", []byte{0xa1, 3, 0x4, 2, 1}, 0xa1, false, []byte{}}, true},
78 {readASN1Testscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/readASN1Test#{"missing", []byte{0xa1, 3, 0x4, 1, 1}, 0xa0, true, []byte{}}, false},
79 {readASN1Testscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/readASN1Test#{"present", []byte{0xa1, 3, 0x4, 1, 1}, 0xa1, true, []byte{1}}, true},
80 }
81
82 func TestReadASN1OptionalOctetStringscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/TestReadASN1OptionalOctetString().(t *testingscip-go gomod github.com/golang/go/src go1.14 testing/.Tscip-go gomod github.com/golang/go/src go1.14 testing/T#) {
83 for _, test := range optionalOctetStringTestDatascip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/optionalOctetStringTestData. {
84 t.Runscip-go gomod github.com/golang/go/src go1.14 testing/T#Run().(test.namescip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/readASN1Test#name., func(t *testingscip-go gomod github.com/golang/go/src go1.14 testing/.Tscip-go gomod github.com/golang/go/src go1.14 testing/T#) {
85 in := Stringscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/String#(test.inscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/readASN1Test#in.)
86 var out []byte
87 var present bool
88 ok := in.ReadOptionalASN1OctetStringscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/String#ReadOptionalASN1OctetString().(&out, &present, test.tagscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/readASN1Test#tag.)
89 if ok != test.okscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/readASN1Test#ok. || present != test.presentscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/optionalOctetStringTestData:present. || !bytesscip-go gomod github.com/golang/go/src go1.14 bytes/.Equalscip-go gomod github.com/golang/go/src go1.14 bytes/Equal().(out, test.outscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/readASN1Test#out..([]byte)) {
90 t.Errorfscip-go gomod github.com/golang/go/src go1.14 testing/common#Errorf().("in.ReadOptionalASN1OctetString() = %v, want %v; present = %v want %v; out = %v, want %v", ok, test.okscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/readASN1Test#ok., present, test.presentscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/optionalOctetStringTestData:present., out, test.outscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/readASN1Test#out.)
91 }
92 })
93 }
94 }
95
96 const defaultIntscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/defaultInt. = -1
97
98 var optionalIntTestDatascip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/optionalIntTestData. = []readASN1Testscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/readASN1Test#{
99 {"empty", []byte{}, 0xa0, true, defaultIntscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/defaultInt.},
100 {"invalid", []byte{0xa1, 3, 0x2, 2, 127}, 0xa1, false, 0},
101 {"missing", []byte{0xa1, 3, 0x2, 1, 127}, 0xa0, true, defaultIntscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/defaultInt.},
102 {"present", []byte{0xa1, 3, 0x2, 1, 42}, 0xa1, true, 42},
103 }
104
105 func TestReadASN1OptionalIntegerscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/TestReadASN1OptionalInteger().(t *testingscip-go gomod github.com/golang/go/src go1.14 testing/.Tscip-go gomod github.com/golang/go/src go1.14 testing/T#) {
106 for _, test := range optionalIntTestDatascip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/optionalIntTestData. {
107 t.Runscip-go gomod github.com/golang/go/src go1.14 testing/T#Run().(test.namescip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/readASN1Test#name., func(t *testingscip-go gomod github.com/golang/go/src go1.14 testing/.Tscip-go gomod github.com/golang/go/src go1.14 testing/T#) {
108 in := Stringscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/String#(test.inscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/readASN1Test#in.)
109 var out int
110 ok := in.ReadOptionalASN1Integerscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/String#ReadOptionalASN1Integer().(&out, test.tagscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/readASN1Test#tag., defaultIntscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/defaultInt.)
111 if ok != test.okscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/readASN1Test#ok. || ok && out != test.outscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/readASN1Test#out..(int) {
112 t.Errorfscip-go gomod github.com/golang/go/src go1.14 testing/common#Errorf().("in.ReadOptionalASN1Integer() = %v, want %v; out = %v, want %v", ok, test.okscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/readASN1Test#ok., out, test.outscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/readASN1Test#out.)
113 }
114 })
115 }
116 }
117
118 const defaultBoolscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/defaultBool. = false
119
120 var optionalBoolTestDatascip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/optionalBoolTestData. = []readASN1Testscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/readASN1Test#{
121 {"empty", []byte{}, 0xa0, true, false},
122 {"invalid", []byte{0xa1, 0x3, 0x1, 0x2, 0x7f}, 0xa1, false, defaultBoolscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/defaultBool.},
123 {"missing", []byte{0xa1, 0x3, 0x1, 0x1, 0x7f}, 0xa0, true, defaultBoolscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/defaultBool.},
124 {"present", []byte{0xa1, 0x3, 0x1, 0x1, 0xff}, 0xa1, true, true},
125 }
126
127 func TestReadASN1OptionalBooleanscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/TestReadASN1OptionalBoolean().(t *testingscip-go gomod github.com/golang/go/src go1.14 testing/.Tscip-go gomod github.com/golang/go/src go1.14 testing/T#) {
128 for _, test := range optionalBoolTestDatascip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/optionalBoolTestData. {
129 t.Runscip-go gomod github.com/golang/go/src go1.14 testing/T#Run().(test.namescip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/readASN1Test#name., func(t *testingscip-go gomod github.com/golang/go/src go1.14 testing/.Tscip-go gomod github.com/golang/go/src go1.14 testing/T#) {
130 in := Stringscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/String#(test.inscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/readASN1Test#in.)
131 var out bool
132 ok := in.ReadOptionalASN1Booleanscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/String#ReadOptionalASN1Boolean().(&out, test.tagscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/readASN1Test#tag., defaultBoolscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/defaultBool.)
133 if ok != test.okscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/readASN1Test#ok. || ok && out != test.outscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/readASN1Test#out..(bool) {
134 t.Errorfscip-go gomod github.com/golang/go/src go1.14 testing/common#Errorf().("in.ReadOptionalASN1Boolean() = %v, want %v; out = %v, want %v", ok, test.okscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/readASN1Test#ok., out, test.outscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/readASN1Test#out.)
135 }
136 })
137 }
138 }
139
140 func TestReadASN1IntegerSignedscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/TestReadASN1IntegerSigned().(t *testingscip-go gomod github.com/golang/go/src go1.14 testing/.Tscip-go gomod github.com/golang/go/src go1.14 testing/T#) {
141 testData64 := []struct {
142 in []byte
143 out int64
144 }{
145 {[]byte{2, 3, 128, 0, 0}, -0x800000},
146 {[]byte{2, 2, 255, 0}, -256},
147 {[]byte{2, 2, 255, 127}, -129},
148 {[]byte{2, 1, 128}, -128},
149 {[]byte{2, 1, 255}, -1},
150 {[]byte{2, 1, 0}, 0},
151 {[]byte{2, 1, 1}, 1},
152 {[]byte{2, 1, 2}, 2},
153 {[]byte{2, 1, 127}, 127},
154 {[]byte{2, 2, 0, 128}, 128},
155 {[]byte{2, 2, 1, 0}, 256},
156 {[]byte{2, 4, 0, 128, 0, 0}, 0x800000},
157 }
158 for i, test := range testData64 {
159 in := Stringscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/String#(test.in)
160 var out int64
161 ok := in.ReadASN1Integerscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/String#ReadASN1Integer().(&out)
162 if !ok || out != test.out {
163 t.Errorfscip-go gomod github.com/golang/go/src go1.14 testing/common#Errorf().("#%d: in.ReadASN1Integer() = %v, want true; out = %d, want %d", i, ok, out, test.out)
164 }
165 }
166
167 // Repeat the same cases, reading into a big.Int.
168 t.Runscip-go gomod github.com/golang/go/src go1.14 testing/T#Run().("big.Int", func(t *testingscip-go gomod github.com/golang/go/src go1.14 testing/.Tscip-go gomod github.com/golang/go/src go1.14 testing/T#) {
169 for i, test := range testData64 {
170 in := Stringscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/String#(test.in)
171 var out bigscip-go gomod github.com/golang/go/src go1.14 `math/big`/.Intscip-go gomod github.com/golang/go/src go1.14 `math/big`/Int#
172 ok := in.ReadASN1Integerscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/String#ReadASN1Integer().(&out)
173 if !ok || out.Int64scip-go gomod github.com/golang/go/src go1.14 `math/big`/Int#Int64().() != test.out {
174 t.Errorfscip-go gomod github.com/golang/go/src go1.14 testing/common#Errorf().("#%d: in.ReadASN1Integer() = %v, want true; out = %d, want %d", i, ok, out.Int64scip-go gomod github.com/golang/go/src go1.14 `math/big`/Int#Int64().(), test.out)
175 }
176 }
177 })
178
179 // Repeat the same cases, reading into a []byte.
180 t.Runscip-go gomod github.com/golang/go/src go1.14 testing/T#Run().("bytes", func(t *testingscip-go gomod github.com/golang/go/src go1.14 testing/.Tscip-go gomod github.com/golang/go/src go1.14 testing/T#) {
181 for i, test := range testData64 {
182 in := Stringscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/String#(test.in)
183 var out []byte
184 ok := in.ReadASN1Integerscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/String#ReadASN1Integer().(&out)
185 if test.out < 0 {
186 if ok {
187 t.Errorfscip-go gomod github.com/golang/go/src go1.14 testing/common#Errorf().("#%d: in.ReadASN1Integer(%d) = %v, want false", i, test.out, ok)
188 }
189 continue
190 }
191 if !ok {
192 t.Errorfscip-go gomod github.com/golang/go/src go1.14 testing/common#Errorf().("#%d: in.ReadASN1Integer() = %v, want true", i, ok)
193 continue
194 }
195 n := new(bigscip-go gomod github.com/golang/go/src go1.14 `math/big`/.Intscip-go gomod github.com/golang/go/src go1.14 `math/big`/Int#).SetBytesscip-go gomod github.com/golang/go/src go1.14 `math/big`/Int#SetBytes().(out).Int64scip-go gomod github.com/golang/go/src go1.14 `math/big`/Int#Int64().()
196 if n != test.out {
197 t.Errorfscip-go gomod github.com/golang/go/src go1.14 testing/common#Errorf().("#%d: in.ReadASN1Integer() = %v, want true; out = %x, want %d", i, ok, out, test.out)
198 }
199 if out[0] == 0 && len(out) > 1 {
200 t.Errorfscip-go gomod github.com/golang/go/src go1.14 testing/common#Errorf().("#%d: in.ReadASN1Integer() = %v; out = %x, has leading zeroes", i, ok, out)
201 }
202 }
203 })
204
205 // Repeat with the implicit-tagging functions
206 t.Runscip-go gomod github.com/golang/go/src go1.14 testing/T#Run().("WithTag", func(t *testingscip-go gomod github.com/golang/go/src go1.14 testing/.Tscip-go gomod github.com/golang/go/src go1.14 testing/T#) {
207 for i, test := range testData64 {
208 tag := asn1scip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte/asn1`/.Tagscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte/asn1`/Tag#((i * 3) % 32).ContextSpecificscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte/asn1`/Tag#ContextSpecific().()
209
210 testData := make([]byte, len(test.in))
211 copy(testData, test.in)
212
213 // Alter the tag of the test case.
214 testData[0] = uint8(tag)
215
216 in := Stringscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/String#(testData)
217 var out int64
218 ok := in.ReadASN1Int64WithTagscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/String#ReadASN1Int64WithTag().(&out, tag)
219 if !ok || out != test.out {
220 t.Errorfscip-go gomod github.com/golang/go/src go1.14 testing/common#Errorf().("#%d: in.ReadASN1Int64WithTag() = %v, want true; out = %d, want %d", i, ok, out, test.out)
221 }
222
223 var b Builderscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/Builder#
224 b.AddASN1Int64WithTagscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/Builder#AddASN1Int64WithTag().(test.out, tag)
225 result, err := b.Bytesscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/Builder#Bytes().()
226
227 if err != nil {
228 t.Errorfscip-go gomod github.com/golang/go/src go1.14 testing/common#Errorf().("#%d: AddASN1Int64WithTag failed: %s", i, err)
229 continue
230 }
231
232 if !bytesscip-go gomod github.com/golang/go/src go1.14 bytes/.Equalscip-go gomod github.com/golang/go/src go1.14 bytes/Equal().(result, testData) {
233 t.Errorfscip-go gomod github.com/golang/go/src go1.14 testing/common#Errorf().("#%d: AddASN1Int64WithTag: got %x, want %x", i, result, testData)
234 }
235 }
236 })
237 }
238
239 func TestReadASN1IntegerUnsignedscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/TestReadASN1IntegerUnsigned().(t *testingscip-go gomod github.com/golang/go/src go1.14 testing/.Tscip-go gomod github.com/golang/go/src go1.14 testing/T#) {
240 testData := []struct {
241 in []byte
242 out uint64
243 }{
244 {[]byte{2, 1, 0}, 0},
245 {[]byte{2, 1, 1}, 1},
246 {[]byte{2, 1, 2}, 2},
247 {[]byte{2, 1, 127}, 127},
248 {[]byte{2, 2, 0, 128}, 128},
249 {[]byte{2, 2, 1, 0}, 256},
250 {[]byte{2, 4, 0, 128, 0, 0}, 0x800000},
251 {[]byte{2, 8, 127, 255, 255, 255, 255, 255, 255, 255}, 0x7fffffffffffffff},
252 {[]byte{2, 9, 0, 128, 0, 0, 0, 0, 0, 0, 0}, 0x8000000000000000},
253 {[]byte{2, 9, 0, 255, 255, 255, 255, 255, 255, 255, 255}, 0xffffffffffffffff},
254 }
255 for i, test := range testData {
256 in := Stringscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/String#(test.in)
257 var out uint64
258 ok := in.ReadASN1Integerscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/String#ReadASN1Integer().(&out)
259 if !ok || out != test.out {
260 t.Errorfscip-go gomod github.com/golang/go/src go1.14 testing/common#Errorf().("#%d: in.ReadASN1Integer() = %v, want true; out = %d, want %d", i, ok, out, test.out)
261 }
262 }
263 }
264
265 func TestReadASN1IntegerInvalidscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/TestReadASN1IntegerInvalid().(t *testingscip-go gomod github.com/golang/go/src go1.14 testing/.Tscip-go gomod github.com/golang/go/src go1.14 testing/T#) {
266 testData := []Stringscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/String#{
267 []byte{3, 1, 0}, // invalid tag
268 // truncated
269 []byte{2, 1},
270 []byte{2, 2, 0},
271 // not minimally encoded
272 []byte{2, 2, 0, 1},
273 []byte{2, 2, 0xff, 0xff},
274 }
275
276 for i, test := range testData {
277 var out int64
278 if test.ReadASN1Integerscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/String#ReadASN1Integer().(&out) {
279 t.Errorfscip-go gomod github.com/golang/go/src go1.14 testing/common#Errorf().("#%d: in.ReadASN1Integer() = true, want false (out = %d)", i, out)
280 }
281 }
282 }
283
284 func TestASN1ObjectIdentifierscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/TestASN1ObjectIdentifier().(t *testingscip-go gomod github.com/golang/go/src go1.14 testing/.Tscip-go gomod github.com/golang/go/src go1.14 testing/T#) {
285 testData := []struct {
286 in []byte
287 ok bool
288 out []int
289 }{
290 {[]byte{}, false, []int{}},
291 {[]byte{6, 0}, false, []int{}},
292 {[]byte{5, 1, 85}, false, []int{2, 5}},
293 {[]byte{6, 1, 85}, true, []int{2, 5}},
294 {[]byte{6, 2, 85, 0x02}, true, []int{2, 5, 2}},
295 {[]byte{6, 4, 85, 0x02, 0xc0, 0x00}, true, []int{2, 5, 2, 0x2000}},
296 {[]byte{6, 3, 0x81, 0x34, 0x03}, true, []int{2, 100, 3}},
297 {[]byte{6, 7, 85, 0x02, 0xc0, 0x80, 0x80, 0x80, 0x80}, false, []int{}},
298 {[]byte{6, 7, 85, 0x02, 0x85, 0xc7, 0xcc, 0xfb, 0x01}, true, []int{2, 5, 2, 1492336001}},
299 {[]byte{6, 7, 0x55, 0x02, 0x87, 0xff, 0xff, 0xff, 0x7f}, true, []int{2, 5, 2, 2147483647}}, // 2**31-1
300 {[]byte{6, 7, 0x55, 0x02, 0x88, 0x80, 0x80, 0x80, 0x00}, false, []int{}}, // 2**31
301 {[]byte{6, 3, 85, 0x80, 0x02}, false, []int{}}, // leading 0x80 octet
302 }
303
304 for i, test := range testData {
305 in := Stringscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/String#(test.in)
306 var out encoding_asn1scip-go gomod github.com/golang/go/src go1.14 `encoding/asn1`/.ObjectIdentifierscip-go gomod github.com/golang/go/src go1.14 `encoding/asn1`/ObjectIdentifier#
307 ok := in.ReadASN1ObjectIdentifierscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/String#ReadASN1ObjectIdentifier().(&out)
308 if ok != test.ok || ok && !out.Equalscip-go gomod github.com/golang/go/src go1.14 `encoding/asn1`/ObjectIdentifier#Equal().(test.out) {
309 t.Errorfscip-go gomod github.com/golang/go/src go1.14 testing/common#Errorf().("#%d: in.ReadASN1ObjectIdentifier() = %v, want %v; out = %v, want %v", i, ok, test.ok, out, test.out)
310 continue
311 }
312
313 var b Builderscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/Builder#
314 b.AddASN1ObjectIdentifierscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/Builder#AddASN1ObjectIdentifier().(out)
315 result, err := b.Bytesscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/Builder#Bytes().()
316 if builderOk := err == nil; test.ok != builderOk {
317 t.Errorfscip-go gomod github.com/golang/go/src go1.14 testing/common#Errorf().("#%d: error from Builder.Bytes: %s", i, err)
318 continue
319 }
320 if test.ok && !bytesscip-go gomod github.com/golang/go/src go1.14 bytes/.Equalscip-go gomod github.com/golang/go/src go1.14 bytes/Equal().(result, test.in) {
321 t.Errorfscip-go gomod github.com/golang/go/src go1.14 testing/common#Errorf().("#%d: reserialisation didn't match, got %x, want %x", i, result, test.in)
322 continue
323 }
324 }
325 }
326
327 func TestReadASN1GeneralizedTimescip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/TestReadASN1GeneralizedTime().(t *testingscip-go gomod github.com/golang/go/src go1.14 testing/.Tscip-go gomod github.com/golang/go/src go1.14 testing/T#) {
328 testData := []struct {
329 in string
330 ok bool
331 out timescip-go gomod github.com/golang/go/src go1.14 time/.Timescip-go gomod github.com/golang/go/src go1.14 time/Time#
332 }{
333 {"20100102030405Z", true, timescip-go gomod github.com/golang/go/src go1.14 time/.Datescip-go gomod github.com/golang/go/src go1.14 time/Date().(2010, 01, 02, 03, 04, 05, 0, timescip-go gomod github.com/golang/go/src go1.14 time/.UTCscip-go gomod github.com/golang/go/src go1.14 time/UTC.)},
334 {"20100102030405", false, timescip-go gomod github.com/golang/go/src go1.14 time/.Timescip-go gomod github.com/golang/go/src go1.14 time/Time#{}},
335 {"20100102030405+0607", true, timescip-go gomod github.com/golang/go/src go1.14 time/.Datescip-go gomod github.com/golang/go/src go1.14 time/Date().(2010, 01, 02, 03, 04, 05, 0, timescip-go gomod github.com/golang/go/src go1.14 time/.FixedZonescip-go gomod github.com/golang/go/src go1.14 time/FixedZone().("", 6*60*60+7*60))},
336 {"20100102030405-0607", true, timescip-go gomod github.com/golang/go/src go1.14 time/.Datescip-go gomod github.com/golang/go/src go1.14 time/Date().(2010, 01, 02, 03, 04, 05, 0, timescip-go gomod github.com/golang/go/src go1.14 time/.FixedZonescip-go gomod github.com/golang/go/src go1.14 time/FixedZone().("", -6*60*60-7*60))},
337 /* These are invalid times. However, the time package normalises times
338 * and they were accepted in some versions. See #11134. */
339 {"00000100000000Z", false, timescip-go gomod github.com/golang/go/src go1.14 time/.Timescip-go gomod github.com/golang/go/src go1.14 time/Time#{}},
340 {"20101302030405Z", false, timescip-go gomod github.com/golang/go/src go1.14 time/.Timescip-go gomod github.com/golang/go/src go1.14 time/Time#{}},
341 {"20100002030405Z", false, timescip-go gomod github.com/golang/go/src go1.14 time/.Timescip-go gomod github.com/golang/go/src go1.14 time/Time#{}},
342 {"20100100030405Z", false, timescip-go gomod github.com/golang/go/src go1.14 time/.Timescip-go gomod github.com/golang/go/src go1.14 time/Time#{}},
343 {"20100132030405Z", false, timescip-go gomod github.com/golang/go/src go1.14 time/.Timescip-go gomod github.com/golang/go/src go1.14 time/Time#{}},
344 {"20100231030405Z", false, timescip-go gomod github.com/golang/go/src go1.14 time/.Timescip-go gomod github.com/golang/go/src go1.14 time/Time#{}},
345 {"20100102240405Z", false, timescip-go gomod github.com/golang/go/src go1.14 time/.Timescip-go gomod github.com/golang/go/src go1.14 time/Time#{}},
346 {"20100102036005Z", false, timescip-go gomod github.com/golang/go/src go1.14 time/.Timescip-go gomod github.com/golang/go/src go1.14 time/Time#{}},
347 {"20100102030460Z", false, timescip-go gomod github.com/golang/go/src go1.14 time/.Timescip-go gomod github.com/golang/go/src go1.14 time/Time#{}},
348 {"-20100102030410Z", false, timescip-go gomod github.com/golang/go/src go1.14 time/.Timescip-go gomod github.com/golang/go/src go1.14 time/Time#{}},
349 {"2010-0102030410Z", false, timescip-go gomod github.com/golang/go/src go1.14 time/.Timescip-go gomod github.com/golang/go/src go1.14 time/Time#{}},
350 {"2010-0002030410Z", false, timescip-go gomod github.com/golang/go/src go1.14 time/.Timescip-go gomod github.com/golang/go/src go1.14 time/Time#{}},
351 {"201001-02030410Z", false, timescip-go gomod github.com/golang/go/src go1.14 time/.Timescip-go gomod github.com/golang/go/src go1.14 time/Time#{}},
352 {"20100102-030410Z", false, timescip-go gomod github.com/golang/go/src go1.14 time/.Timescip-go gomod github.com/golang/go/src go1.14 time/Time#{}},
353 {"2010010203-0410Z", false, timescip-go gomod github.com/golang/go/src go1.14 time/.Timescip-go gomod github.com/golang/go/src go1.14 time/Time#{}},
354 {"201001020304-10Z", false, timescip-go gomod github.com/golang/go/src go1.14 time/.Timescip-go gomod github.com/golang/go/src go1.14 time/Time#{}},
355 }
356 for i, test := range testData {
357 in := Stringscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/String#(append([]byte{byte(asn1scip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte/asn1`/.GeneralizedTimescip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte/asn1`/GeneralizedTime.), byte(len(test.in))}, test.in...))
358 var out timescip-go gomod github.com/golang/go/src go1.14 time/.Timescip-go gomod github.com/golang/go/src go1.14 time/Time#
359 ok := in.ReadASN1GeneralizedTimescip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/String#ReadASN1GeneralizedTime().(&out)
360 if ok != test.ok || ok && !reflectscip-go gomod github.com/golang/go/src go1.14 reflect/.DeepEqualscip-go gomod github.com/golang/go/src go1.14 reflect/DeepEqual().(out, test.out) {
361 t.Errorfscip-go gomod github.com/golang/go/src go1.14 testing/common#Errorf().("#%d: in.ReadASN1GeneralizedTime() = %v, want %v; out = %q, want %q", i, ok, test.ok, out, test.out)
362 }
363 }
364 }
365
366 func TestReadASN1UTCTimescip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/TestReadASN1UTCTime().(t *testingscip-go gomod github.com/golang/go/src go1.14 testing/.Tscip-go gomod github.com/golang/go/src go1.14 testing/T#) {
367 testData := []struct {
368 in string
369 ok bool
370 out timescip-go gomod github.com/golang/go/src go1.14 time/.Timescip-go gomod github.com/golang/go/src go1.14 time/Time#
371 }{
372 {"000102030405Z", true, timescip-go gomod github.com/golang/go/src go1.14 time/.Datescip-go gomod github.com/golang/go/src go1.14 time/Date().(2000, 01, 02, 03, 04, 05, 0, timescip-go gomod github.com/golang/go/src go1.14 time/.UTCscip-go gomod github.com/golang/go/src go1.14 time/UTC.)},
373 {"500102030405Z", true, timescip-go gomod github.com/golang/go/src go1.14 time/.Datescip-go gomod github.com/golang/go/src go1.14 time/Date().(1950, 01, 02, 03, 04, 05, 0, timescip-go gomod github.com/golang/go/src go1.14 time/.UTCscip-go gomod github.com/golang/go/src go1.14 time/UTC.)},
374 {"490102030405Z", true, timescip-go gomod github.com/golang/go/src go1.14 time/.Datescip-go gomod github.com/golang/go/src go1.14 time/Date().(2049, 01, 02, 03, 04, 05, 0, timescip-go gomod github.com/golang/go/src go1.14 time/.UTCscip-go gomod github.com/golang/go/src go1.14 time/UTC.)},
375 {"990102030405Z", true, timescip-go gomod github.com/golang/go/src go1.14 time/.Datescip-go gomod github.com/golang/go/src go1.14 time/Date().(1999, 01, 02, 03, 04, 05, 0, timescip-go gomod github.com/golang/go/src go1.14 time/.UTCscip-go gomod github.com/golang/go/src go1.14 time/UTC.)},
376 {"250102030405Z", true, timescip-go gomod github.com/golang/go/src go1.14 time/.Datescip-go gomod github.com/golang/go/src go1.14 time/Date().(2025, 01, 02, 03, 04, 05, 0, timescip-go gomod github.com/golang/go/src go1.14 time/.UTCscip-go gomod github.com/golang/go/src go1.14 time/UTC.)},
377 {"750102030405Z", true, timescip-go gomod github.com/golang/go/src go1.14 time/.Datescip-go gomod github.com/golang/go/src go1.14 time/Date().(1975, 01, 02, 03, 04, 05, 0, timescip-go gomod github.com/golang/go/src go1.14 time/.UTCscip-go gomod github.com/golang/go/src go1.14 time/UTC.)},
378 {"000102030405+0905", true, timescip-go gomod github.com/golang/go/src go1.14 time/.Datescip-go gomod github.com/golang/go/src go1.14 time/Date().(2000, 01, 02, 03, 04, 05, 0, timescip-go gomod github.com/golang/go/src go1.14 time/.FixedZonescip-go gomod github.com/golang/go/src go1.14 time/FixedZone().("", 9*60*60+5*60))},
379 {"000102030405-0905", true, timescip-go gomod github.com/golang/go/src go1.14 time/.Datescip-go gomod github.com/golang/go/src go1.14 time/Date().(2000, 01, 02, 03, 04, 05, 0, timescip-go gomod github.com/golang/go/src go1.14 time/.FixedZonescip-go gomod github.com/golang/go/src go1.14 time/FixedZone().("", -9*60*60-5*60))},
380 {"0001020304Z", true, timescip-go gomod github.com/golang/go/src go1.14 time/.Datescip-go gomod github.com/golang/go/src go1.14 time/Date().(2000, 01, 02, 03, 04, 0, 0, timescip-go gomod github.com/golang/go/src go1.14 time/.UTCscip-go gomod github.com/golang/go/src go1.14 time/UTC.)},
381 {"5001020304Z", true, timescip-go gomod github.com/golang/go/src go1.14 time/.Datescip-go gomod github.com/golang/go/src go1.14 time/Date().(1950, 01, 02, 03, 04, 00, 0, timescip-go gomod github.com/golang/go/src go1.14 time/.UTCscip-go gomod github.com/golang/go/src go1.14 time/UTC.)},
382 {"0001020304+0905", true, timescip-go gomod github.com/golang/go/src go1.14 time/.Datescip-go gomod github.com/golang/go/src go1.14 time/Date().(2000, 01, 02, 03, 04, 0, 0, timescip-go gomod github.com/golang/go/src go1.14 time/.FixedZonescip-go gomod github.com/golang/go/src go1.14 time/FixedZone().("", 9*60*60+5*60))},
383 {"0001020304-0905", true, timescip-go gomod github.com/golang/go/src go1.14 time/.Datescip-go gomod github.com/golang/go/src go1.14 time/Date().(2000, 01, 02, 03, 04, 0, 0, timescip-go gomod github.com/golang/go/src go1.14 time/.FixedZonescip-go gomod github.com/golang/go/src go1.14 time/FixedZone().("", -9*60*60-5*60))},
384 {"000102030405Z0700", false, timescip-go gomod github.com/golang/go/src go1.14 time/.Timescip-go gomod github.com/golang/go/src go1.14 time/Time#{}},
385 {"000102030405", false, timescip-go gomod github.com/golang/go/src go1.14 time/.Timescip-go gomod github.com/golang/go/src go1.14 time/Time#{}},
386 }
387 for i, test := range testData {
388 in := Stringscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/String#(append([]byte{byte(asn1scip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte/asn1`/.UTCTimescip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte/asn1`/UTCTime.), byte(len(test.in))}, test.in...))
389 var out timescip-go gomod github.com/golang/go/src go1.14 time/.Timescip-go gomod github.com/golang/go/src go1.14 time/Time#
390 ok := in.ReadASN1UTCTimescip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/String#ReadASN1UTCTime().(&out)
391 if ok != test.ok || ok && !reflectscip-go gomod github.com/golang/go/src go1.14 reflect/.DeepEqualscip-go gomod github.com/golang/go/src go1.14 reflect/DeepEqual().(out, test.out) {
392 t.Errorfscip-go gomod github.com/golang/go/src go1.14 testing/common#Errorf().("#%d: in.ReadASN1UTCTime() = %v, want %v; out = %q, want %q", i, ok, test.ok, out, test.out)
393 }
394 }
395 }
396
397 func TestReadASN1BitStringscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/TestReadASN1BitString().(t *testingscip-go gomod github.com/golang/go/src go1.14 testing/.Tscip-go gomod github.com/golang/go/src go1.14 testing/T#) {
398 testData := []struct {
399 in []byte
400 ok bool
401 out encoding_asn1scip-go gomod github.com/golang/go/src go1.14 `encoding/asn1`/.BitStringscip-go gomod github.com/golang/go/src go1.14 `encoding/asn1`/BitString#
402 }{
403 {[]byte{}, false, encoding_asn1scip-go gomod github.com/golang/go/src go1.14 `encoding/asn1`/.BitStringscip-go gomod github.com/golang/go/src go1.14 `encoding/asn1`/BitString#{}},
404 {[]byte{0x00}, true, encoding_asn1scip-go gomod github.com/golang/go/src go1.14 `encoding/asn1`/.BitStringscip-go gomod github.com/golang/go/src go1.14 `encoding/asn1`/BitString#{}},
405 {[]byte{0x07, 0x00}, true, encoding_asn1scip-go gomod github.com/golang/go/src go1.14 `encoding/asn1`/.BitStringscip-go gomod github.com/golang/go/src go1.14 `encoding/asn1`/BitString#{Bytesscip-go gomod github.com/golang/go/src go1.14 `encoding/asn1`/BitString#Bytes.: []byte{0}, BitLengthscip-go gomod github.com/golang/go/src go1.14 `encoding/asn1`/BitString#BitLength.: 1}},
406 {[]byte{0x07, 0x01}, false, encoding_asn1scip-go gomod github.com/golang/go/src go1.14 `encoding/asn1`/.BitStringscip-go gomod github.com/golang/go/src go1.14 `encoding/asn1`/BitString#{}},
407 {[]byte{0x07, 0x40}, false, encoding_asn1scip-go gomod github.com/golang/go/src go1.14 `encoding/asn1`/.BitStringscip-go gomod github.com/golang/go/src go1.14 `encoding/asn1`/BitString#{}},
408 {[]byte{0x08, 0x00}, false, encoding_asn1scip-go gomod github.com/golang/go/src go1.14 `encoding/asn1`/.BitStringscip-go gomod github.com/golang/go/src go1.14 `encoding/asn1`/BitString#{}},
409 {[]byte{0xff}, false, encoding_asn1scip-go gomod github.com/golang/go/src go1.14 `encoding/asn1`/.BitStringscip-go gomod github.com/golang/go/src go1.14 `encoding/asn1`/BitString#{}},
410 {[]byte{0xfe, 0x00}, false, encoding_asn1scip-go gomod github.com/golang/go/src go1.14 `encoding/asn1`/.BitStringscip-go gomod github.com/golang/go/src go1.14 `encoding/asn1`/BitString#{}},
411 }
412 for i, test := range testData {
413 in := Stringscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/String#(append([]byte{3, byte(len(test.in))}, test.in...))
414 var out encoding_asn1scip-go gomod github.com/golang/go/src go1.14 `encoding/asn1`/.BitStringscip-go gomod github.com/golang/go/src go1.14 `encoding/asn1`/BitString#
415 ok := in.ReadASN1BitStringscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/String#ReadASN1BitString().(&out)
416 if ok != test.ok || ok && (!bytesscip-go gomod github.com/golang/go/src go1.14 bytes/.Equalscip-go gomod github.com/golang/go/src go1.14 bytes/Equal().(out.Bytesscip-go gomod github.com/golang/go/src go1.14 `encoding/asn1`/BitString#Bytes., test.out.Bytesscip-go gomod github.com/golang/go/src go1.14 `encoding/asn1`/BitString#Bytes.) || out.BitLengthscip-go gomod github.com/golang/go/src go1.14 `encoding/asn1`/BitString#BitLength. != test.out.BitLengthscip-go gomod github.com/golang/go/src go1.14 `encoding/asn1`/BitString#BitLength.) {
417 t.Errorfscip-go gomod github.com/golang/go/src go1.14 testing/common#Errorf().("#%d: in.ReadASN1BitString() = %v, want %v; out = %v, want %v", i, ok, test.ok, out, test.out)
418 }
419 }
420 }
421
422 func TestAddASN1BigIntscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/TestAddASN1BigInt().(t *testingscip-go gomod github.com/golang/go/src go1.14 testing/.Tscip-go gomod github.com/golang/go/src go1.14 testing/T#) {
423 x := bigscip-go gomod github.com/golang/go/src go1.14 `math/big`/.NewIntscip-go gomod github.com/golang/go/src go1.14 `math/big`/NewInt().(-1)
424 var b Builderscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/Builder#
425 b.AddASN1BigIntscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/Builder#AddASN1BigInt().(x)
426 got, err := b.Bytesscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/Builder#Bytes().()
427 if err != nil {
428 t.Fatalfscip-go gomod github.com/golang/go/src go1.14 testing/common#Fatalf().("unexpected error adding -1: %v", err)
429 }
430 s := Stringscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/String#(got)
431 var y bigscip-go gomod github.com/golang/go/src go1.14 `math/big`/.Intscip-go gomod github.com/golang/go/src go1.14 `math/big`/Int#
432 ok := s.ReadASN1Integerscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/String#ReadASN1Integer().(&y)
433 if !ok || x.Cmpscip-go gomod github.com/golang/go/src go1.14 `math/big`/Int#Cmp().(&y) != 0 {
434 t.Errorfscip-go gomod github.com/golang/go/src go1.14 testing/common#Errorf().("unexpected bytes %v, want %v", &y, x)
435 }
436 }
437
438 func TestReadASN1Booleanscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/TestReadASN1Boolean().(t *testingscip-go gomod github.com/golang/go/src go1.14 testing/.Tscip-go gomod github.com/golang/go/src go1.14 testing/T#) {
439 testData := []struct {
440 in []byte
441 ok bool
442 out bool
443 }{
444 {[]byte{}, false, false},
445 {[]byte{0x01, 0x01, 0x00}, true, false},
446 {[]byte{0x01, 0x01, 0xff}, true, true},
447 {[]byte{0x01, 0x01, 0x01}, false, false},
448 }
449 for i, test := range testData {
450 in := Stringscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/String#(test.in)
451 var out bool
452 ok := in.ReadASN1Booleanscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/String#ReadASN1Boolean().(&out)
453 if ok != test.ok || ok && (out != test.out) {
454 t.Errorfscip-go gomod github.com/golang/go/src go1.14 testing/common#Errorf().("#%d: in.ReadASN1Boolean() = %v, want %v; out = %v, want %v", i, ok, test.ok, out, test.out)
455 }
456 }
457 }