proto

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 27, 2018 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package proto contains mostly auto-generated code for parsing/packing SCION capnp messages, as well as some helper functions to working with capnp in Go simpler.

The helper functions are all contained in cereal.go. They provide a simple interface to read/write any capnp messages that have a Go representation, relying on https://godoc.org/zombiezen.com/go/capnproto2/pogs to do the heavy lifting.

One thing to note is that these helper functions generally only operate on complete capnp messages. If you, for example, want to create an IFID proto, that needs to be nested inside a SCION control message. For example:

// Create new ifid instance
ifid1 := &ifid.IFID{OrigIfID: uint64(ifID)}
// Wrap it in a SCION control message.
cpld1, _ := ctrl.NewPld(ifid1)
// Pack the ctrl message to bytes.
b, _ := PackRoot(cpld1)
// Parse new ctrl message from bytes.
cpld2, _ := ParseFromRaw(b)
// Access the contents (unnamed union).
cont, _ := cpld2.Contents()
// Interface-assertion to IFID type.
ifid2 := cont.(*ifid.IFID)

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func PackRoot

func PackRoot(c Cerealizable) (common.RawBytes, error)

PackRoot creates a complete capnp message for c, and returns it encoded as bytes.

func ParseFromRaw

func ParseFromRaw(c Cerealizable, pType ProtoIdType, b common.RawBytes) error

ParseFromRaw is a utility function, which reads a capnp message from b and parses it into c. It is effectively a composition of ReadRootFromRaw and ParseStruct.

func ParseFromReader

func ParseFromReader(c Cerealizable, pType ProtoIdType, r io.Reader) error

ParseFromReader is a utility function, which reads a capnp message from r and parses it into c. It is effectively a composition of ReadRootFromReader and ParseStruct.

func ParseStruct

func ParseStruct(c Cerealizable, pType ProtoIdType, s capnp.Struct) error

ParseStruct parses a capnp struct into a Cerealizable instance.

func ReadRootFromRaw

func ReadRootFromRaw(b common.RawBytes) (capnp.Struct, error)

ReadRootFromRaw returns the root struct from a capnp message encoded in b.

func ReadRootFromReader

func ReadRootFromReader(r io.Reader) (_ capnp.Struct, err error)

ReadRootFromReader returns the root struct from a capnp message read from r.

func WriteRoot

func WriteRoot(c Cerealizable, b common.RawBytes) (int, error)

WriteRoot creates a complete capnp message for c, and writes it out to b. The int return value is the number of bytes written.

Types

type Cerealizable

type Cerealizable interface {
	fmt.Stringer
	ProtoId() ProtoIdType
}

Cerealizable represents a type which has a corresponding Cap'n Proto (capnp) representation, and supports pogs insertion/extraction.

type ProtoIdType

type ProtoIdType uint64

ProtoIdType represents a capnp struct Id.

func (ProtoIdType) String

func (p ProtoIdType) String() string

type SignS

type SignS struct {
	Timestamp uint32
	Type      SignType
	// Src holds the required metadata to verify the signature. The format is "STRING: METADATA".
	// The prefix consists of "STRING: " and is required to match the regex "^\w+\: ".
	// There are no format restrictions on the metadata.
	Src       common.RawBytes
	Signature common.RawBytes
}

func NewSignS

func NewSignS(type_ SignType, src common.RawBytes) *SignS

func (*SignS) Copy

func (s *SignS) Copy() *SignS

func (*SignS) Pack

func (s *SignS) Pack() common.RawBytes

func (*SignS) ProtoId

func (s *SignS) ProtoId() ProtoIdType

func (*SignS) Sign

func (s *SignS) Sign(key, message common.RawBytes) (common.RawBytes, error)

func (*SignS) SignAndSet

func (s *SignS) SignAndSet(key, message common.RawBytes) error

func (*SignS) String

func (s *SignS) String() string

func (*SignS) Time

func (s *SignS) Time() time.Time

Time returns the timestamp. If the receiver is nil, the zero value is returned.

func (*SignS) Verify

func (s *SignS) Verify(key, message common.RawBytes) error

type SignedBlobS

type SignedBlobS struct {
	Blob common.RawBytes
	Sign *SignS
}

func (*SignedBlobS) Pack

func (sbs *SignedBlobS) Pack() common.RawBytes

func (*SignedBlobS) ProtoId

func (sbs *SignedBlobS) ProtoId() ProtoIdType

func (*SignedBlobS) String

func (sbs *SignedBlobS) String() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL