Namespace: go.std.encoding.asn1
v1.0Contents
Summary
Provides a low-level interface to the encoding/asn1 package.
Package asn1 implements parsing of DER-encoded ASN.1 data structures,
as defined in ITU-T Rec X.690.
See also ``A Layman's Guide to a Subset of ASN.1, BER, and DER,''
http://luca.ntop.org/Teaching/Appunti/asn1.html.
Index
- *BitString
- *Enumerated
- *Flag
- *ObjectIdentifier
- *RawContent
- *RawValue
- *StructuralError
- *SyntaxError
- BitString
- ClassApplication
- ClassContextSpecific
- ClassPrivate
- ClassUniversal
- Enumerated
- Flag
- Marshal
- MarshalWithParams
- NullBytes
- NullRawValue
- ObjectIdentifier
- RawContent
- RawValue
- StructuralError
- SyntaxError
- TagBMPString
- TagBitString
- TagBoolean
- TagEnum
- TagGeneralString
- TagGeneralizedTime
- TagIA5String
- TagInteger
- TagNull
- TagNumericString
- TagOID
- TagOctetString
- TagPrintableString
- TagSequence
- TagSet
- TagT61String
- TagUTCTime
- TagUTF8String
- Unmarshal
- UnmarshalWithParams
- arrayOfBitString
- arrayOfEnumerated
- arrayOfFlag
- arrayOfObjectIdentifier
- arrayOfRawContent
- arrayOfRawValue
- arrayOfStructuralError
- arrayOfSyntaxError
Legend
-
Constant
Variable
Function
Macro
Special form
Type
GoVar
Receiver/Method
Constants
Constants are variables with :const true in their metadata. Joker currently does not recognize them as special; as such, it allows redefining them or their values.-
ClassApplication
Int v1.0ASN.1 class types represent the namespace of the tag.
-
ClassContextSpecific
Int v1.0ASN.1 class types represent the namespace of the tag.
-
ClassPrivate
Int v1.0ASN.1 class types represent the namespace of the tag.
-
ClassUniversal
Int v1.0ASN.1 class types represent the namespace of the tag.
-
TagBMPString
Int v1.0ASN.1 tags represent the type of the following object.
-
TagBitString
Int v1.0ASN.1 tags represent the type of the following object.
-
TagBoolean
Int v1.0ASN.1 tags represent the type of the following object.
-
TagEnum
Int v1.0ASN.1 tags represent the type of the following object.
-
TagGeneralString
Int v1.0ASN.1 tags represent the type of the following object.
-
TagGeneralizedTime
Int v1.0ASN.1 tags represent the type of the following object.
-
TagIA5String
Int v1.0ASN.1 tags represent the type of the following object.
-
TagInteger
Int v1.0ASN.1 tags represent the type of the following object.
-
TagNull
Int v1.0ASN.1 tags represent the type of the following object.
-
TagNumericString
Int v1.0ASN.1 tags represent the type of the following object.
-
TagOID
Int v1.0ASN.1 tags represent the type of the following object.
-
TagOctetString
Int v1.0ASN.1 tags represent the type of the following object.
-
TagPrintableString
Int v1.0ASN.1 tags represent the type of the following object.
-
TagSequence
Int v1.0ASN.1 tags represent the type of the following object.
-
TagSet
Int v1.0ASN.1 tags represent the type of the following object.
-
TagT61String
Int v1.0ASN.1 tags represent the type of the following object.
-
TagUTCTime
Int v1.0ASN.1 tags represent the type of the following object.
-
TagUTF8String
Int v1.0ASN.1 tags represent the type of the following object.
Variables
-
NullBytes
Var v1.0NullBytes contains bytes representing the DER-encoded ASN.1 NULL type.
-
NullRawValue
Var v1.0NullRawValue is a RawValue with its Tag set to the ASN.1 NULL type tag (5).
Functions, Macros, and Special Forms
-
Marshal
Function v1.0(Marshal val)
Marshal returns the ASN.1 encoding of val.
In addition to the struct tags recognised by Unmarshal, the following can be
used:
ia5: causes strings to be marshaled as ASN.1, IA5String values
omitempty: causes empty slices to be skipped
printable: causes strings to be marshaled as ASN.1, PrintableString values
utf8: causes strings to be marshaled as ASN.1, UTF8String values
utc: causes time.Time to be marshaled as ASN.1, UTCTime values
generalized: causes time.Time to be marshaled as ASN.1, GeneralizedTime values
Go input arguments: (val any)
Go returns: ([]byte, error)
Joker input arguments: [^GoObject val]
Joker returns: [^arrayOfByte, ^Error] -
MarshalWithParams
Function v1.0(MarshalWithParams val params)
MarshalWithParams allows field parameters to be specified for the
top-level element. The form of the params is the same as the field tags.
Go input arguments: (val any, params string)
Go returns: ([]byte, error)
Joker input arguments: [^GoObject val, ^String params]
Joker returns: [^arrayOfByte, ^Error] -
Unmarshal
Function v1.0(Unmarshal b val)
Unmarshal parses the DER-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. If val
is nil or not a pointer, Unmarshal returns an error.
After parsing b, any bytes that were leftover and not used to fill
val will be returned in rest. When parsing a SEQUENCE into a struct,
any trailing elements of the SEQUENCE that do not have matching
fields in val will not be included in rest, as these are considered
valid elements of the SEQUENCE and not trailing data.
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 interface{}.
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
When decoding an ASN.1 value with an IMPLICIT tag into a string field,
Unmarshal will default to a PrintableString, which doesn't support
characters such as '@' and '&'. To force other encodings, use the following
tags:
ia5 causes strings to be unmarshaled as ASN.1 IA5String values
numeric causes strings to be unmarshaled as ASN.1 NumericString values
utf8 causes strings to be unmarshaled as ASN.1 UTF8String values
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 name of a slice type ends with "SET" then it's treated as if
the "set" tag was set on it. This results in interpreting the type as a
SET OF x rather than a SEQUENCE OF x. 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.
Go input arguments: (b []byte, val any)
Go returns: (rest []byte, err error)
Joker input arguments: [^arrayOfByte b, ^GoObject val]
Joker returns: [^arrayOfByte rest, ^Error err] -
UnmarshalWithParams
Function v1.0(UnmarshalWithParams b val params)
UnmarshalWithParams allows field parameters to be specified for the
top-level element. The form of the params is the same as the field tags.
Go input arguments: (b []byte, val any, params string)
Go returns: (rest []byte, err error)
Joker input arguments: [^arrayOfByte b, ^GoObject val, ^String params]
Joker returns: [^arrayOfByte rest, ^Error err]
Types
-
*BitString
Concrete Type v1.0BitString is the structure to use when you want an ASN.1 BIT STRING type. A
bit string is padded up to the nearest byte in memory and the number of
valid bits is recorded. Padding bits will be zero.
-
*Enumerated
Concrete Type v1.0An Enumerated is represented as a plain int.
-
*Flag
Concrete Type v1.0A Flag accepts any data and is set to true if present.
-
*ObjectIdentifier
Concrete Type v1.0An ObjectIdentifier represents an ASN.1 OBJECT IDENTIFIER.
-
*RawContent
Concrete Type v1.0RawContent 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.
-
*RawValue
Concrete Type v1.0A RawValue represents an undecoded ASN.1 object.
-
*StructuralError
Concrete Type v1.0A StructuralError suggests that the ASN.1 data is valid, but the Go type
which is receiving it doesn't match.
-
*SyntaxError
Concrete Type v1.0A SyntaxError suggests that the ASN.1 data is invalid.
-
BitString
Concrete Type v1.0BitString is the structure to use when you want an ASN.1 BIT STRING type. A
bit string is padded up to the nearest byte in memory and the number of
valid bits is recorded. Padding bits will be zero.
-
At
Receiver for BitString v1.0([i])
At returns the bit at the given index. If the index is out of range it
returns false.
-
RightAlign
Receiver for BitString v1.0([])
RightAlign returns a slice where the padding bits are at the beginning. The
slice may share memory with the BitString.
-
Enumerated
Concrete Type v1.0An Enumerated is represented as a plain int.
-
Flag
Concrete Type v1.0A Flag accepts any data and is set to true if present.
-
ObjectIdentifier
Concrete Type v1.0An ObjectIdentifier represents an ASN.1 OBJECT IDENTIFIER.
-
Equal
Receiver for ObjectIdentifier v1.0([other])
Equal reports whether oi and other represent the same identifier.
-
String
Receiver for ObjectIdentifier v1.0([])
-
RawContent
Concrete Type v1.0RawContent 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.
-
RawValue
Concrete Type v1.0A RawValue represents an undecoded ASN.1 object.
-
StructuralError
Concrete Type v1.0A StructuralError suggests that the ASN.1 data is valid, but the Go type
which is receiving it doesn't match.
-
Error
Receiver for StructuralError v1.0([])
-
SyntaxError
Concrete Type v1.0A SyntaxError suggests that the ASN.1 data is invalid.
-
Error
Receiver for SyntaxError v1.0([])
-
arrayOfBitString
Concrete Type v1.0BitString is the structure to use when you want an ASN.1 BIT STRING type. A
bit string is padded up to the nearest byte in memory and the number of
valid bits is recorded. Padding bits will be zero.
-
arrayOfEnumerated
Concrete Type v1.0An Enumerated is represented as a plain int.
-
arrayOfFlag
Concrete Type v1.0A Flag accepts any data and is set to true if present.
-
arrayOfObjectIdentifier
Concrete Type v1.0An ObjectIdentifier represents an ASN.1 OBJECT IDENTIFIER.
-
arrayOfRawContent
Concrete Type v1.0RawContent 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.
-
arrayOfRawValue
Concrete Type v1.0A RawValue represents an undecoded ASN.1 object.
-
arrayOfStructuralError
Concrete Type v1.0A StructuralError suggests that the ASN.1 data is valid, but the Go type
which is receiving it doesn't match.
-
arrayOfSyntaxError
Concrete Type v1.0A SyntaxError suggests that the ASN.1 data is invalid.