asn

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Mar 27, 2024 License: Apache-2.0 Imports: 4 Imported by: 1

Documentation

Index

Constants

View Source
const (
	TagBoolean         = 1
	TagInteger         = 2
	TagBitString       = 3
	TagOctetString     = 4
	TagNull            = 5
	TagOID             = 6
	TagEnumerated      = 10
	TagUTF8String      = 12
	TagSequence        = 16
	TagSet             = 17
	TagNumericString   = 18
	TagPrintableString = 19
	TagT61String       = 20
	TagIA5String       = 22
	TagUTCTime         = 23
	TagGeneralizedTime = 24
	TagGraphicString   = 25
	TagGeneralString   = 27
	TagBMPString       = 30
)

ASN.1 universal tag number

View Source
const (
	ClassUniversal       = 0
	ClassApplication     = 1
	ClassContextSpecific = 2
	ClassPrivate         = 3
)

ASN.1 tag class

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))
	// String types
	UTF8StringType    = reflect.TypeOf(UTF8String(""))
	IA5StringType     = reflect.TypeOf(IA5String(""))
	GraphicStringType = reflect.TypeOf(GraphicString(""))
	// Null type
	NullType = reflect.TypeOf(NULL(false))
)

Functions

func BerMarshal

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

Marshal returns the ASN.1 encoding of val.

func BerMarshalWithParams

func BerMarshalWithParams(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 ParseField

func ParseField(v reflect.Value, bytes []byte, params fieldParameters) error

ParseField is the main parsing function. Given a byte slice containing type value, it will try to parse a suitable ASN.1 value out and store it in the given Value. TODO : ObjectIdenfier

func Unmarshal

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

Unmarshal parses the BER-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 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 int64

An Enumerated is represented as a plain int64.

type GraphicString

type GraphicString string

GraphicString

type IA5String

type IA5String string

IA5String

type NULL

type NULL bool

NULL type, true for exist

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

type UTF8String

type UTF8String string

UTF8String

Jump to

Keyboard shortcuts

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