Debian Codegraph @

internal/legacy/x509/oid.go

raw symbols SCIP
1 // Copyright 2023 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 legacyx509scip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/legacy/x509`/
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`/"
10 "errorsscip-go gomod github.com/golang/go/src go1.14 errors/"
11 "mathscip-go gomod github.com/golang/go/src go1.14 math/"
12 "math/bigscip-go gomod github.com/golang/go/src go1.14 `math/big`/"
13 "math/bitsscip-go gomod github.com/golang/go/src go1.14 `math/bits`/"
14 "strconvscip-go gomod github.com/golang/go/src go1.14 strconv/"
15 "stringsscip-go gomod github.com/golang/go/src go1.14 strings/"
16 )
17
18 var (
19 errInvalidOIDscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/legacy/x509`/errInvalidOID. = errorsscip-go gomod github.com/golang/go/src go1.14 errors/.Newscip-go gomod github.com/golang/go/src go1.14 errors/New().("invalid oid")
20 )
21
22 // An OID represents an ASN.1 OBJECT IDENTIFIER.
23 type OIDscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/legacy/x509`/OID# struct {
24 derscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/legacy/x509`/OID#der. []byte
25 }
26
27 // ParseOID parses a Object Identifier string, represented by ASCII numbers separated by dots.
28 func ParseOIDscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/legacy/x509`/ParseOID().(oid string) (OIDscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/legacy/x509`/OID#, error) {
29 var o OIDscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/legacy/x509`/OID#
30 return o, o.unmarshalOIDTextscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/legacy/x509`/OID#unmarshalOIDText().(oid)
31 }
32
33 func newOIDFromDERscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/legacy/x509`/newOIDFromDER().(der []byte) (OIDscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/legacy/x509`/OID#, bool) {
34 if len(der) == 0 || der[len(der)-1]&0x80 != 0 {
35 return OIDscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/legacy/x509`/OID#{}, false
36 }
37
38 start := 0
39 for i, v := range der {
40 // ITU-T X.690, section 8.19.2:
41 // The subidentifier shall be encoded in the fewest possible octets,
42 // that is, the leading octet of the subidentifier shall not have the value 0x80.
43 if i == start && v == 0x80 {
44 return OIDscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/legacy/x509`/OID#{}, false
45 }
46 if v&0x80 == 0 {
47 start = i + 1
48 }
49 }
50
51 return OIDscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/legacy/x509`/OID#{der}, true
52 }
53
54 // OIDFromInts creates a new OID using ints, each integer is a separate component.
55 func OIDFromIntsscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/legacy/x509`/OIDFromInts().(oid []uint64) (OIDscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/legacy/x509`/OID#, error) {
56 if len(oid) < 2 || oid[0] > 2 || (oid[0] < 2 && oid[1] >= 40) {
57 return OIDscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/legacy/x509`/OID#{}, errInvalidOIDscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/legacy/x509`/errInvalidOID.
58 }
59
60 length := base128IntLengthscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/legacy/x509`/base128IntLength().(oid[0]*40 + oid[1])
61 for _, v := range oid[2:] {
62 length += base128IntLengthscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/legacy/x509`/base128IntLength().(v)
63 }
64
65 der := make([]byte, 0, length)
66 der = appendBase128Intscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/legacy/x509`/appendBase128Int().(der, oid[0]*40+oid[1])
67 for _, v := range oid[2:] {
68 der = appendBase128Intscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/legacy/x509`/appendBase128Int().(der, v)
69 }
70 return OIDscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/legacy/x509`/OID#{der}, nil
71 }
72
73 func base128IntLengthscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/legacy/x509`/base128IntLength().(n uint64) int {
74 if n == 0 {
75 return 1
76 }
77 return (bitsscip-go gomod github.com/golang/go/src go1.14 `math/bits`/.Len64scip-go gomod github.com/golang/go/src go1.14 `math/bits`/Len64().(n) + 6) / 7
78 }
79
80 func appendBase128Intscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/legacy/x509`/appendBase128Int().(dst []byte, n uint64) []byte {
81 for i := base128IntLengthscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/legacy/x509`/base128IntLength().(n) - 1; i >= 0; i-- {
82 o := byte(n >> uint(i*7))
83 o &= 0x7f
84 if i != 0 {
85 o |= 0x80
86 }
87 dst = append(dst, o)
88 }
89 return dst
90 }
91
92 func base128BigIntLengthscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/legacy/x509`/base128BigIntLength().(n *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#) int {
93 if n.Cmpscip-go gomod github.com/golang/go/src go1.14 `math/big`/Int#Cmp().(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().(0)) == 0 {
94 return 1
95 }
96 return (n.BitLenscip-go gomod github.com/golang/go/src go1.14 `math/big`/Int#BitLen().() + 6) / 7
97 }
98
99 func appendBase128BigIntscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/legacy/x509`/appendBase128BigInt().(dst []byte, n *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#) []byte {
100 if n.Cmpscip-go gomod github.com/golang/go/src go1.14 `math/big`/Int#Cmp().(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().(0)) == 0 {
101 return append(dst, 0)
102 }
103
104 for i := base128BigIntLengthscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/legacy/x509`/base128BigIntLength().(n) - 1; i >= 0; i-- {
105 o := byte(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().(0).Rshscip-go gomod github.com/golang/go/src go1.14 `math/big`/Int#Rsh().(n, uint(i)*7).Bitsscip-go gomod github.com/golang/go/src go1.14 `math/big`/Int#Bits().()[0])
106 o &= 0x7f
107 if i != 0 {
108 o |= 0x80
109 }
110 dst = append(dst, o)
111 }
112 return dst
113 }
114
115 // AppendText implements [encoding.TextAppender]
116 func (o OIDscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/legacy/x509`/OID#) AppendTextscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/legacy/x509`/OID#AppendText().(b []byte) ([]byte, error) {
117 return append(b, o.Stringscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/legacy/x509`/OID#String().()...), nil
118 }
119
120 // MarshalText implements [encoding.TextMarshaler]
121 func (o OIDscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/legacy/x509`/OID#) MarshalTextscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/legacy/x509`/OID#MarshalText().() ([]byte, error) {
122 return o.AppendTextscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/legacy/x509`/OID#AppendText().(nil)
123 }
124
125 // UnmarshalText implements [encoding.TextUnmarshaler]
126 func (o *OIDscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/legacy/x509`/OID#) UnmarshalTextscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/legacy/x509`/OID#UnmarshalText().(text []byte) error {
127 return o.unmarshalOIDTextscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/legacy/x509`/OID#unmarshalOIDText().(string(text))
128 }
129
130 // cutString slices s around the first instance of sep,
131 // returning the text before and after sep.
132 // The found result reports whether sep appears in s.
133 // If sep does not appear in s, cut returns s, "", false.
134 func cutStringscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/legacy/x509`/cutString().(s, sep string) (before, after string, found bool) {
135 if i := stringsscip-go gomod github.com/golang/go/src go1.14 strings/.Indexscip-go gomod github.com/golang/go/src go1.14 strings/Index().(s, sep); i >= 0 {
136 return s[:i], s[i+len(sep):], true
137 }
138 return s, "", false
139 }
140
141 func (o *OIDscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/legacy/x509`/OID#) unmarshalOIDTextscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/legacy/x509`/OID#unmarshalOIDText().(oid string) error {
142 // (*big.Int).SetString allows +/- signs, but we don't want
143 // to allow them in the string representation of Object Identifier, so
144 // reject such encodings.
145 for _, c := range oid {
146 isDigit := c >= '0' && c <= '9'
147 if !isDigit && c != '.' {
148 return errInvalidOIDscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/legacy/x509`/errInvalidOID.
149 }
150 }
151
152 var (
153 firstNum string
154 secondNum string
155 )
156
157 var nextComponentExists bool
158 firstNum, oid, nextComponentExists = cutStringscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/legacy/x509`/cutString().(oid, ".")
159 if !nextComponentExists {
160 return errInvalidOIDscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/legacy/x509`/errInvalidOID.
161 }
162 secondNum, oid, nextComponentExists = cutStringscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/legacy/x509`/cutString().(oid, ".")
163
164 var (
165 first = 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().(0)
166 second = 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().(0)
167 )
168
169 if _, ok := first.SetStringscip-go gomod github.com/golang/go/src go1.14 `math/big`/Int#SetString().(firstNum, 10); !ok {
170 return errInvalidOIDscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/legacy/x509`/errInvalidOID.
171 }
172 if _, ok := second.SetStringscip-go gomod github.com/golang/go/src go1.14 `math/big`/Int#SetString().(secondNum, 10); !ok {
173 return errInvalidOIDscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/legacy/x509`/errInvalidOID.
174 }
175
176 if first.Cmpscip-go gomod github.com/golang/go/src go1.14 `math/big`/Int#Cmp().(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().(2)) > 0 || (first.Cmpscip-go gomod github.com/golang/go/src go1.14 `math/big`/Int#Cmp().(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().(2)) < 0 && second.Cmpscip-go gomod github.com/golang/go/src go1.14 `math/big`/Int#Cmp().(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().(40)) >= 0) {
177 return errInvalidOIDscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/legacy/x509`/errInvalidOID.
178 }
179
180 firstComponent := first.Mulscip-go gomod github.com/golang/go/src go1.14 `math/big`/Int#Mul().(first, 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().(40))
181 firstComponent.Addscip-go gomod github.com/golang/go/src go1.14 `math/big`/Int#Add().(firstComponent, second)
182
183 der := appendBase128BigIntscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/legacy/x509`/appendBase128BigInt().(make([]byte, 0, 32), firstComponent)
184
185 for nextComponentExists {
186 var strNum string
187 strNum, oid, nextComponentExists = cutStringscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/legacy/x509`/cutString().(oid, ".")
188 b, ok := 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().(0).SetStringscip-go gomod github.com/golang/go/src go1.14 `math/big`/Int#SetString().(strNum, 10)
189 if !ok {
190 return errInvalidOIDscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/legacy/x509`/errInvalidOID.
191 }
192 der = appendBase128BigIntscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/legacy/x509`/appendBase128BigInt().(der, b)
193 }
194
195 o.derscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/legacy/x509`/OID#der. = der
196 return nil
197 }
198
199 // AppendBinary implements [encoding.BinaryAppender]
200 func (o OIDscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/legacy/x509`/OID#) AppendBinaryscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/legacy/x509`/OID#AppendBinary().(b []byte) ([]byte, error) {
201 return append(b, o.derscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/legacy/x509`/OID#der....), nil
202 }
203
204 // MarshalBinary implements [encoding.BinaryMarshaler]
205 func (o OIDscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/legacy/x509`/OID#) MarshalBinaryscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/legacy/x509`/OID#MarshalBinary().() ([]byte, error) {
206 return o.AppendBinaryscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/legacy/x509`/OID#AppendBinary().(nil)
207 }
208
209 // cloneBytes returns a copy of b[:len(b)].
210 // The result may have additional unused capacity.
211 // Clone(nil) returns nil.
212 func cloneBytesscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/legacy/x509`/cloneBytes().(b []byte) []byte {
213 if b == nil {
214 return nil
215 }
216 return append([]byte{}, b...)
217 }
218
219 // UnmarshalBinary implements [encoding.BinaryUnmarshaler]
220 func (o *OIDscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/legacy/x509`/OID#) UnmarshalBinaryscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/legacy/x509`/OID#UnmarshalBinary().(b []byte) error {
221 oid, ok := newOIDFromDERscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/legacy/x509`/newOIDFromDER().(cloneBytesscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/legacy/x509`/cloneBytes().(b))
222 if !ok {
223 return errInvalidOIDscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/legacy/x509`/errInvalidOID.
224 }
225 *o = oid
226 return nil
227 }
228
229 // Equal returns true when oid and other represents the same Object Identifier.
230 func (oid OIDscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/legacy/x509`/OID#) Equalscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/legacy/x509`/OID#Equal().(other OIDscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/legacy/x509`/OID#) bool {
231 // There is only one possible DER encoding of
232 // each unique Object Identifier.
233 return bytesscip-go gomod github.com/golang/go/src go1.14 bytes/.Equalscip-go gomod github.com/golang/go/src go1.14 bytes/Equal().(oid.derscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/legacy/x509`/OID#der., other.derscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/legacy/x509`/OID#der.)
234 }
235
236 func parseBase128Intscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/legacy/x509`/parseBase128Int().(bytes []byte, initOffset int) (ret, offset int, failed bool) {
237 offset = initOffset
238 var ret64 int64
239 for shifted := 0; offset < len(bytes); shifted++ {
240 // 5 * 7 bits per byte == 35 bits of data
241 // Thus the representation is either non-minimal or too large for an int32
242 if shifted == 5 {
243 failed = true
244 return
245 }
246 ret64 <<= 7
247 b := bytes[offset]
248 // integers should be minimally encoded, so the leading octet should
249 // never be 0x80
250 if shifted == 0 && b == 0x80 {
251 failed = true
252 return
253 }
254 ret64 |= int64(b & 0x7f)
255 offset++
256 if b&0x80 == 0 {
257 ret = int(ret64)
258 // Ensure that the returned value fits in an int on all platforms
259 if ret64 > mathscip-go gomod github.com/golang/go/src go1.14 math/.MaxInt32scip-go gomod github.com/golang/go/src go1.14 math/MaxInt32. {
260 failed = true
261 }
262 return
263 }
264 }
265 failed = true
266 return
267 }
268
269 // EqualASN1OID returns whether an OID equals an asn1.ObjectIdentifier. If
270 // asn1.ObjectIdentifier cannot represent the OID specified by oid, because
271 // a component of OID requires more than 31 bits, it returns false.
272 func (oid OIDscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/legacy/x509`/OID#) EqualASN1OIDscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/legacy/x509`/OID#EqualASN1OID().(other 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#) bool {
273 if len(other) < 2 {
274 return false
275 }
276 v, offset, failed := parseBase128Intscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/legacy/x509`/parseBase128Int().(oid.derscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/legacy/x509`/OID#der., 0)
277 if failed {
278 // This should never happen, since we've already parsed the OID,
279 // but just in case.
280 return false
281 }
282 if v < 80 {
283 a, b := v/40, v%40
284 if other[0] != a || other[1] != b {
285 return false
286 }
287 } else {
288 a, b := 2, v-80
289 if other[0] != a || other[1] != b {
290 return false
291 }
292 }
293
294 i := 2
295 for ; offset < len(oid.derscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/legacy/x509`/OID#der.); i++ {
296 v, offset, failed = parseBase128Intscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/legacy/x509`/parseBase128Int().(oid.derscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/legacy/x509`/OID#der., offset)
297 if failed {
298 // Again, shouldn't happen, since we've already parsed
299 // the OID, but better safe than sorry.
300 return false
301 }
302 if i >= len(other) || v != other[i] {
303 return false
304 }
305 }
306
307 return i == len(other)
308 }
309
310 // Strings returns the string representation of the Object Identifier.
311 func (oid OIDscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/legacy/x509`/OID#) Stringscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/legacy/x509`/OID#String().() string {
312 var b stringsscip-go gomod github.com/golang/go/src go1.14 strings/.Builderscip-go gomod github.com/golang/go/src go1.14 strings/Builder#
313 b.Growscip-go gomod github.com/golang/go/src go1.14 strings/Builder#Grow().(32)
314 const (
315 valSize = 64 // size in bits of val.
316 bitsPerByte = 7
317 maxValSafeShift = (1 << (valSize - bitsPerByte)) - 1
318 )
319 var (
320 start = 0
321 val = uint64(0)
322 numBuf = make([]byte, 0, 21)
323 bigVal *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#
324 overflow bool
325 )
326 for i, v := range oid.derscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/legacy/x509`/OID#der. {
327 curVal := v & 0x7F
328 valEnd := v&0x80 == 0
329 if valEnd {
330 if start != 0 {
331 b.WriteBytescip-go gomod github.com/golang/go/src go1.14 strings/Builder#WriteByte().('.')
332 }
333 }
334 if !overflow && val > maxValSafeShift {
335 if bigVal == nil {
336 bigVal = 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#)
337 }
338 bigVal = bigVal.SetUint64scip-go gomod github.com/golang/go/src go1.14 `math/big`/Int#SetUint64().(val)
339 overflow = true
340 }
341 if overflow {
342 bigVal = bigVal.Lshscip-go gomod github.com/golang/go/src go1.14 `math/big`/Int#Lsh().(bigVal, bitsPerByte).Orscip-go gomod github.com/golang/go/src go1.14 `math/big`/Int#Or().(bigVal, 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().(int64(curVal)))
343 if valEnd {
344 if start == 0 {
345 b.WriteStringscip-go gomod github.com/golang/go/src go1.14 strings/Builder#WriteString().("2.")
346 bigVal = bigVal.Subscip-go gomod github.com/golang/go/src go1.14 `math/big`/Int#Sub().(bigVal, 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().(80))
347 }
348 numBuf = bigVal.Appendscip-go gomod github.com/golang/go/src go1.14 `math/big`/Int#Append().(numBuf, 10)
349 b.Writescip-go gomod github.com/golang/go/src go1.14 strings/Builder#Write().(numBuf)
350 numBuf = numBuf[:0]
351 val = 0
352 start = i + 1
353 overflow = false
354 }
355 continue
356 }
357 val <<= bitsPerByte
358 val |= uint64(curVal)
359 if valEnd {
360 if start == 0 {
361 if val < 80 {
362 b.Writescip-go gomod github.com/golang/go/src go1.14 strings/Builder#Write().(strconvscip-go gomod github.com/golang/go/src go1.14 strconv/.AppendUintscip-go gomod github.com/golang/go/src go1.14 strconv/AppendUint().(numBuf, val/40, 10))
363 b.WriteBytescip-go gomod github.com/golang/go/src go1.14 strings/Builder#WriteByte().('.')
364 b.Writescip-go gomod github.com/golang/go/src go1.14 strings/Builder#Write().(strconvscip-go gomod github.com/golang/go/src go1.14 strconv/.AppendUintscip-go gomod github.com/golang/go/src go1.14 strconv/AppendUint().(numBuf, val%40, 10))
365 } else {
366 b.WriteStringscip-go gomod github.com/golang/go/src go1.14 strings/Builder#WriteString().("2.")
367 b.Writescip-go gomod github.com/golang/go/src go1.14 strings/Builder#Write().(strconvscip-go gomod github.com/golang/go/src go1.14 strconv/.AppendUintscip-go gomod github.com/golang/go/src go1.14 strconv/AppendUint().(numBuf, val-80, 10))
368 }
369 } else {
370 b.Writescip-go gomod github.com/golang/go/src go1.14 strings/Builder#Write().(strconvscip-go gomod github.com/golang/go/src go1.14 strconv/.AppendUintscip-go gomod github.com/golang/go/src go1.14 strconv/AppendUint().(numBuf, val, 10))
371 }
372 val = 0
373 start = i + 1
374 }
375 }
376 return b.Stringscip-go gomod github.com/golang/go/src go1.14 strings/Builder#String().()
377 }