ber

package
v0.0.0-...-15d4781 Latest Latest
Warning

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

Go to latest
Published: Mar 24, 2019 License: ISC Imports: 9 Imported by: 0

Documentation

Overview

package ber provides utilities for working with BER encoded data structures

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Get

func Get(data []byte, tag uint32, optional bool) (body, rest []byte, err error)

Get gets a specific TLV from the buffer

func Marshal

func Marshal(obj interface{}) ([]byte, error)

Marshal marshals an object as BER/DER

The specified object must be a structure. Members will be iterated and automatically BER encoded. The struct will not itself be enclosed in a tag

Any unnamed struct member will be inlined directly. Pointer values are considered optional: nil will not be marshalled, and on unmarshalling absence shall be treated as nil

Struct members must be tagged with the `ber` tag. If this tag is set to `-`, then the field will be skipped. Otherwise, it should be a smartcard style/wire-format hex tag as opposed to the ASN.1 format tags used by the Go marshal/asn.1 package

The tag value may be followed by any of a number of comma separated flag values. These can be:

* One of an encoding control flag. Valid encoding control flags are

  • `ber`: Marshal the nested object as if by a recursive call to Marshal
  • `big` or `bin_big`: Marshal the nested object using encoding/binary in big endian
  • `little` or `bin_little`: Same but little endian
  • `asn1`: Marshal the nested object using encoding/asn1

If no encoding control flag is specified, then

* `[]byte` or `string` is encoded directly * All other types are required to implement MarshalBinary

func MarshalValue

func MarshalValue(val reflect.Value) ([]byte, error)

MarshalsValue marshals a reflect.Value

func Next

func Next(data []byte) (tag uint32, body, rest []byte, err error)

Next reads the next TLV from the buffer

func NextLength

func NextLength(data []byte) (length int, rest []byte, err error)

NextLength reads a length value from the buffer

func NextTag

func NextTag(data []byte) (tag uint32, rest []byte, err error)

NextTag gets the next tag from data

func PackTag

func PackTag(tag uint32) []byte

Pack a tag into a byte array

func Put

func Put(buf []byte, tag uint32, data []byte) ([]byte, error)

Put appends a TLV to a buffer

func Unmarshal

func Unmarshal(buf []byte, obj interface{}) error

Unmarshal unmarshals buf into `obj`

func UnmarshalValue

func UnmarshalValue(buf []byte, val reflect.Value) error

UnmarshalValue unmarshals into a reflect.Value

Types

This section is empty.

Jump to

Keyboard shortcuts

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