Documentation ¶
Overview ¶
Package cbor provides helpers for encoding and decoding canonical CBOR.
Using this package will produce canonical encodings which can be used in cryptographic contexts like signing as the same message is guaranteed to always have the same serialization.
Index ¶
- Variables
- func FixSliceForSerde(b []byte) []byte
- func GetVersion(data []byte) (uint16, error)
- func Marshal(src interface{}) []byte
- func MustUnmarshal(data []byte, dst interface{})
- func NewDecoder(r io.Reader) *cbor.Decoder
- func NewEncoder(w io.Writer) *cbor.Encoder
- func Unmarshal(data []byte, dst interface{}) error
- func UnmarshalTrusted(data []byte, dst interface{}) error
- type MessageCodec
- type MessageReader
- type MessageWriter
- type RawMessage
- type Versioned
Constants ¶
This section is empty.
Variables ¶
var ( // ErrInvalidVersion is the error returned when a versioned // serialized blob is either missing, or has an invalid version. ErrInvalidVersion = errors.New("cbor: missing or invalid version") )
Functions ¶
func FixSliceForSerde ¶
FixSliceForSerde will convert `nil` to `[]byte` to work around serde brain damage.
func GetVersion ¶
GetVersion returns the version of a versioned serializable data structure, if any.
func Marshal ¶
func Marshal(src interface{}) []byte
Marshal serializes a given type into a CBOR byte vector.
func MustUnmarshal ¶
func MustUnmarshal(data []byte, dst interface{})
MustUnmarshal deserializes a CBOR byte vector into a given type. Panics if unmarshal fails.
func UnmarshalTrusted ¶
UnmarshalTrusted deserializes a CBOR byte vector into a given type.
This method MUST ONLY BE USED FOR TRUSTED INPUTS as it relaxes some decoding restrictions.
Types ¶
type MessageCodec ¶
type MessageCodec struct { MessageReader MessageWriter }
MessageCodec is a length-prefixed Message encoder/decoder.
func NewMessageCodec ¶
func NewMessageCodec(rw io.ReadWriter, module string) *MessageCodec
NewMessageCodec constructs a new Message encoder/decoder.
type MessageReader ¶
type MessageReader struct {
// contains filtered or unexported fields
}
MessageReader is a reader wrapper that decodes CBOR-encoded Message structures.
func (*MessageReader) Read ¶
func (c *MessageReader) Read(msg interface{}) error
Read deserializes a single CBOR-encoded Message from the underlying reader.
type MessageWriter ¶
type MessageWriter struct {
// contains filtered or unexported fields
}
MessageWriter is a writer wrapper that encodes Messages structures to CBOR.
func (*MessageWriter) Write ¶
func (c *MessageWriter) Write(msg interface{}) error
Write serializes a single Message to CBOR and writes it to the underlying writer.
type RawMessage ¶
type RawMessage = cbor.RawMessage
RawMessage is a raw encoded CBOR value. It implements Marshaler and Unmarshaler interfaces and can be used to delay CBOR decoding or precompute a CBOR encoding.