Debian Codegraph @

internal/cryptobyte/builder.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 "errorsscip-go gomod github.com/golang/go/src go1.14 errors/"
9 "fmtscip-go gomod github.com/golang/go/src go1.14 fmt/"
10 )
11
12 // A Builder builds byte strings from fixed-length and length-prefixed values.
13 // Builders either allocate space as needed, or are ‘fixed’, which means that
14 // they write into a given buffer and produce an error if it's exhausted.
15 //
16 // The zero value is a usable Builder that allocates space as needed.
17 //
18 // Simple values are marshaled and appended to a Builder using methods on the
19 // Builder. Length-prefixed values are marshaled by providing a
20 // BuilderContinuation, which is a function that writes the inner contents of
21 // the value to a given Builder. See the documentation for BuilderContinuation
22 // for details.
23 type Builderscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/Builder# struct {
24 errscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/Builder#err. error
25 resultscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/Builder#result. []byte
26 fixedSizescip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/Builder#fixedSize. bool
27 childscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/Builder#child. *Builderscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/Builder#
28 offsetscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/Builder#offset. int
29 pendingLenLenscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/Builder#pendingLenLen. int
30 pendingIsASN1scip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/Builder#pendingIsASN1. bool
31 inContinuationscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/Builder#inContinuation. *bool
32 }
33
34 // NewBuilder creates a Builder that appends its output to the given buffer.
35 // Like append(), the slice will be reallocated if its capacity is exceeded.
36 // Use Bytes to get the final buffer.
37 func NewBuilderscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/NewBuilder().(buffer []byte) *Builderscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/Builder# {
38 return &Builderscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/Builder#{
39 resultscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/Builder#result.: buffer,
40 }
41 }
42
43 // NewFixedBuilder creates a Builder that appends its output into the given
44 // buffer. This builder does not reallocate the output buffer. Writes that
45 // would exceed the buffer's capacity are treated as an error.
46 func NewFixedBuilderscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/NewFixedBuilder().(buffer []byte) *Builderscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/Builder# {
47 return &Builderscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/Builder#{
48 resultscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/Builder#result.: buffer,
49 fixedSizescip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/Builder#fixedSize.: true,
50 }
51 }
52
53 // SetError sets the value to be returned as the error from Bytes. Writes
54 // performed after calling SetError are ignored.
55 func (b *Builderscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/Builder#) SetErrorscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/Builder#SetError().(err error) {
56 b.errscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/Builder#err. = err
57 }
58
59 // Bytes returns the bytes written by the builder or an error if one has
60 // occurred during building.
61 func (b *Builderscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/Builder#) Bytesscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/Builder#Bytes().() ([]byte, error) {
62 if b.errscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/Builder#err. != nil {
63 return nil, b.errscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/Builder#err.
64 }
65 return b.resultscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/Builder#result.[b.offsetscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/Builder#offset.:], nil
66 }
67
68 // BytesOrPanic returns the bytes written by the builder or panics if an error
69 // has occurred during building.
70 func (b *Builderscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/Builder#) BytesOrPanicscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/Builder#BytesOrPanic().() []byte {
71 if b.errscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/Builder#err. != nil {
72 panic(b.errscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/Builder#err.)
73 }
74 return b.resultscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/Builder#result.[b.offsetscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/Builder#offset.:]
75 }
76
77 // AddUint8 appends an 8-bit value to the byte string.
78 func (b *Builderscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/Builder#) AddUint8scip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/Builder#AddUint8().(v uint8) {
79 b.addscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/Builder#add().(byte(v))
80 }
81
82 // AddUint16 appends a big-endian, 16-bit value to the byte string.
83 func (b *Builderscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/Builder#) AddUint16scip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/Builder#AddUint16().(v uint16) {
84 b.addscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/Builder#add().(byte(v>>8), byte(v))
85 }
86
87 // AddUint24 appends a big-endian, 24-bit value to the byte string. The highest
88 // byte of the 32-bit input value is silently truncated.
89 func (b *Builderscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/Builder#) AddUint24scip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/Builder#AddUint24().(v uint32) {
90 b.addscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/Builder#add().(byte(v>>16), byte(v>>8), byte(v))
91 }
92
93 // AddUint32 appends a big-endian, 32-bit value to the byte string.
94 func (b *Builderscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/Builder#) AddUint32scip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/Builder#AddUint32().(v uint32) {
95 b.addscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/Builder#add().(byte(v>>24), byte(v>>16), byte(v>>8), byte(v))
96 }
97
98 // AddUint48 appends a big-endian, 48-bit value to the byte string.
99 func (b *Builderscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/Builder#) AddUint48scip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/Builder#AddUint48().(v uint64) {
100 b.addscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/Builder#add().(byte(v>>40), byte(v>>32), byte(v>>24), byte(v>>16), byte(v>>8), byte(v))
101 }
102
103 // AddUint64 appends a big-endian, 64-bit value to the byte string.
104 func (b *Builderscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/Builder#) AddUint64scip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/Builder#AddUint64().(v uint64) {
105 b.addscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/Builder#add().(byte(v>>56), byte(v>>48), byte(v>>40), byte(v>>32), byte(v>>24), byte(v>>16), byte(v>>8), byte(v))
106 }
107
108 // AddBytes appends a sequence of bytes to the byte string.
109 func (b *Builderscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/Builder#) AddBytesscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/Builder#AddBytes().(v []byte) {
110 b.addscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/Builder#add().(v...)
111 }
112
113 // BuilderContinuation is a continuation-passing interface for building
114 // length-prefixed byte sequences. Builder methods for length-prefixed
115 // sequences (AddUint8LengthPrefixed etc) will invoke the BuilderContinuation
116 // supplied to them. The child builder passed to the continuation can be used
117 // to build the content of the length-prefixed sequence. For example:
118 //
119 // parent := cryptobyte.NewBuilder()
120 // parent.AddUint8LengthPrefixed(func (child *Builder) {
121 // child.AddUint8(42)
122 // child.AddUint8LengthPrefixed(func (grandchild *Builder) {
123 // grandchild.AddUint8(5)
124 // })
125 // })
126 //
127 // It is an error to write more bytes to the child than allowed by the reserved
128 // length prefix. After the continuation returns, the child must be considered
129 // invalid, i.e. users must not store any copies or references of the child
130 // that outlive the continuation.
131 //
132 // If the continuation panics with a value of type BuildError then the inner
133 // error will be returned as the error from Bytes. If the child panics
134 // otherwise then Bytes will repanic with the same value.
135 type BuilderContinuationscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/BuilderContinuation# func(child *Builderscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/Builder#)
136
137 // BuildError wraps an error. If a BuilderContinuation panics with this value,
138 // the panic will be recovered and the inner error will be returned from
139 // Builder.Bytes.
140 type BuildErrorscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/BuildError# struct {
141 Errscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/BuildError#Err. error
142 }
143
144 // AddUint8LengthPrefixed adds a 8-bit length-prefixed byte sequence.
145 func (b *Builderscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/Builder#) AddUint8LengthPrefixedscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/Builder#AddUint8LengthPrefixed().(f BuilderContinuationscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/BuilderContinuation#) {
146 b.addLengthPrefixedscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/Builder#addLengthPrefixed().(1, false, f)
147 }
148
149 // AddUint16LengthPrefixed adds a big-endian, 16-bit length-prefixed byte sequence.
150 func (b *Builderscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/Builder#) AddUint16LengthPrefixedscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/Builder#AddUint16LengthPrefixed().(f BuilderContinuationscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/BuilderContinuation#) {
151 b.addLengthPrefixedscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/Builder#addLengthPrefixed().(2, false, f)
152 }
153
154 // AddUint24LengthPrefixed adds a big-endian, 24-bit length-prefixed byte sequence.
155 func (b *Builderscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/Builder#) AddUint24LengthPrefixedscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/Builder#AddUint24LengthPrefixed().(f BuilderContinuationscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/BuilderContinuation#) {
156 b.addLengthPrefixedscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/Builder#addLengthPrefixed().(3, false, f)
157 }
158
159 // AddUint32LengthPrefixed adds a big-endian, 32-bit length-prefixed byte sequence.
160 func (b *Builderscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/Builder#) AddUint32LengthPrefixedscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/Builder#AddUint32LengthPrefixed().(f BuilderContinuationscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/BuilderContinuation#) {
161 b.addLengthPrefixedscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/Builder#addLengthPrefixed().(4, false, f)
162 }
163
164 func (b *Builderscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/Builder#) callContinuationscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/Builder#callContinuation().(f BuilderContinuationscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/BuilderContinuation#, arg *Builderscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/Builder#) {
165 if !*b.inContinuationscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/Builder#inContinuation. {
166 *b.inContinuationscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/Builder#inContinuation. = true
167
168 defer func() {
169 *b.inContinuationscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/Builder#inContinuation. = false
170
171 r := recover()
172 if r == nil {
173 return
174 }
175
176 if buildError, ok := r.(BuildErrorscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/BuildError#); ok {
177 b.errscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/Builder#err. = buildError.Errscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/BuildError#Err.
178 } else {
179 panic(r)
180 }
181 }()
182 }
183
184 f(arg)
185 }
186
187 func (b *Builderscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/Builder#) addLengthPrefixedscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/Builder#addLengthPrefixed().(lenLen int, isASN1 bool, f BuilderContinuationscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/BuilderContinuation#) {
188 // Subsequent writes can be ignored if the builder has encountered an error.
189 if b.errscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/Builder#err. != nil {
190 return
191 }
192
193 offset := len(b.resultscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/Builder#result.)
194 b.addscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/Builder#add().(make([]byte, lenLen)...)
195
196 if b.inContinuationscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/Builder#inContinuation. == nil {
197 b.inContinuationscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/Builder#inContinuation. = new(bool)
198 }
199
200 b.childscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/Builder#child. = &Builderscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/Builder#{
201 resultscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/Builder#result.: b.resultscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/Builder#result.,
202 fixedSizescip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/Builder#fixedSize.: b.fixedSizescip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/Builder#fixedSize.,
203 offsetscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/Builder#offset.: offset,
204 pendingLenLenscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/Builder#pendingLenLen.: lenLen,
205 pendingIsASN1scip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/Builder#pendingIsASN1.: isASN1,
206 inContinuationscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/Builder#inContinuation.: b.inContinuationscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/Builder#inContinuation.,
207 }
208
209 b.callContinuationscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/Builder#callContinuation().(f, b.childscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/Builder#child.)
210 b.flushChildscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/Builder#flushChild().()
211 if b.childscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/Builder#child. != nil {
212 panic("cryptobyte: internal error")
213 }
214 }
215
216 func (b *Builderscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/Builder#) flushChildscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/Builder#flushChild().() {
217 if b.childscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/Builder#child. == nil {
218 return
219 }
220 b.childscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/Builder#child..flushChildscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/Builder#flushChild().()
221 child := b.childscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/Builder#child.
222 b.childscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/Builder#child. = nil
223
224 if child.errscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/Builder#err. != nil {
225 b.errscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/Builder#err. = child.errscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/Builder#err.
226 return
227 }
228
229 length := len(child.resultscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/Builder#result.) - child.pendingLenLenscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/Builder#pendingLenLen. - child.offsetscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/Builder#offset.
230
231 if length < 0 {
232 panic("cryptobyte: internal error") // result unexpectedly shrunk
233 }
234
235 if child.pendingIsASN1scip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/Builder#pendingIsASN1. {
236 // For ASN.1, we reserved a single byte for the length. If that turned out
237 // to be incorrect, we have to move the contents along in order to make
238 // space.
239 if child.pendingLenLenscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/Builder#pendingLenLen. != 1 {
240 panic("cryptobyte: internal error")
241 }
242 var lenLen, lenByte uint8
243 if int64(length) > 0xfffffffe {
244 b.errscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/Builder#err. = errorsscip-go gomod github.com/golang/go/src go1.14 errors/.Newscip-go gomod github.com/golang/go/src go1.14 errors/New().("pending ASN.1 child too long")
245 return
246 } else if length > 0xffffff {
247 lenLen = 5
248 lenByte = 0x80 | 4
249 } else if length > 0xffff {
250 lenLen = 4
251 lenByte = 0x80 | 3
252 } else if length > 0xff {
253 lenLen = 3
254 lenByte = 0x80 | 2
255 } else if length > 0x7f {
256 lenLen = 2
257 lenByte = 0x80 | 1
258 } else {
259 lenLen = 1
260 lenByte = uint8(length)
261 length = 0
262 }
263
264 // Insert the initial length byte, make space for successive length bytes,
265 // and adjust the offset.
266 child.resultscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/Builder#result.[child.offsetscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/Builder#offset.] = lenByte
267 extraBytes := int(lenLen - 1)
268 if extraBytes != 0 {
269 child.addscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/Builder#add().(make([]byte, extraBytes)...)
270 childStart := child.offsetscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/Builder#offset. + child.pendingLenLenscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/Builder#pendingLenLen.
271 copy(child.resultscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/Builder#result.[childStart+extraBytes:], child.resultscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/Builder#result.[childStart:])
272 }
273 child.offsetscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/Builder#offset.++
274 child.pendingLenLenscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/Builder#pendingLenLen. = extraBytes
275 }
276
277 l := length
278 for i := child.pendingLenLenscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/Builder#pendingLenLen. - 1; i >= 0; i-- {
279 child.resultscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/Builder#result.[child.offsetscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/Builder#offset.+i] = uint8(l)
280 l >>= 8
281 }
282 if l != 0 {
283 b.errscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/Builder#err. = fmtscip-go gomod github.com/golang/go/src go1.14 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.14 fmt/Errorf().("cryptobyte: pending child length %d exceeds %d-byte length prefix", length, child.pendingLenLenscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/Builder#pendingLenLen.)
284 return
285 }
286
287 if b.fixedSizescip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/Builder#fixedSize. && &b.resultscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/Builder#result.[0] != &child.resultscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/Builder#result.[0] {
288 panic("cryptobyte: BuilderContinuation reallocated a fixed-size buffer")
289 }
290
291 b.resultscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/Builder#result. = child.resultscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/Builder#result.
292 }
293
294 func (b *Builderscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/Builder#) addscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/Builder#add().(bytes ...byte) {
295 if b.errscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/Builder#err. != nil {
296 return
297 }
298 if b.childscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/Builder#child. != nil {
299 panic("cryptobyte: attempted write while child is pending")
300 }
301 if len(b.resultscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/Builder#result.)+len(bytes) < len(bytes) {
302 b.errscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/Builder#err. = errorsscip-go gomod github.com/golang/go/src go1.14 errors/.Newscip-go gomod github.com/golang/go/src go1.14 errors/New().("cryptobyte: length overflow")
303 }
304 if b.fixedSizescip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/Builder#fixedSize. && len(b.resultscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/Builder#result.)+len(bytes) > cap(b.resultscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/Builder#result.) {
305 b.errscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/Builder#err. = errorsscip-go gomod github.com/golang/go/src go1.14 errors/.Newscip-go gomod github.com/golang/go/src go1.14 errors/New().("cryptobyte: Builder is exceeding its fixed-size buffer")
306 return
307 }
308 b.resultscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/Builder#result. = append(b.resultscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/Builder#result., bytes...)
309 }
310
311 // Unwrite rolls back non-negative n bytes written directly to the Builder.
312 // An attempt by a child builder passed to a continuation to unwrite bytes
313 // from its parent will panic.
314 func (b *Builderscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/Builder#) Unwritescip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/Builder#Unwrite().(n int) {
315 if b.errscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/Builder#err. != nil {
316 return
317 }
318 if b.childscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/Builder#child. != nil {
319 panic("cryptobyte: attempted unwrite while child is pending")
320 }
321 length := len(b.resultscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/Builder#result.) - b.pendingLenLenscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/Builder#pendingLenLen. - b.offsetscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/Builder#offset.
322 if length < 0 {
323 panic("cryptobyte: internal error")
324 }
325 if n < 0 {
326 panic("cryptobyte: attempted to unwrite negative number of bytes")
327 }
328 if n > length {
329 panic("cryptobyte: attempted to unwrite more than was written")
330 }
331 b.resultscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/Builder#result. = b.resultscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/Builder#result.[:len(b.resultscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/Builder#result.)-n]
332 }
333
334 // A MarshalingValue marshals itself into a Builder.
335 type MarshalingValuescip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/MarshalingValue# interface {
336 // Marshal is called by Builder.AddValue. It receives a pointer to a builder
337 // to marshal itself into. It may return an error that occurred during
338 // marshaling, such as unset or invalid values.
339 Marshalscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/MarshalingValue#Marshal.(b *Builderscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/Builder#) error
340 }
341
342 // AddValue calls Marshal on v, passing a pointer to the builder to append to.
343 // If Marshal returns an error, it is set on the Builder so that subsequent
344 // appends don't have an effect.
345 func (b *Builderscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/Builder#) AddValuescip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/Builder#AddValue().(v MarshalingValuescip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/MarshalingValue#) {
346 err := v.Marshalscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/MarshalingValue#Marshal.(b)
347 if err != nil {
348 b.errscip-go gomod github.com/smallstep/pkcs7 . `github.com/smallstep/pkcs7/internal/cryptobyte`/Builder#err. = err
349 }
350 }