v0.1.2 Latest Latest

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

Go to latest
Published: May 11, 2015 License: BSD-3-Clause, MPL-2.0 Imports: 5 Imported by: 0


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




This section is empty.


View Source
var ClassMap = map[Class]string{
	ClassUniversal:   "Universal",
	ClassApplication: "Application",
	ClassContext:     "Context",
	ClassPrivate:     "Private",
View Source
var Debug bool = false
View Source
var TypeMap = map[Type]string{
	TypePrimitive:   "Primitive",
	TypeConstructed: "Constructed",


func DecodeString

func DecodeString(data []byte) string

func PrintBytes

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

func PrintPacket

func PrintPacket(p *Packet)


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 Packet

type Packet struct {
	ClassType   Class
	TagType     Type
	Tag         Tag
	Value       interface{}
	ByteValue   []byte
	Data        *bytes.Buffer
	Children    []*Packet
	Description string

func DecodePacket

func DecodePacket(data []byte) *Packet

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 NewInteger

func NewInteger(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)

func (*Packet) AppendChild

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

func (*Packet) Bytes

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

type Tag

type Tag uint8
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

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