ber

package module
v1.5.5 Latest Latest
Warning

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

Go to latest
Published: Sep 14, 2023 License: MIT Imports: 11 Imported by: 46

README

GoDoc Build Status

ASN1 BER Encoding / Decoding Library for the GO programming language.

Required libraries: None

Working: Very basic encoding / decoding needed for LDAP protocol

Tests Implemented: A few

TODO: Fix all encoding / decoding to conform to ASN1 BER spec Implement Tests / Benchmarks


The Go gopher was designed by Renee French. (http://reneefrench.blogspot.com/) The design is licensed under the Creative Commons 3.0 Attributions license. Read this article for more details: http://blog.golang.org/gopher

Documentation

Index

Constants

View Source
const (
	// LengthLongFormBitmask is the mask to apply to the length byte to see if a long-form byte sequence is used
	LengthLongFormBitmask = 0x80
	// LengthValueBitmask is the mask to apply to the length byte to get the number of bytes in the long-form byte sequence
	LengthValueBitmask = 0x7f

	// LengthIndefinite is returned from readLength to indicate an indefinite length
	LengthIndefinite = -1
)

Variables

View Source
var ClassMap = map[Class]string{
	ClassUniversal:   "Universal",
	ClassApplication: "Application",
	ClassContext:     "Context",
	ClassPrivate:     "Private",
}
View Source
var Debug = false
View Source
var ErrInvalidTimeFormat = errors.New("invalid time format")

ErrInvalidTimeFormat is returned when the generalizedTime string was not correct.

View Source
var MaxPacketLengthBytes int64 = math.MaxInt32

MaxPacketLengthBytes specifies the maximum allowed packet size when calling ReadPacket or DecodePacket. Set to 0 for no limit.

View Source
var TypeMap = map[Type]string{
	TypePrimitive:   "Primitive",
	TypeConstructed: "Constructed",
}

Functions

func DecodeString

func DecodeString(data []byte) string

func DescribePacket added in v1.5.5

func DescribePacket(p *Packet) string

Return a string describing packet content. This is not recursive, If the packet is a sequence, use `printPacket()`, or browse sequence yourself.

func ParseGeneralizedTime added in v1.5.0

func ParseGeneralizedTime(v []byte) (time.Time, error)

ParseGeneralizedTime parses a string value and if it conforms to GeneralizedTime^0 format, will return a time.Time for that value.

func ParseInt64

func ParseInt64(bytes []byte) (ret int64, err error)

func ParseReal added in v1.5.0

func ParseReal(v []byte) (val float64, err error)

func PrintBytes

func PrintBytes(out io.Writer, buf []byte, indent string)

func PrintPacket

func PrintPacket(p *Packet)

func WritePacket added in v1.4.1

func WritePacket(out io.Writer, p *Packet)

Types

type Class

type Class uint8
const (
	ClassUniversal   Class = 0   // 00xxxxxxb
	ClassApplication Class = 64  // 01xxxxxxb
	ClassContext     Class = 128 // 10xxxxxxb
	ClassPrivate     Class = 192 // 11xxxxxxb
	ClassBitmask     Class = 192 // 11xxxxxxb
)

type Identifier

type Identifier struct {
	ClassType Class
	TagType   Type
	Tag       Tag
}

type Packet

type Packet struct {
	Identifier
	Value       interface{}
	ByteValue   []byte
	Data        *bytes.Buffer
	Children    []*Packet
	Description string
}

func DecodePacket

func DecodePacket(data []byte) *Packet

DecodePacket decodes the given bytes into a single Packet If a decode error is encountered, nil is returned.

func DecodePacketErr

func DecodePacketErr(data []byte) (*Packet, error)

DecodePacketErr decodes the given bytes into a single Packet If a decode error is encountered, nil is returned.

func Encode

func Encode(classType Class, tagType Type, tag Tag, value interface{}, description string) *Packet

func NewBoolean

func NewBoolean(classType Class, tagType Type, tag Tag, value bool, description string) *Packet

func NewGeneralizedTime added in v1.5.0

func NewGeneralizedTime(classType Class, tagType Type, tag Tag, value time.Time, description string) *Packet

func NewInteger

func NewInteger(classType Class, tagType Type, tag Tag, value interface{}, description string) *Packet

func NewLDAPBoolean added in v1.4.1

func NewLDAPBoolean(classType Class, tagType Type, tag Tag, value bool, description string) *Packet

NewLDAPBoolean returns a RFC 4511-compliant Boolean packet.

func NewReal added in v1.5.0

func NewReal(classType Class, tagType Type, tag Tag, value interface{}, description string) *Packet

func NewSequence

func NewSequence(description string) *Packet

func NewString

func NewString(classType Class, tagType Type, tag Tag, value, description string) *Packet

func ReadPacket

func ReadPacket(reader io.Reader) (*Packet, error)

ReadPacket reads a single Packet from the reader.

func (*Packet) AppendChild

func (p *Packet) AppendChild(child *Packet)

func (*Packet) Bytes

func (p *Packet) Bytes() []byte

type Tag

type Tag uint64
const (
	TagEOC              Tag = 0x00
	TagBoolean          Tag = 0x01
	TagInteger          Tag = 0x02
	TagBitString        Tag = 0x03
	TagOctetString      Tag = 0x04
	TagNULL             Tag = 0x05
	TagObjectIdentifier Tag = 0x06
	TagObjectDescriptor Tag = 0x07
	TagExternal         Tag = 0x08
	TagRealFloat        Tag = 0x09
	TagEnumerated       Tag = 0x0a
	TagEmbeddedPDV      Tag = 0x0b
	TagUTF8String       Tag = 0x0c
	TagRelativeOID      Tag = 0x0d
	TagSequence         Tag = 0x10
	TagSet              Tag = 0x11
	TagNumericString    Tag = 0x12
	TagPrintableString  Tag = 0x13
	TagT61String        Tag = 0x14
	TagVideotexString   Tag = 0x15
	TagIA5String        Tag = 0x16
	TagUTCTime          Tag = 0x17
	TagGeneralizedTime  Tag = 0x18
	TagGraphicString    Tag = 0x19
	TagVisibleString    Tag = 0x1a
	TagGeneralString    Tag = 0x1b
	TagUniversalString  Tag = 0x1c
	TagCharacterString  Tag = 0x1d
	TagBMPString        Tag = 0x1e
	TagBitmask          Tag = 0x1f // xxx11111b

	// HighTag indicates the start of a high-tag byte sequence
	HighTag Tag = 0x1f // xxx11111b
	// HighTagContinueBitmask indicates the high-tag byte sequence should continue
	HighTagContinueBitmask Tag = 0x80 // 10000000b
	// HighTagValueBitmask obtains the tag value from a high-tag byte sequence byte
	HighTagValueBitmask Tag = 0x7f // 01111111b
)

type Type

type Type uint8
const (
	TypePrimitive   Type = 0  // xx0xxxxxb
	TypeConstructed Type = 32 // xx1xxxxxb
	TypeBitmask     Type = 32 // xx1xxxxxb
)

Jump to

Keyboard shortcuts

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