Documentation ¶
Index ¶
- Constants
- Variables
- func IsAlphabet(r rune) bool
- type Buffer
- type BufferReader
- func (r *BufferReader) Delegate(l int) ParseReader
- func (r *BufferReader) Length() int
- func (r *BufferReader) Pos() int
- func (r *BufferReader) Range(start, end int) Wire
- func (r *BufferReader) Read(b []byte) (int, error)
- func (r *BufferReader) ReadBuf(l int) (Buffer, error)
- func (r *BufferReader) ReadByte() (byte, error)
- func (r *BufferReader) ReadWire(l int) (Wire, error)
- func (r *BufferReader) Seek(offset int64, whence int) (int64, error)
- func (r *BufferReader) Skip(n int) error
- func (r *BufferReader) UnreadByte() error
- type Component
- func ComponentFromBytes(buf []byte) (Component, error)
- func ComponentFromStr(s string) (Component, error)
- func NewByteOffsetComponent(off uint64) Component
- func NewBytesComponent(typ TLNum, val []byte) Component
- func NewNumberComponent(typ TLNum, val uint64) Component
- func NewSegmentComponent(seg uint64) Component
- func NewSequenceNumComponent(seq uint64) Component
- func NewStringComponent(typ TLNum, val string) Component
- func NewTimestampComponent(t uint64) Component
- func NewVersionComponent(v uint64) Component
- func ParseComponent(buf Buffer) (Component, int)
- func ReadComponent(r ParseReader) (Component, error)
- func (c Component) Bytes() []byte
- func (c Component) CanonicalString() string
- func (c Component) Clone() Component
- func (c Component) Compare(rhs ComponentPattern) int
- func (c Component) ComponentPatternTrait() ComponentPattern
- func (c Component) EncodeInto(buf Buffer) int
- func (c Component) EncodingLength() int
- func (c Component) Equal(rhs ComponentPattern) bool
- func (c Component) FromMatching(m Matching) (*Component, error)
- func (c Component) Hash() uint64
- func (c Component) HashInto(h hash.Hash)
- func (c Component) IsMatch(value Component) bool
- func (c Component) Length() TLNum
- func (Component) Match(value Component, m Matching)
- func (c Component) NumberVal() uint64
- func (c Component) String() string
- type ComponentPattern
- type ErrFailToParse
- type ErrFormat
- type ErrIncompatibleType
- type ErrNotFound
- type ErrSkipRequired
- type ErrUnexpected
- type ErrUnrecognizedField
- type Matching
- type Name
- func (n Name) Bytes() []byte
- func (n Name) Clone() Name
- func (n Name) Compare(rhs Name) int
- func (n Name) EncodeInto(buf Buffer) int
- func (n Name) EncodingLength() int
- func (n Name) Equal(rhs Name) bool
- func (n Name) Hash() uint64
- func (n Name) IsPrefix(rhs Name) bool
- func (n Name) PrefixHash() []uint64
- func (n Name) String() string
- func (n Name) ToFullName(rawData Wire) Name
- type NamePattern
- type Nat
- type ParseReader
- type Pattern
- func (p Pattern) CanonicalString() string
- func (p Pattern) Compare(rhs ComponentPattern) int
- func (p Pattern) ComponentPatternTrait() ComponentPattern
- func (p Pattern) Equal(rhs ComponentPattern) bool
- func (p Pattern) FromMatching(m Matching) (*Component, error)
- func (p Pattern) IsMatch(value Component) bool
- func (p Pattern) Match(value Component, m Matching)
- func (p Pattern) String() string
- type PlaceHolder
- type TLNum
- type Wire
- type WireReader
- func (r *WireReader) Delegate(l int) ParseReader
- func (r *WireReader) Length() int
- func (r *WireReader) Pos() int
- func (r *WireReader) Range(start, end int) Wire
- func (r *WireReader) Read(b []byte) (int, error)
- func (r *WireReader) ReadBuf(l int) (Buffer, error)
- func (r *WireReader) ReadByte() (byte, error)
- func (r *WireReader) ReadWire(l int) (Wire, error)
- func (r *WireReader) Skip(n int) error
- func (r *WireReader) UnreadByte() error
Constants ¶
const ( ParamShaNameConvention = "params-sha256" DigestShaNameConvention = "sha256digest" )
Variables ¶
var ErrBufferOverflow = errors.New("buffer overflow when parsing. One of the TLV Length is wrong")
var ErrIncorrectDigest = errors.New("the sha256 digest is missing or incorrect")
Functions ¶
func IsAlphabet ¶ added in v0.0.2
Types ¶
type Buffer ¶
type Buffer []byte
Buffer is a buffer of bytes
func ShrinkLength ¶
Shrink length reduce the L by `shrink“ in a TLV encoded buffer `buf`
Precondition: `buf` starts with proper Type and Length numbers. Length > `shrink`. May crash otherwise.
Returns the new buffer containing reduced TL header. May start from the middle of original buffer, but always goes to the end.
type BufferReader ¶
type BufferReader struct {
// contains filtered or unexported fields
}
func NewBufferReader ¶
func NewBufferReader(buf Buffer) *BufferReader
func (*BufferReader) Delegate ¶
func (r *BufferReader) Delegate(l int) ParseReader
func (*BufferReader) Length ¶
func (r *BufferReader) Length() int
func (*BufferReader) Pos ¶
func (r *BufferReader) Pos() int
func (*BufferReader) Range ¶
func (r *BufferReader) Range(start, end int) Wire
func (*BufferReader) ReadByte ¶
func (r *BufferReader) ReadByte() (byte, error)
func (*BufferReader) Skip ¶
func (r *BufferReader) Skip(n int) error
func (*BufferReader) UnreadByte ¶
func (r *BufferReader) UnreadByte() error
type Component ¶
func ComponentFromBytes ¶
func ComponentFromStr ¶
func NewByteOffsetComponent ¶
func NewBytesComponent ¶
func NewNumberComponent ¶
func NewSegmentComponent ¶
func NewSequenceNumComponent ¶
func NewStringComponent ¶
func NewTimestampComponent ¶
func NewVersionComponent ¶
func ParseComponent ¶
func ReadComponent ¶
func ReadComponent(r ParseReader) (Component, error)
func (Component) CanonicalString ¶ added in v0.0.2
func (Component) Compare ¶
func (c Component) Compare(rhs ComponentPattern) int
func (Component) ComponentPatternTrait ¶
func (c Component) ComponentPatternTrait() ComponentPattern
func (Component) EncodeInto ¶
func (Component) EncodingLength ¶
func (Component) Equal ¶
func (c Component) Equal(rhs ComponentPattern) bool
type ComponentPattern ¶
type ComponentPattern interface { // ComponentPatternTrait returns the type trait of Component or Pattern // This is used to make ComponentPattern a union type of Component or Pattern // Component | Pattern does not work because we need a mixed list NamePattern ComponentPatternTrait() ComponentPattern // String returns the string of the component, with naming conventions. // Since naming conventions are not standardized, this should not be used for purposes other than logging. // please use CanonicalString() for stable string representation. String() string // CanonicalString returns the string representation of the component without naming conventions. CanonicalString() string // Compare returns an integer comparing two components lexicographically. // It compares the type number first, and then its value. // A component is always less than a pattern. // The result will be 0 if a == b, -1 if a < b, and +1 if a > b. Compare(ComponentPattern) int // Equal returns the two components/patterns are the same. Equal(ComponentPattern) bool // IsMatch returns if the Component value matches with the current component/pattern. IsMatch(value Component) bool // Match matches the current pattern/component with the value, and put the matching into the Matching map. Match(value Component, m Matching) // FromMatching initiates the pattern from the Matching map. FromMatching(m Matching) (*Component, error) }
func ComponentPatternFromStr ¶
func ComponentPatternFromStr(s string) (ComponentPattern, error)
type ErrFailToParse ¶
func (ErrFailToParse) Error ¶
func (e ErrFailToParse) Error() string
func (ErrFailToParse) Unwrap ¶
func (e ErrFailToParse) Unwrap() error
type ErrIncompatibleType ¶
func (ErrIncompatibleType) Error ¶
func (e ErrIncompatibleType) Error() string
type ErrNotFound ¶
type ErrNotFound struct {
Key string
}
func (ErrNotFound) Error ¶
func (e ErrNotFound) Error() string
type ErrSkipRequired ¶
func (ErrSkipRequired) Error ¶
func (e ErrSkipRequired) Error() string
type ErrUnexpected ¶
type ErrUnexpected struct {
Err error
}
func (ErrUnexpected) Error ¶
func (e ErrUnexpected) Error() string
func (ErrUnexpected) Unwrap ¶
func (e ErrUnexpected) Unwrap() error
type ErrUnrecognizedField ¶
type ErrUnrecognizedField struct {
TypeNum TLNum
}
func (ErrUnrecognizedField) Error ¶
func (e ErrUnrecognizedField) Error() string
type Name ¶
type Name []Component
func NameFromBytes ¶
func NameFromStr ¶
func ReadName ¶
func ReadName(r ParseReader) (Name, error)
ReadName reads a Name from a Wire **excluding** the TL prefix.
func (Name) EncodeInto ¶
EncodeInto encodes a Name into a Buffer **excluding** the TL prefix. Please use Bytes() to get the fully encoded name.
func (Name) EncodingLength ¶
EncodingLength computes a Name's length after encoding **excluding** the TL prefix.
func (Name) PrefixHash ¶ added in v0.0.2
PrefixHash returns the hash value of all prefixes of the name ret[n] means the hash of the prefix of length n. ret[0] is the same for all names.
func (Name) ToFullName ¶
type NamePattern ¶
type NamePattern []ComponentPattern
func NamePatternFromStr ¶
func NamePatternFromStr(s string) (NamePattern, error)
func (NamePattern) Compare ¶
func (n NamePattern) Compare(rhs NamePattern) int
func (NamePattern) Equal ¶
func (n NamePattern) Equal(rhs NamePattern) bool
func (NamePattern) FromMatching ¶
func (n NamePattern) FromMatching(m Matching) (Name, error)
func (NamePattern) IsPrefix ¶
func (n NamePattern) IsPrefix(rhs NamePattern) bool
func (NamePattern) Match ¶
func (n NamePattern) Match(name Name, m Matching)
func (NamePattern) String ¶
func (n NamePattern) String() string
type Nat ¶
type Nat uint64
Nat is a TLV natural number
func (Nat) EncodeInto ¶
func (Nat) EncodingLength ¶
type ParseReader ¶
type ParseReader interface { io.Reader io.ByteScanner // ReadWire reads a list of buffers in place without copy. // It always tries to read the required length of bytes. ReadWire(l int) (Wire, error) // ReadBuf reads a continuous buffer, trying to avoid copy. ReadBuf(l int) (Buffer, error) // Range returns a wire that contains the bytes between start and end, without copy. Range(start, end int) Wire // Pos returns the current position in the buffer/wire. Pos() int // Length returns the length of the buffer/wire. Length() int // Skip skips the next n bytes. Skip(n int) error // Delegate returns a new ParseReader that starts from the current position with length l. // The result is equivalent to the following: // // start := r.Pos() // r.Skip(l) // return r.Range(start, r.Pos()) Delegate(l int) ParseReader }
ParseReader is an interface operating on Buffer and Wire
type Pattern ¶
func (Pattern) CanonicalString ¶ added in v0.0.2
func (Pattern) Compare ¶
func (p Pattern) Compare(rhs ComponentPattern) int
func (Pattern) ComponentPatternTrait ¶
func (p Pattern) ComponentPatternTrait() ComponentPattern
func (Pattern) Equal ¶
func (p Pattern) Equal(rhs ComponentPattern) bool
type PlaceHolder ¶
type PlaceHolder struct{}
PlaceHolder is an empty structure that used to give names of procedure arguments.
type TLNum ¶
type TLNum uint64
TLNum is a TLV Type or Length number
const ( TypeInvalidComponent TLNum = 0x00 TypeImplicitSha256DigestComponent TLNum = 0x01 TypeParametersSha256DigestComponent TLNum = 0x02 TypeGenericNameComponent TLNum = 0x08 TypeKeywordNameComponent TLNum = 0x20 TypeSegmentNameComponent TLNum = 0x32 TypeByteOffsetNameComponent TLNum = 0x34 TypeVersionNameComponent TLNum = 0x36 TypeTimestampNameComponent TLNum = 0x38 TypeSequenceNumNameComponent TLNum = 0x3a )
const TypeName TLNum = 0x07
func ParseTLNum ¶
ParseTLNum parses a TLNum from a buffer. It is supposed to be used internally, so panic on index out of bounds.
func ReadTLNum ¶
func ReadTLNum(r io.ByteReader) (val TLNum, err error)
ReadTLNum reads a TLNum from a io.Reader.
func (TLNum) EncodeInto ¶
func (TLNum) EncodingLength ¶
type Wire ¶
type Wire []Buffer
Wire is a collection of Buffer. May be allocated in non-contiguous memory.
type WireReader ¶
type WireReader struct {
// contains filtered or unexported fields
}
WireReader is used for reading from a Wire. It is used when parsing a fragmented packet.
func NewWireReader ¶
func NewWireReader(w Wire) *WireReader
func (*WireReader) Delegate ¶
func (r *WireReader) Delegate(l int) ParseReader
func (*WireReader) Length ¶
func (r *WireReader) Length() int
func (*WireReader) Pos ¶
func (r *WireReader) Pos() int
func (*WireReader) Range ¶
func (r *WireReader) Range(start, end int) Wire
func (*WireReader) ReadByte ¶
func (r *WireReader) ReadByte() (byte, error)
func (*WireReader) Skip ¶
func (r *WireReader) Skip(n int) error
func (*WireReader) UnreadByte ¶
func (r *WireReader) UnreadByte() error