ber

package
v1.2.1 Latest Latest
Warning

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

Go to latest
Published: Jul 14, 2016 License: BSD-3-Clause, Apache-2.0 Imports: 4 Imported by: 0

README

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

Required Librarys: 
   None

Working:
   Very basic encoding / decoding needed for LDAP protocol

Tests Implemented:
   None

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

Documentation

Index

Constants

View Source
const (
	TagEOC              = 0x00
	TagBoolean          = 0x01
	TagInteger          = 0x02
	TagBitString        = 0x03
	TagOctetString      = 0x04
	TagNULL             = 0x05
	TagObjectIdentifier = 0x06
	TagObjectDescriptor = 0x07
	TagExternal         = 0x08
	TagRealFloat        = 0x09
	TagEnumerated       = 0x0a
	TagEmbeddedPDV      = 0x0b
	TagUTF8String       = 0x0c
	TagRelativeOID      = 0x0d
	TagSequence         = 0x10
	TagSet              = 0x11
	TagNumericString    = 0x12
	TagPrintableString  = 0x13
	TagT61String        = 0x14
	TagVideotexString   = 0x15
	TagIA5String        = 0x16
	TagUTCTime          = 0x17
	TagGeneralizedTime  = 0x18
	TagGraphicString    = 0x19
	TagVisibleString    = 0x1a
	TagGeneralString    = 0x1b
	TagUniversalString  = 0x1c
	TagCharacterString  = 0x1d
	TagBMPString        = 0x1e
	TagBitmask          = 0x1f // xxx11111b
)
View Source
const (
	ClassUniversal   = 0   // 00xxxxxxb
	ClassApplication = 64  // 01xxxxxxb
	ClassContext     = 128 // 10xxxxxxb
	ClassPrivate     = 192 // 11xxxxxxb
	ClassBitmask     = 192 // 11xxxxxxb
)
View Source
const (
	TypePrimative   = 0  // xx0xxxxxb
	TypeConstructed = 32 // xx1xxxxxb
	TypeBitmask     = 32 // xx1xxxxxb
)

Variables

View Source
var ClassMap = map[uint8]string{
	ClassUniversal:   "Universal",
	ClassApplication: "Application",
	ClassContext:     "Context",
	ClassPrivate:     "Private",
}
View Source
var Debug bool = false
View Source
var TagMap = map[uint8]string{
	TagEOC:              "EOC (End-of-Content)",
	TagBoolean:          "Boolean",
	TagInteger:          "Integer",
	TagBitString:        "Bit String",
	TagOctetString:      "Octet String",
	TagNULL:             "NULL",
	TagObjectIdentifier: "Object Identifier",
	TagObjectDescriptor: "Object Descriptor",
	TagExternal:         "External",
	TagRealFloat:        "Real (float)",
	TagEnumerated:       "Enumerated",
	TagEmbeddedPDV:      "Embedded PDV",
	TagUTF8String:       "UTF8 String",
	TagRelativeOID:      "Relative-OID",
	TagSequence:         "Sequence and Sequence of",
	TagSet:              "Set and Set OF",
	TagNumericString:    "Numeric String",
	TagPrintableString:  "Printable String",
	TagT61String:        "T61 String",
	TagVideotexString:   "Videotex String",
	TagIA5String:        "IA5 String",
	TagUTCTime:          "UTC Time",
	TagGeneralizedTime:  "Generalized Time",
	TagGraphicString:    "Graphic String",
	TagVisibleString:    "Visible String",
	TagGeneralString:    "General String",
	TagUniversalString:  "Universal String",
	TagCharacterString:  "Character String",
	TagBMPString:        "BMP String",
}
View Source
var TypeMap = map[uint8]string{
	TypePrimative:   "Primative",
	TypeConstructed: "Constructed",
}

Functions

func DecodeInteger

func DecodeInteger(data []byte) (ret uint64)

func DecodeString

func DecodeString(data []byte) (ret string)

func EncodeInteger

func EncodeInteger(val uint64) []byte

func PrintBytes

func PrintBytes(buf []byte, indent string)

func PrintPacket

func PrintPacket(p *Packet)

Types

type Packet

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

func DecodePacket

func DecodePacket(data []byte) *Packet

func Encode

func Encode(ClassType, TagType, Tag uint8, Value interface{}, Description string) *Packet

func NewBoolean

func NewBoolean(ClassType, TagType, Tag uint8, Value bool, Description string) *Packet

func NewInteger

func NewInteger(ClassType, TagType, Tag uint8, Value uint64, Description string) *Packet

func NewSequence

func NewSequence(Description string) *Packet

func NewString

func NewString(ClassType, TagType, Tag uint8, 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

func (*Packet) DataLength

func (p *Packet) DataLength() uint64

Jump to

Keyboard shortcuts

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