func (ctx *Context) decode(reader io.Reader, value reflect.Value, opts *fieldOptions) error {
	raw, err := decodeRawValue(reader)
	if err != nil {
		return err
	}
	if ctx.der.decoding && raw.Indefinite {
		return parseError("indefinite length form is not supported by DER mode")
	}
	elem, err := ctx.getExpectedElement(raw, value.Type(), opts)
	if err != nil {
		return err
	}
	if raw.Class != elem.class || raw.Tag != elem.tag {
		ctx.log.Printf("%#v\n", opts)
		return parseError("expected tag (%d,%d) but found (%d,%d)",
			elem.class, elem.tag, raw.Class, raw.Tag)
	}
	return elem.decoder(raw.Content, value)
}
Main decode function
package asn1
import (
	"bytes"
	"io"
	"reflect"
	"sort"
)
type expectedElement struct {
	class   uint
	tag     uint
	decoder decoderFunction
}
type expectedFieldElement struct {
	expectedElement
	value reflect.Value
	opts  *fieldOptions
}
func (ctx *Context) Decode(data []byte, obj interface{}) (rest []byte, err error) {
	return ctx.DecodeWithOptions(data, obj, "")
}
func (ctx *Context) DecodeWithOptions(data []byte, obj interface{}, options string) (rest []byte, err error) {
	opts, err := parseOptions(options)
	if err != nil {
		return nil, err
	}
	value := reflect.ValueOf(obj)
	switch value.Kind() {
	case reflect.Ptr, reflect.Interface:
		value = value.Elem()
	}
	if !value.CanSet() {
		return nil, syntaxError("go type '%s' is read-only", value.Type())
	}
	reader := bytes.NewBuffer(data)
	err = ctx.decode(reader, value, opts)
	if err != nil {
		return nil, err
	}
	return reader.Bytes(), nil
}