Documentation ¶
Index ¶
- Constants
- Variables
- func BerMarshal(val interface{}) ([]byte, error)
- func BerMarshalWithParams(val interface{}, params string) ([]byte, error)
- func ParseField(v reflect.Value, bytes []byte, params fieldParameters) error
- func Unmarshal(b []byte, value interface{}) error
- func UnmarshalWithParams(b []byte, value interface{}, params string) error
- type BitString
- type Enumerated
- type GraphicString
- type IA5String
- type NULL
- type ObjectIdentifier
- type OctetString
- type UTF8String
Constants ¶
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
const ( ClassUniversal = 0 ClassApplication = 1 ClassContextSpecific = 2 ClassPrivate = 3 )
ASN.1 tag class
Variables ¶
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 ¶
Marshal returns the ASN.1 encoding of val.
func BerMarshalWithParams ¶
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 ¶
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 ¶
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 ¶
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 ObjectIdentifier ¶
type ObjectIdentifier []byte
ObjectIdentifier is for an ASN.1 OBJECT IDENTIFIER type