Source File
opaque.go
Belonging Package
golang.org/x/crypto/openpgp/packet
package packet
import (
)
func ( *OpaquePacket) ( io.Writer) ( error) {
= serializeHeader(, packetType(.Tag), len(.Contents))
if == nil {
_, = .Write(.Contents)
}
return
}
type OpaqueReader struct {
r io.Reader
}
func ( io.Reader) *OpaqueReader {
return &OpaqueReader{r: }
}
func ( *OpaqueReader) () ( *OpaquePacket, error) {
, , , := readHeader(.r)
if != nil {
return
}
= &OpaquePacket{Tag: uint8(), Reason: }
= .parse()
if != nil {
consumeAll()
}
return
}
type OpaqueSubpacket struct {
SubType uint8
Contents []byte
}
func ( []byte) ( []*OpaqueSubpacket, error) {
var (
int
*OpaqueSubpacket
)
for len() > 0 {
, , = nextSubpacket()
if != nil {
break
}
= append(, )
= [+len(.Contents):]
}
return
}
var uint32
if len() < 1 {
goto
}
= &OpaqueSubpacket{}
switch {
case [0] < 192:
= 2 // 1 length byte, 1 subtype byte
if len() < {
goto
}
= uint32([0])
= [1:]
case [0] < 255:
= 3 // 2 length bytes, 1 subtype
if len() < {
goto
}
= uint32([0]-192)<<8 + uint32([1]) + 192
= [2:]
default:
= 6 // 5 length bytes, 1 subtype
if len() < {
goto
}
= uint32([1])<<24 |
uint32([2])<<16 |
uint32([3])<<8 |
uint32([4])
= [5:]
}
if > uint32(len()) || == 0 {
goto
}
.SubType = [0]
.Contents = [1:]
return
:
= errors.StructuralError("subpacket truncated")
return
}
func ( *OpaqueSubpacket) ( io.Writer) ( error) {
:= make([]byte, 6)
:= serializeSubpacketLength(, len(.Contents)+1)
[] = .SubType
if _, = .Write([:+1]); != nil {
return
}
_, = .Write(.Contents)
return
![]() |
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. |