aper

package module
v1.0.6 Latest Latest
Warning

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

Go to latest
Published: Dec 21, 2022 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// BitStringType is the type of BitString
	BitStringType = reflect.TypeOf(BitString{})
	// OctetStringType is the type of OctetString
	OctetStringType = reflect.TypeOf(OctetString{})
	// ObjectIdentifierType is the type of ObjectIdentify
	ObjectIdentifierType = reflect.TypeOf(ObjectIdentifier{})
	// EnumeratedType is the type of Enumerated
	EnumeratedType = reflect.TypeOf(Enumerated(0))
)

Functions

func GetBitString

func GetBitString(srcBytes []byte, bitsOffset uint, numBits uint) (dstBytes []byte, err error)

GetBitString is to get BitString with desire size from source byte array with bit offset

func GetBitsValue

func GetBitsValue(srcBytes []byte, bitsOffset uint, numBits uint) (value uint64, err error)

GetBitsValue is to get Value with desire bits from source byte array with bit offset

func Marshal

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

Marshal returns the ASN.1 encoding of val.

func MarshalWithParams

func MarshalWithParams(val interface{}, params string) ([]byte, error)

MarshalWithParams allows field parameters to be specified for the top-level element. The form of the params is the same as the field tags.

func Unmarshal

func Unmarshal(b []byte, value interface{}) error

Unmarshal parses the APER-encoded ASN.1 data structure b and uses the reflect package to fill in an arbitrary value pointed at by value. Because Unmarshal uses the reflect package, the structs being written to must use upper case field names.

An ASN.1 INTEGER can be written to an int, int32, int64, If the encoded value does not fit in the Go type, Unmarshal returns a parse error.

An ASN.1 BIT STRING can be written to a BitString.

An ASN.1 OCTET STRING can be written to a []byte.

An ASN.1 OBJECT IDENTIFIER can be written to an ObjectIdentifier.

An ASN.1 ENUMERATED can be written to an Enumerated.

Any of the above ASN.1 values can be written to an interface{}. The value stored in the interface has the corresponding Go type. For integers, that type is int64.

An ASN.1 SEQUENCE OF x can be written to a slice if an x can be written to the slice's element type.

An ASN.1 SEQUENCE can be written to a struct if each of the elements in the sequence can be written to the corresponding element in the struct.

The following tags on struct fields have special meaning to Unmarshal:

	optional        	OPTIONAL tag in SEQUENCE
	sizeExt             specifies that size  is extensible
	valueExt            specifies that value is extensible
	sizeLB		        set the minimum value of size constraint
	sizeUB              set the maximum value of value constraint
	valueLB		        set the minimum value of size constraint
	valueUB             set the maximum value of value constraint
	default             sets the default value
	openType            specifies the open Type
 referenceFieldName	the string of the reference field for this type (only if openType used)
 referenceFieldValue	the corresponding value of the reference field for this type (only if openType used)

Other ASN.1 types are not supported; if it encounters them, Unmarshal returns a parse error.

func UnmarshalWithParams

func UnmarshalWithParams(b []byte, value interface{}, params string) error

UnmarshalWithParams allows field parameters to be specified for the top-level element. The form of the params is the same as the field tags.

Types

type BitString

type BitString struct {
	Bytes     []byte // bits packed into bytes.
	BitLength uint64 // length in bits.
}

BitString is for an ASN.1 BIT STRING type, BitLength means the effective bits.

type Enumerated

type Enumerated uint64

An Enumerated is represented as a plain uint64.

type ObjectIdentifier

type ObjectIdentifier []byte

ObjectIdentifier is for an ASN.1 OBJECT IDENTIFIER type

type OctetString

type OctetString []byte

OctetString is for an ASN.1 OCTET STRING type

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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