Documentation ¶
Index ¶
- func Marshal(v any) ([]byte, error)
- func MarshalWithOptions(v any, optionsString string) ([]byte, error)
- func Unmarshal(b []byte, val any) (rest []byte, err error)
- func UnmarshalWithParams(b []byte, val any, params string) (rest []byte, err error)
- type BitString
- type Encoder
- type Enumerated
- type Flag
- type Null
- type ObjectIdentifier
- type RawContent
- type StructuralError
- type SyntaxError
- type Tag
- type TagClass
- type UnsupportedTypeError
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
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 val. 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, or *big.Int (from the math/big package). 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.
An ASN.1 UTCTIME or GENERALIZEDTIME can be written to a time.Time.
An ASN.1 PrintableString, IA5String, or NumericString can be written to a string.
Any of the above ASN.1 values can be written to an any. The value stored in the interface has the corresponding Go type. For integers, that type is int64.
An ASN.1 SEQUENCE OF x or SET OF x can be written to a slice if an x can be written to the slice's element type.
An ASN.1 SEQUENCE or SET 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:
application specifies that an APPLICATION tag is used private specifies that a PRIVATE tag is used default:x sets the default value for optional integer fields (only used if optional is also present) explicit specifies that an additional, explicit tag wraps the implicit one optional marks the field as ASN.1 OPTIONAL set causes a SET, rather than a SEQUENCE type to be expected tag:x specifies the ASN.1 tag number; implies ASN.1 CONTEXT SPECIFIC
If the type of the first field of a structure is RawContent then the raw ASN1 contents of the struct will be stored in it.
If the type name of a slice element ends with "SET" then it's treated as if the "set" tag was set on it. This can be used with nested slices where a struct tag cannot be given.
Other ASN.1 types are not supported; if it encounters them, Unmarshal returns a parse error.
Types ¶
type ObjectIdentifier ¶
type ObjectIdentifier []int
func NewObjectIdentifier ¶
func NewObjectIdentifier(root int, node []int) (ObjectIdentifier, error)
func (ObjectIdentifier) Equal ¶
func (oi ObjectIdentifier) Equal(other ObjectIdentifier) bool
Equal reports whether oi and other represent the same identifier.
func (ObjectIdentifier) String ¶
func (oi ObjectIdentifier) String() string
type RawContent ¶
type RawContent []byte
RawContent is used to signal that the undecoded, DER data needs to be preserved for a struct. To use it, the first field of the struct must have this type. It's an error for any of the other fields to have this type.
type StructuralError ¶
type StructuralError struct {
Msg string
}
A StructuralError suggests that the ASN.1 data is valid, but the Go type which is receiving it doesn't match.
func (StructuralError) Error ¶
func (e StructuralError) Error() string
type SyntaxError ¶
type SyntaxError struct {
Msg string
}
A SyntaxError suggests that the ASN.1 data is invalid.
func (SyntaxError) Error ¶
func (e SyntaxError) Error() string
type Tag ¶
type Tag uint
const ( TagBoolean Tag = 0x01 TagInteger Tag = 0x02 TagBitString Tag = 0x03 TagOctetString Tag = 0x04 TagNull Tag = 0x05 TagObjectIdentifier Tag = 0x06 TagObjectDescriptor Tag = 0x07 TagExternal Tag = 0x08 TagReal Tag = 0x09 TagEnumerated Tag = 0x0a TagEmbeddedPdv Tag = 0x0b TagUtf8String Tag = 0x0c TagRelativeOid Tag = 0x0d TagTime Tag = 0x0e TagSequence Tag = 0x10 TagSequenceOf Tag = 0x10 TagSet Tag = 0x11 TagSetOf Tag = 0x11 TagNumericString Tag = 0x12 TagPrintableString Tag = 0x13 TagT61String Tag = 0x14 TagVideotexString Tag = 0x15 TagIa5String Tag = 0x16 TagUtcTime Tag = 0x17 TagGeneralizedTime Tag = 0x18 TagGraphicString Tag = 0x19 TagVisibleString Tag = 0x1a TagGeneralString Tag = 0x1b TagUniversalString Tag = 0x1c TagCharacterString Tag = 0x1d TagBmpString Tag = 0x1e TagDate Tag = 0x1f TagTimeOfDay Tag = 0x20 TagDateTime Tag = 0x21 TagDuration Tag = 0x22 TagOidIri Tag = 0x23 TagRelativeOidIri Tag = 0x24 )
type UnsupportedTypeError ¶
func (*UnsupportedTypeError) Error ¶
func (e *UnsupportedTypeError) Error() string