aper

package
v0.7.20 Latest Latest
Warning

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

Go to latest
Published: Sep 17, 2021 License: Apache-2.0 Imports: 9 Imported by: 13

README

Free 5GC "aper" project

Encoding and decoding of ASN.1 structs to APER encoding format

This is copied from v1.0.0 of https://github.com/free5gc/aper

Changes:

  • logrus has been replaced by own logging
  • errors are generated through our own package
  • can handle structs that have one or more private fields (lowercase)

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// BitStringType is the type of BitString
	BitStringType = reflect.TypeOf(asn1.BitString{})
)
View Source
var ChoiceMap = map[string]map[int]reflect.Type{}

ChoiceMap - a global map of choices - specific to the Protobuf being handled

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

This section is empty.

Jump to

Keyboard shortcuts

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