ttlv

package
v0.0.0-...-7eb09aa Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2021 License: GPL-3.0 Imports: 10 Imported by: 1

Documentation

Overview

cryptctl - Copyright (c) 2017 SUSE Linux GmbH, Germany This source code is licensed under GPL version 3 that can be found in LICENSE file.

cryptctl - Copyright (c) 2017 SUSE Linux GmbH, Germany This source code is licensed under GPL version 3 that can be found in LICENSE file.

cryptctl - Copyright (c) 2017 SUSE Linux GmbH, Germany This source code is licensed under GPL version 3 that can be found in LICENSE file.

Index

Constants

View Source
const (
	TypStruct    = 0x1
	TypInt       = 0x2
	TypLong      = 0x3
	TypeEnum     = 0x5
	TypeText     = 0x7
	TypeBytes    = 0x8
	TypeDateTime = 0x9
	LenTTL       = 3 + 1 + 4 // 3 bytes of tag, 1 byte of type, 4 bytes of length
)

Variables

View Source
var SampleCreateRequest = WiresharkDumpToBytes(`
0000   42 00 78 01 00 00 01 a8 42 00 77 01 00 00 00 80
0010   42 00 69 01 00 00 00 20 42 00 6a 02 00 00 00 04
0020   00 00 00 01 00 00 00 00 42 00 6b 02 00 00 00 04
0030   00 00 00 02 00 00 00 00 42 00 0c 01 00 00 00 40
0040   42 00 23 01 00 00 00 38 42 00 24 05 00 00 00 04
0050   00 00 00 01 00 00 00 00 42 00 25 01 00 00 00 20
0060   42 00 99 07 00 00 00 08 74 65 73 74 75 73 65 72
0070   42 00 a1 07 00 00 00 08 74 65 73 74 70 61 73 73
0080   42 00 0d 02 00 00 00 04 00 00 00 01 00 00 00 00
0090   42 00 0f 01 00 00 01 18 42 00 5c 05 00 00 00 04
00a0   00 00 00 01 00 00 00 00 42 00 79 01 00 00 01 00
00b0   42 00 57 05 00 00 00 04 00 00 00 02 00 00 00 00
00c0   42 00 91 01 00 00 00 e8 42 00 08 01 00 00 00 30
00d0   42 00 0a 07 00 00 00 17 43 72 79 70 74 6f 67 72
00e0   61 70 68 69 63 20 41 6c 67 6f 72 69 74 68 6d 00
00f0   42 00 0b 05 00 00 00 04 00 00 00 03 00 00 00 00
0100   42 00 08 01 00 00 00 30 42 00 0a 07 00 00 00 14
0110   43 72 79 70 74 6f 67 72 61 70 68 69 63 20 4c 65
0120   6e 67 74 68 00 00 00 00 42 00 0b 02 00 00 00 04
0130   00 00 00 80 00 00 00 00 42 00 08 01 00 00 00 30
0140   42 00 0a 07 00 00 00 18 43 72 79 70 74 6f 67 72
0150   61 70 68 69 63 20 55 73 61 67 65 20 4d 61 73 6b
0160   42 00 0b 02 00 00 00 04 00 00 00 0c 00 00 00 00
0170   42 00 08 01 00 00 00 38 42 00 0a 07 00 00 00 04
0180   4e 61 6d 65 00 00 00 00 42 00 0b 01 00 00 00 20
0190   42 00 55 07 00 00 00 07 41 45 53 4b 65 79 31 00
01a0   42 00 54 05 00 00 00 04 00 00 00 01 00 00 00 00`)
View Source
var SampleCreateResponseSuccess = WiresharkDumpToBytes(`
0000   42 00 7b 01 00 00 00 a0 42 00 7a 01 00 00 00 48
0010   42 00 69 01 00 00 00 20 42 00 6a 02 00 00 00 04
0020   00 00 00 01 00 00 00 00 42 00 6b 02 00 00 00 04
0030   00 00 00 02 00 00 00 00 42 00 92 09 00 00 00 08
0040   00 00 00 00 58 ef 52 8d 42 00 0d 02 00 00 00 04
0050   00 00 00 01 00 00 00 00 42 00 0f 01 00 00 00 48
0060   42 00 5c 05 00 00 00 04 00 00 00 01 00 00 00 00
0070   42 00 7f 05 00 00 00 04 00 00 00 00 00 00 00 00
0080   42 00 7c 01 00 00 00 20 42 00 57 05 00 00 00 04
0090   00 00 00 02 00 00 00 00 42 00 94 07 00 00 00 01
00a0   31 00 00 00 00 00 00 00`)
View Source
var SampleDestroyRequest = WiresharkDumpToBytes(`
0000   42 00 78 01 00 00 00 b8 42 00 77 01 00 00 00 80
0010   42 00 69 01 00 00 00 20 42 00 6a 02 00 00 00 04
0020   00 00 00 01 00 00 00 00 42 00 6b 02 00 00 00 04
0030   00 00 00 02 00 00 00 00 42 00 0c 01 00 00 00 40
0040   42 00 23 01 00 00 00 38 42 00 24 05 00 00 00 04
0050   00 00 00 01 00 00 00 00 42 00 25 01 00 00 00 20
0060   42 00 99 07 00 00 00 08 74 65 73 74 75 73 65 72
0070   42 00 a1 07 00 00 00 08 74 65 73 74 70 61 73 73
0080   42 00 0d 02 00 00 00 04 00 00 00 01 00 00 00 00
0090   42 00 0f 01 00 00 00 28 42 00 5c 05 00 00 00 04
00a0   00 00 00 14 00 00 00 00 42 00 79 01 00 00 00 10
00b0   42 00 94 07 00 00 00 01 31 00 00 00 00 00 00 00`)
View Source
var SampleDestroyResponseFailure = WiresharkDumpToBytes(`
0000   42 00 7b 01 00 00 00 b8 42 00 7a 01 00 00 00 48
0010   42 00 69 01 00 00 00 20 42 00 6a 02 00 00 00 04
0020   00 00 00 01 00 00 00 00 42 00 6b 02 00 00 00 04
0030   00 00 00 02 00 00 00 00 42 00 92 09 00 00 00 08
0040   00 00 00 00 59 09 e8 3a 42 00 0d 02 00 00 00 04
0050   00 00 00 01 00 00 00 00 42 00 0f 01 00 00 00 60
0060   42 00 5c 05 00 00 00 04 00 00 00 14 00 00 00 00
0070   42 00 7f 05 00 00 00 04 00 00 00 01 00 00 00 00
0080   42 00 7e 05 00 00 00 04 00 00 00 01 00 00 00 00
0090   42 00 7d 07 00 00 00 25 43 6f 75 6c 64 20 6e 6f
00a0   74 20 6c 6f 63 61 74 65 20 6f 62 6a 65 63 74 3a
00b0   20 64 6f 65 73 6e 6f 74 65 78 69 73 74 00 00 00`)
View Source
var SampleDestroyResponseSuccess = WiresharkDumpToBytes(`
0000   42 00 7b 01 00 00 00 90 42 00 7a 01 00 00 00 48
0010   42 00 69 01 00 00 00 20 42 00 6a 02 00 00 00 04
0020   00 00 00 01 00 00 00 00 42 00 6b 02 00 00 00 04
0030   00 00 00 02 00 00 00 00 42 00 92 09 00 00 00 08
0040   00 00 00 00 58 ef 52 8d 42 00 0d 02 00 00 00 04
0050   00 00 00 01 00 00 00 00 42 00 0f 01 00 00 00 38
0060   42 00 5c 05 00 00 00 04 00 00 00 14 00 00 00 00
0070   42 00 7f 05 00 00 00 04 00 00 00 00 00 00 00 00
0080   42 00 7c 01 00 00 00 10 42 00 94 07 00 00 00 01
0090   31 00 00 00 00 00 00 00`)
View Source
var SampleGetRequest = WiresharkDumpToBytes(`
0000   42 00 78 01 00 00 00 b8 42 00 77 01 00 00 00 80
0010   42 00 69 01 00 00 00 20 42 00 6a 02 00 00 00 04
0020   00 00 00 01 00 00 00 00 42 00 6b 02 00 00 00 04
0030   00 00 00 02 00 00 00 00 42 00 0c 01 00 00 00 40
0040   42 00 23 01 00 00 00 38 42 00 24 05 00 00 00 04
0050   00 00 00 01 00 00 00 00 42 00 25 01 00 00 00 20
0060   42 00 99 07 00 00 00 08 74 65 73 74 75 73 65 72
0070   42 00 a1 07 00 00 00 08 74 65 73 74 70 61 73 73
0080   42 00 0d 02 00 00 00 04 00 00 00 01 00 00 00 00
0090   42 00 0f 01 00 00 00 28 42 00 5c 05 00 00 00 04
00a0   00 00 00 0a 00 00 00 00 42 00 79 01 00 00 00 10
00b0   42 00 94 07 00 00 00 01 31 00 00 00 00 00 00 00`)
View Source
var SampleGetResponseFailure = WiresharkDumpToBytes(`
0000   42 00 7b 01 00 00 00 b8 42 00 7a 01 00 00 00 48
0010   42 00 69 01 00 00 00 20 42 00 6a 02 00 00 00 04
0020   00 00 00 01 00 00 00 00 42 00 6b 02 00 00 00 04
0030   00 00 00 02 00 00 00 00 42 00 92 09 00 00 00 08
0040   00 00 00 00 59 09 e8 3a 42 00 0d 02 00 00 00 04
0050   00 00 00 01 00 00 00 00 42 00 0f 01 00 00 00 60
0060   42 00 5c 05 00 00 00 04 00 00 00 0a 00 00 00 00
0070   42 00 7f 05 00 00 00 04 00 00 00 01 00 00 00 00
0080   42 00 7e 05 00 00 00 04 00 00 00 01 00 00 00 00
0090   42 00 7d 07 00 00 00 25 43 6f 75 6c 64 20 6e 6f
00a0   74 20 6c 6f 63 61 74 65 20 6f 62 6a 65 63 74 3a
00b0   20 64 6f 65 73 6e 6f 74 65 78 69 73 74 00 00 00`)
View Source
var SampleGetResponseSuccess = WiresharkDumpToBytes(`
0000   42 00 7b 01 00 00 01 00 42 00 7a 01 00 00 00 48
0010   42 00 69 01 00 00 00 20 42 00 6a 02 00 00 00 04
0020   00 00 00 01 00 00 00 00 42 00 6b 02 00 00 00 04
0030   00 00 00 02 00 00 00 00 42 00 92 09 00 00 00 08
0040   00 00 00 00 58 ef 52 8d 42 00 0d 02 00 00 00 04
0050   00 00 00 01 00 00 00 00 42 00 0f 01 00 00 00 a8
0060   42 00 5c 05 00 00 00 04 00 00 00 0a 00 00 00 00
0070   42 00 7f 05 00 00 00 04 00 00 00 00 00 00 00 00
0080   42 00 7c 01 00 00 00 80 42 00 57 05 00 00 00 04
0090   00 00 00 02 00 00 00 00 42 00 94 07 00 00 00 01
00a0   31 00 00 00 00 00 00 00 42 00 8f 01 00 00 00 58
00b0   42 00 40 01 00 00 00 50 42 00 42 05 00 00 00 04
00c0   00 00 00 01 00 00 00 00 42 00 45 01 00 00 00 18
00d0   42 00 43 08 00 00 00 10 40 4a 70 1c 3c ae ea af
00e0   04 74 25 69 cf 64 b2 7a 42 00 28 05 00 00 00 04
00f0   00 00 00 03 00 00 00 00 42 00 2a 02 00 00 00 04
0100   00 00 00 80 00 00 00 00`)

Functions

func CopyPrimitive

func CopyPrimitive(dest, src Item) error

Copy tag, type, and value of a primitive TTLV item from src to dest. Both src and dest are pointers.

func DebugTTLVItem

func DebugTTLVItem(indent int, entity interface{}) string

Generate a string that describes an item (pointer) in very detail. If the item is a structure, the output descends into the child items too.

func EncodeAny

func EncodeAny(thing Item) (ret []byte)

Encode any TTLV item. Input must be pointer to item and must not be nil.

func EncodeIntBigEndian

func EncodeIntBigEndian(someInt interface{}) []byte

Encode any fixed-size integer into big endian byte array and return.

func RoundUpTo8

func RoundUpTo8(in int) int

Round input integer upward to be divisible by 8.

func WiresharkDumpToBytes

func WiresharkDumpToBytes(in string) []byte

Decode wireshark's hex dump of a network packet into byte array by removing its extra pieces.

Types

type Bytes

type Bytes struct {
	TTL
	Value []byte
}

TTLV byte array. Length of value is actual array length, but representation is padded to align with 8 bytes.

func (*Bytes) GetLength

func (bytes *Bytes) GetLength() int

func (*Bytes) GetTTL

func (bytes *Bytes) GetTTL() TTL

func (*Bytes) ResetTyp

func (bytes *Bytes) ResetTyp()

type DateTime

type DateTime struct {
	TTL
	Time time.Time
}

TTLV date time - seconds since Unix epoch represented as LongInteger. Length of value is 8.

func (*DateTime) GetLength

func (dt *DateTime) GetLength() int

func (*DateTime) GetTTL

func (dt *DateTime) GetTTL() TTL

func (*DateTime) ResetTyp

func (dt *DateTime) ResetTyp()

type Enumeration

type Enumeration struct {
	TTL
	Value int32
}

TTLV enumeration. Length of value is 4. Representation comes with 4 additional bytes of padding.

func (*Enumeration) GetLength

func (enum *Enumeration) GetLength() int

func (*Enumeration) GetTTL

func (enum *Enumeration) GetTTL() TTL

func (*Enumeration) ResetTyp

func (enum *Enumeration) ResetTyp()

type Integer

type Integer struct {
	TTL
	Value int32
}

TTLV integer. Length of value is 4. Representation comes with 4 additional bytes of padding.

func (*Integer) GetLength

func (i *Integer) GetLength() int

func (*Integer) GetTTL

func (i *Integer) GetTTL() TTL

func (*Integer) ResetTyp

func (i *Integer) ResetTyp()

type Item

type Item interface {
	GetTTL() TTL    // Return TTL component of TTLV item.
	GetLength() int // Calculate value length and give the length to TTL. Apart from Structure, the length does not count padding.
	ResetTyp()      // Reset Typ byte in TTL structure to the one corresponding to implementation.
}

All TTLV items implement this interface.

func DecodeAny

func DecodeAny(in []byte) (ret Item, length int, err error)

Decode any TTLV item and return pointer to item.

type LongInteger

type LongInteger struct {
	TTL
	Value int64
}

TTLV long integer. Length of value is 8.

func (*LongInteger) GetLength

func (li *LongInteger) GetLength() int

func (*LongInteger) GetTTL

func (li *LongInteger) GetTTL() TTL

func (*LongInteger) ResetTyp

func (li *LongInteger) ResetTyp()

type Structure

type Structure struct {
	TTL
	Items []Item
}

TTLV structure. Length of value is sum of item lengths including padding.

func NewStructure

func NewStructure(tag Tag, items ...Item) *Structure

Construct a new structure with the specified tag, place the items inside the structure as well. Each item must be a pointer to Item.

func (*Structure) GetLength

func (st *Structure) GetLength() int

func (*Structure) GetTTL

func (st *Structure) GetTTL() TTL

func (*Structure) ResetTyp

func (st *Structure) ResetTyp()

type TTL

type TTL struct {
	Tag    Tag
	Typ    byte
	Length int
}

Bytes, type, and value length excluding padding.

func (TTL) TTLString

func (com TTL) TTLString() string

Return tag, type, and length in a string.

func (TTL) WriteTTTo

func (com TTL) WriteTTTo(out *bytes.Buffer)

Write tag bytes and type byte into the buffer.

type Tag

type Tag [3]byte // The tag of TTLV consists of three bytes

func DecodeTTL

func DecodeTTL(in []byte) (tag Tag, typ byte, length int32, err error)

Decode tag, type, and original value length excluding padding from the first several bytes of input buffer.

func (Tag) ByteSlice

func (tag Tag) ByteSlice() []byte

Syntactic sugar to return byte slice equivalent of the tag.

type Text

type Text struct {
	TTL
	Value string
}

TTLV text string. Length of value is actual string length, but representation is padded to align with 8 bytes.

func (*Text) GetLength

func (text *Text) GetLength() int

func (*Text) GetTTL

func (text *Text) GetTTL() TTL

func (*Text) ResetTyp

func (text *Text) ResetTyp()

Jump to

Keyboard shortcuts

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