tlv

package
v0.0.0-...-dbd5041 Latest Latest
Warning

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

Go to latest
Published: Jan 8, 2015 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Packet Types
	InterestType uint64 = 0x05
	DataType     uint64 = 0x06

	// Common Fields
	NameType                          uint64 = 0x07
	NameComponentType                 uint64 = 0x08
	ImplicitSha256DigestComponentType uint64 = 0x01

	// Interest Packet
	SelectorsType        uint64 = 0x09
	NonceType            uint64 = 0x0A
	ScopeType            uint64 = 0x0B
	InterestLifetimeType uint64 = 0x0C

	// Interest/Selectors
	MinSuffixComponentsType       uint64 = 0x0D
	MaxSuffixComponentsType       uint64 = 0x0E
	PublisherPublicKeyLocatorType uint64 = 0x0F
	ExcludeType                   uint64 = 0x10
	ChildSelectorType             uint64 = 0x11
	MustBeFreshType               uint64 = 0x12
	AnyType                       uint64 = 0x13

	// Data Packet
	MetaInfoType       uint64 = 0x14
	ContentType        uint64 = 0x15
	SignatureInfoType  uint64 = 0x16
	SignatureValueType uint64 = 0x17

	// Data/MetaInfo
	ContentTypeType     uint64 = 0x18
	FreshnessPeriodType uint64 = 0x19
	FinalBlockIdType    uint64 = 0x1A

	// Data/Signature
	SignatureTypeType uint64 = 0x1B
	KeyLocatorType    uint64 = 0x1C
	KeyDigestType     uint64 = 0x1D
)

Variables

View Source
var Any = tlv(AnyType, empty)

Any ::= ANY-TYPE TLV-LENGTH(=0)

View Source
var Byte = parserFunc(func(input []byte) (interface{}, []byte, error) {
	if len(input) <= 0 {
		return nil, input, io.ErrUnexpectedEOF
	}
	return input[0], input[1:], nil
})
View Source
var Bytes bytesParserType = func(n int) parser {
	return bytesWithLengthParser(n)
}
View Source
var ChildSelector = tlv(ChildSelectorType, nonNegativeInteger)

ChildSelector ::= CHILD-SELECTOR-TYPE TLV-LENGTH

nonNegativeInteger
View Source
var Content = tlv(ContentType, Bytes)

Content ::= CONTENT-TYPE TLV-LENGTH BYTE*

View Source
var ContentTypeParser = tlv(ContentTypeType, nonNegativeInteger)

ContentType ::= CONTENT-TYPE-TYPE TLV-LENGTH

nonNegativeInteger

Data ::= DATA-TLV TLV-LENGTH

Name
MetaInfo
Content
Signature
View Source
var DigestSha256SignatureInfo = tlv(SignatureInfoType,
	tlv(SignatureTypeType, exactly(0)),
)

SignatureInfo ::= SIGNATURE-INFO-TYPE TLV-LENGTH(=3)

SIGNATURE-TYPE-TYPE TLV-LENGTH(=1) 0
View Source
var DigestSha256SignatureValue = tlv(SignatureValueType,
	Bytes(32),
)

SignatureValue ::= SIGNATURE-VALUE-TYPE TLV-LENGTH(=32)

BYTE+(=SHA256{Name, MetaInfo, Content, SignatureInfo})
View Source
var ErrUnexpectexUintTLVLengthValue = errors.New("Unexpected UintTLV length value")
View Source
var Exclude = tlv(ExcludeType, maybe(Any), oneOrMore(NameComponent, maybe(Any)))

Exclude ::= EXCLUDE-TYPE TLV-LENGTH Any? (NameComponent (Any)?)+

View Source
var FinalBlockID = tlv(FinalBlockIdType, NameComponent)

FinalBlockId ::= FINAL-BLOCK-ID-TLV TLV-LENGTH

NameComponent
View Source
var FreshnessPeriod = tlv(FreshnessPeriodType, nonNegativeInteger)

FreshnessPeriod ::= FRESHNESS-PERIOD-TLV TLV-LENGTH

nonNegativeInteger
View Source
var GenericNameComponent = tlv(NameComponentType, Bytes)

GenericNameComponent ::= NAME-COMPONENT-TYPE TLV-LENGTH BYTE*

View Source
var ImplicitSha256DigestComponent = tlv(ImplicitSha256DigestComponentType, Bytes(32))

ImplicitSha256DigestComponent ::= IMPLICIT-SHA256-DIGEST-COMPONENT-TYPE TLV-LENGTH(=32)

BYTE{32}
View Source
var Interest = tlv(InterestType,
	Name,
	maybe(Selectors),
	Nonce,
	maybe(Scope),
	maybe(InterestLifetime),
)

Interest ::= INTEREST-TYPE TLV-LENGTH

Name
Selectors?
Nonce
Scope?
InterestLifetime?
View Source
var InterestLifetime = tlv(InterestLifetimeType, nonNegativeInteger)

InterestLifetime ::= INTEREST-LIFETIME-TYPE TLV-LENGTH nonNegativeInteger

View Source
var KeyDigest = tlv(KeyDigestType, Bytes)

KeyDigest ::= KEY-DIGEST-TYPE TLV-LENGTH BYTE+

View Source
var KeyLocator = tlv(KeyLocatorType, or(Name, KeyDigest))

KeyLocator ::= KEY-LOCATOR-TYPE TLV-LENGTH (Name | KeyDigest)

View Source
var MaxSuffixComponents = tlv(MaxSuffixComponentsType, nonNegativeInteger)

MaxSuffixComponents ::= MAX-SUFFIX-COMPONENTS-TYPE TLV-LENGTH

nonNegativeInteger
View Source
var MetaInfo = tlv(MetaInfoType,
	maybe(ContentTypeParser),
	maybe(FreshnessPeriod),
	maybe(FinalBlockID),
)

MetaInfo ::= META-INFO-TYPE TLV-LENGTH

ContentType?
FreshnessPeriod?
FinalBlockId?
View Source
var MinSuffixComponents = tlv(MinSuffixComponentsType, nonNegativeInteger)

MinSuffixComponents ::= MIN-SUFFIX-COMPONENTS-TYPE TLV-LENGTH

nonNegativeInteger
View Source
var MustBeFresh = tlv(MustBeFreshType, empty)

MustBeFresh ::= MUST-BE-FRESH-TYPE TLV-LENGTH(=0)

View Source
var Name = tlv(NameType, zeroOrMore(NameComponent))

Name ::= NAME-TYPE TLV-LENGTH NameComponent*

NameComponent ::= GenericNameComponent | ImplicitSha256DigestComponent

View Source
var Nonce = tlv(NonceType, Bytes(4))

Nonce ::= NONCE-TYPE TLV-LENGTH(=4) BYTE{4}

View Source
var PublisherPublicKeyLocator = KeyLocator

PublisherPublicKeyLocator ::= KeyLocator

View Source
var Scope = tlv(ScopeType, nonNegativeInteger)

Scope ::= SCOPE-TYPE TLV-LENGTH nonNegativeInteger

View Source
var Selectors = tlv(SelectorsType,
	maybe(MinSuffixComponents),
	maybe(MaxSuffixComponents),
	maybe(PublisherPublicKeyLocator),
	maybe(Exclude),
	maybe(ChildSelector),
	maybe(MustBeFresh),
)

Selectors ::= SELECTORS-TYPE TLV-LENGTH

MinSuffixComponents?
MaxSuffixComponents?
PublisherPublicKeyLocator?
Exclude?
ChildSelector?
MustBeFresh?

SignatureValue ::= SIGNATURE-VALUE-TYPE TLV-LENGTH

... (SignatureType-specific TLVs and
BYTE+
View Source
var SignatureSha256WithEcdsaInfo = tlv(SignatureInfoType,
	tlv(SignatureTypeType, exactly(3)),
	KeyLocator,
)

SignatureInfo ::= SIGNATURE-INFO-TYPE TLV-LENGTH

SIGNATURE-TYPE-TYPE TLV-LENGTH(=1) 3
KeyLocator
View Source
var SignatureSha256WithEcdsaValue = tlv(SignatureValueType,
	Bytes,
)

SignatureValue ::= SIGNATURE-VALUE-TYPE TLV-LENGTH

BYTE+(=ECDSA over SHA256{Name, MetaInfo, Content, SignatureInfo})
View Source
var SignatureSha256WithRsaInfo = tlv(SignatureInfoType,
	tlv(SignatureTypeType, exactly(1)),
	KeyLocator,
)

SignatureInfo ::= SIGNATURE-INFO-TYPE TLV-LENGTH

SIGNATURE-TYPE-TYPE TLV-LENGTH(=1) 1
KeyLocator
View Source
var SignatureSha256WithRsaValue = tlv(SignatureValueType,
	Bytes,
)

SignatureValue ::= SIGNATURE-VALUE-TYPE TLV-LENGTH

BYTE+(=RSA over SHA256{Name, MetaInfo, Content, SignatureInfo})
View Source
var SignatureType = tlv(SignatureTypeType, nonNegativeInteger)

SignatureType ::= SIGNATURE-TYPE-TYPE TLV-LENGTH

nonNegativeInteger

Functions

func BytesReader

func BytesReader() valueReader

func ChildrenReader

func ChildrenReader() valueReader

func IsValue

func IsValue(v interface{}) bool

IsValue reports whether v is a valid Value parameter type.

func NewDecoder

func NewDecoder(r io.Reader) encoding.Decoder

func NewEncoder

func NewEncoder(w io.Writer) encoding.Encoder

func ReadNumber

func ReadNumber(r io.Reader) (uint64, int64, error)

func ReadUint

func ReadUint(r io.Reader) (uint64, int64, error)

func ReadValue

func ReadValue(r io.Reader, t uint64) (interface{}, int64, error)

func UintReader

func UintReader() valueReader

func WriteNumber

func WriteNumber(w io.Writer, num uint64) (int64, error)

func WriteUint

func WriteUint(w io.Writer, v uint64) (n int64, err error)

Types

type ByteTLV

type ByteTLV struct {
	T uint64
	V []byte
}

func (ByteTLV) MarshalBinary

func (t ByteTLV) MarshalBinary() ([]byte, error)

func (ByteTLV) Type

func (t ByteTLV) Type() uint64

func (ByteTLV) WriteTo

func (t ByteTLV) WriteTo(w io.Writer) (n int64, err error)

type BytesValue

type BytesValue []TLV

func (BytesValue) ReadFrom

func (v BytesValue) ReadFrom(r io.Reader) (int64, error)

func (BytesValue) WriteTo

func (v BytesValue) WriteTo(w io.Writer) (int64, error)

type ChildrenValue

type ChildrenValue []TLV

func (ChildrenValue) ReadFrom

func (v ChildrenValue) ReadFrom(r io.Reader) (int64, error)

func (ChildrenValue) WriteTo

func (v ChildrenValue) WriteTo(w io.Writer) (int64, error)

type Decoder

type Decoder struct {
	// contains filtered or unexported fields
}

func (*Decoder) Decode

func (r *Decoder) Decode() (interface{}, error)

type Encoder

type Encoder struct {
	// contains filtered or unexported fields
}

func (*Encoder) Encode

func (w *Encoder) Encode(p interface{}) error

type GenericTLV

type GenericTLV struct {
	T uint64
	V interface{}
}

func (GenericTLV) Bytes

func (t GenericTLV) Bytes() []byte

func (GenericTLV) Children

func (t GenericTLV) Children() []TLV

func (GenericTLV) MarshalBinary

func (t GenericTLV) MarshalBinary() ([]byte, error)

func (GenericTLV) Type

func (t GenericTLV) Type() uint64

func (GenericTLV) Uint

func (t GenericTLV) Uint() uint64

func (GenericTLV) WriteTo

func (t GenericTLV) WriteTo(w io.Writer) (n int64, err error)

type Marshaler

type Marshaler interface {
	MarshalTLV() (TLV, error)
}

type ParentTLV

type ParentTLV struct {
	T uint64
	V []TLV
}

func (ParentTLV) MarshalBinary

func (t ParentTLV) MarshalBinary() ([]byte, error)

func (ParentTLV) Type

func (t ParentTLV) Type() uint64

func (ParentTLV) WriteTo

func (t ParentTLV) WriteTo(w io.Writer) (n int64, err error)

type TLV

type TLV interface {
	Type() uint64
	io.WriterTo
	encoding.BinaryMarshaler
}

type UintTLV

type UintTLV struct {
	T uint64
	V uint64
}

func (UintTLV) MarshalBinary

func (t UintTLV) MarshalBinary() ([]byte, error)

func (UintTLV) Type

func (t UintTLV) Type() uint64

func (UintTLV) WriteTo

func (t UintTLV) WriteTo(w io.Writer) (int64, error)

type UintValue

type UintValue []TLV

func (UintValue) ReadFrom

func (v UintValue) ReadFrom(r io.Reader) (int64, error)

func (UintValue) WriteTo

func (v UintValue) WriteTo(w io.Writer) (int64, error)

type UnsupportedTypeError

type UnsupportedTypeError struct {
	Type reflect.Type
}

func (UnsupportedTypeError) Error

func (e UnsupportedTypeError) Error() string

type Value

type Value interface{}

Value is a value that can be stored in a TLV. It is either nil or an instance of one of these types:

uint64
[]byte
[]TLV
string

Jump to

Keyboard shortcuts

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