Source File
builder.go
Belonging Package
vendor/golang.org/x/crypto/cryptobyte
package cryptobyte
import (
)
type BuilderContinuation func(child *Builder)
type BuildError struct {
Err error
}
func ( *Builder) ( BuilderContinuation) {
.addLengthPrefixed(1, false, )
}
func ( *Builder) ( BuilderContinuation) {
.addLengthPrefixed(2, false, )
}
func ( *Builder) ( BuilderContinuation) {
.addLengthPrefixed(3, false, )
}
func ( *Builder) ( BuilderContinuation) {
.addLengthPrefixed(4, false, )
}
func ( *Builder) ( BuilderContinuation, *Builder) {
if !*.inContinuation {
*.inContinuation = true
defer func() {
*.inContinuation = false
:= recover()
if == nil {
return
}
if , := .(BuildError); {
.err = .Err
} else {
panic()
}
}()
}
()
}
if .err != nil {
return
}
:= len(.result)
.add(make([]byte, )...)
if .inContinuation == nil {
.inContinuation = new(bool)
}
.child = &Builder{
result: .result,
fixedSize: .fixedSize,
offset: ,
pendingLenLen: ,
pendingIsASN1: ,
inContinuation: .inContinuation,
}
.callContinuation(, .child)
.flushChild()
if .child != nil {
panic("cryptobyte: internal error")
}
}
func ( *Builder) () {
if .child == nil {
return
}
.child.()
:= .child
.child = nil
if .err != nil {
.err = .err
return
}
:= len(.result) - .pendingLenLen - .offset
if < 0 {
panic("cryptobyte: internal error") // result unexpectedly shrunk
}
if .pendingLenLen != 1 {
panic("cryptobyte: internal error")
}
var , uint8
if int64() > 0xfffffffe {
.err = errors.New("pending ASN.1 child too long")
return
} else if > 0xffffff {
= 5
= 0x80 | 4
} else if > 0xffff {
= 4
= 0x80 | 3
} else if > 0xff {
= 3
= 0x80 | 2
} else if > 0x7f {
= 2
= 0x80 | 1
} else {
= 1
= uint8()
= 0
}
.result[.offset] =
:= int( - 1)
if != 0 {
.add(make([]byte, )...)
:= .offset + .pendingLenLen
copy(.result[+:], .result[:])
}
.offset++
.pendingLenLen =
}
:=
for := .pendingLenLen - 1; >= 0; -- {
.result[.offset+] = uint8()
>>= 8
}
if != 0 {
.err = fmt.Errorf("cryptobyte: pending child length %d exceeds %d-byte length prefix", , .pendingLenLen)
return
}
if .fixedSize && &.result[0] != &.result[0] {
panic("cryptobyte: BuilderContinuation reallocated a fixed-size buffer")
}
.result = .result
}
func ( *Builder) ( ...byte) {
if .err != nil {
return
}
if .child != nil {
panic("cryptobyte: attempted write while child is pending")
}
if len(.result)+len() < len() {
.err = errors.New("cryptobyte: length overflow")
}
if .fixedSize && len(.result)+len() > cap(.result) {
.err = errors.New("cryptobyte: Builder is exceeding its fixed-size buffer")
return
}
.result = append(.result, ...)
}
func ( *Builder) ( int) {
if .err != nil {
return
}
if .child != nil {
panic("cryptobyte: attempted unwrite while child is pending")
}
:= len(.result) - .pendingLenLen - .offset
if < 0 {
panic("cryptobyte: internal error")
}
if > {
panic("cryptobyte: attempted to unwrite more than was written")
}
.result = .result[:len(.result)-]
}
func ( *Builder) ( MarshalingValue) {
:= .Marshal()
if != nil {
.err =
}
![]() |
The pages are generated with Golds v0.3.2-preview. (GOOS=darwin GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds. |