Package asn1
import "asn1"
The asn1 package 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.
Package files
asn1.go common.go marshal.gofunc Marshal
func Marshal(out io.Writer, val interface{}) os.Error
Marshal serialises val as an ASN.1 structure and writes the result to out. In the case of an error, no output is produced.
func MarshalToMemory
func MarshalToMemory(val interface{}) ([]byte, os.Error)
MarshalToMemory performs the same actions as Marshal, but returns the result as a byte slice.
func Unmarshal
func Unmarshal(val interface{}, b []byte) (rest []byte, err os.Error)
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.
An ASN.1 INTEGER can be written to an int or 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 PrintableString or IA5String 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:
optional marks the field as ASN.1 OPTIONAL [explicit] tag:x specifies the ASN.1 tag number; implies ASN.1 CONTEXT SPECIFIC default:x sets the default value for optional integer fields
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.
Other ASN.1 types are not supported; if it encounters them, Unmarshal returns a parse error.
type BitString
BitString 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.
type BitString struct {
Bytes []byte // bits packed into bytes.
BitLength int // length in bits.
}
func (BitString) At
func (b BitString) At(i int) int
At returns the bit at the given index. If the index is out of range it returns false.
func (BitString) RightAlign
func (b BitString) RightAlign() []byte
RightAlign returns a slice where the padding bits are at the beginning. The slice may share memory with the BitString.
type ObjectIdentifier
An ObjectIdentifier represents an ASN.1 OBJECT IDENTIFIER.
type ObjectIdentifier []int
type RawContent
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 RawContent []byte
type RawValue
A RawValue represents an undecoded ASN.1 object.
type RawValue struct {
Class, Tag int
IsCompound bool
Bytes []byte
}
type StructuralError
A StructuralError suggests that the ASN.1 data is valid, but the Go type which is receiving it doesn't match.
type StructuralError struct {
Msg string
}
func (StructuralError) String
func (e StructuralError) String() string
type SyntaxError
A SyntaxError suggests that the ASN.1 data is invalid.
type SyntaxError struct {
Msg string
}
func (SyntaxError) String
func (e SyntaxError) String() string
