func (oid Oid) Cmp(other Oid) int {
	for i, n := range oid {
		if i >= len(other) {
			return 1
		}
		if n != other[i] {
			return int(n) - int(other[i])
		}
	}
	return len(oid) - len(other)
}
Cmp returns zero if both Oids are the same, a negative value if oid
lexicographically precedes other and a positive value otherwise.
package asn1
import (
	"bytes"
	"fmt"
	"math/big"
	"reflect"
)
var (
	bigIntType = reflect.TypeOf((*big.Int)(nil))
	oidType    = reflect.TypeOf(Oid{})
	nullType   = reflect.TypeOf(Null{})
)
type encoderFunction func(reflect.Value) ([]byte, error)
type decoderFunction func([]byte, reflect.Value) error
func (ctx *Context) encodeBool(value reflect.Value) ([]byte, error) {
	if value.Kind() != reflect.Bool {
		return nil, wrongType(reflect.Bool.String(), value)
	}
	if value.Bool() {
		return []byte{0xff}, nil
	}
	return []byte{0x00}, nil
}
func (ctx *Context) decodeBool(data []byte, value reflect.Value) error {
	if !ctx.der.decoding {
		boolValue := parseBigInt(data).Cmp(big.NewInt(0)) != 0
		value.SetBool(boolValue)
		return nil
	}
	if len(data) == 1 {
		switch data[0] {
		case 0x00:
			value.SetBool(false)
			return nil
		case 0xff:
			value.SetBool(true)
			return nil
		}
	}
	return parseError("invalid bool value")
}
func (ctx *Context) encodeBigInt(value reflect.Value) ([]byte, error) {
	num, ok := value.Interface().(*big.Int)
	if !ok {
		return nil, wrongType(bigIntType.String(), value)
	}
	if num == nil {
		return []byte{0x00}, nil
	}
	var buf []byte
	if num.Sign() >= 0 {
		buf = append([]byte{0x00}, num.Bytes()...)
	} else {
		convertedNum := big.NewInt(0)
		convertedNum.Abs(num)
		convertedNum.Sub(convertedNum, big.NewInt(1))
		buf = convertedNum.Bytes()
		for i, b := range buf {
			buf[i] = ^b
		}
		buf = append([]byte{0xff}, buf...)
	}
	return removeIntLeadingBytes(buf), nil
}
func (ctx *Context) decodeBigInt(data []byte, value reflect.Value) error {
	err := checkInt(ctx, data)
	if err != nil {
		return err
	}
	i := parseBigInt(data)
	value.Set(reflect.ValueOf(i))
	return nil
}
func (ctx *Context) encodeInt(value reflect.Value) ([]byte, error) {
	switch value.Kind() {
	case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
	default:
		return nil, wrongType("signed integer", value)
	}
	n := value.Int()
	buf := make([]byte, 8)
	for i := range buf {
		shift := 8 * uint(len(buf)-i-1)
		mask := int64(0xff) << shift
		buf[i] = byte((n & mask) >> shift)
	}
	return removeIntLeadingBytes(buf), nil
}
func (ctx *Context) decodeInt(data []byte, value reflect.Value) error {
	err := checkInt(ctx, data)
	if err != nil {
		return err
	}
	if len(data) > 8 {
		return parseError("integer too large for Go type '%s'", value.Type())
	}
	extensionByte := byte(0x00)
	if len(data) > 0 && data[0]&0x80 != 0 {
		extensionByte = byte(0xff)
	}
	extension := make([]byte, 8-len(data))
	for i := range extension {
		extension[i] = extensionByte
	}
	data = append(extension, data...)
	num := int64(0)
	for i := 0; i < len(data); i++ {
		num <<= 8
		num |= int64(data[i])
	}
	value.SetInt(num)
	return nil
}
func (ctx *Context) encodeUint(value reflect.Value) ([]byte, error) {
	switch value.Kind() {
	case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64:
	default:
		return nil, wrongType("unsigned integer", value)
	}
	n := value.Uint()
	buf := make([]byte, 9)
	for i := range buf {
		shift := 8 * uint(len(buf)-i-1)
		mask := uint64(0xff) << shift
		buf[i] = byte((n & mask) >> shift)
	}
	return removeIntLeadingBytes(buf), nil
}
func (ctx *Context) decodeUint(data []byte, value reflect.Value) error {
	err := checkInt(ctx, data)
	if err != nil {
		return err
	}
	if len(data) > 8 {
		return parseError("integer too large for Go type '%s'", value.Type())
	}
	if len(data) > 0 && data[0]&0x80 != 0 {
		return parseError("negative integer can't be assigned to Go type '%s'", value.Type())
	}
	num := uint64(0)
	for i := 0; i < len(data); i++ {
		num <<= 8
		num |= uint64(data[i])
	}
	value.SetUint(num)
	return nil
}
func (ctx *Context) encodeOctetString(value reflect.Value) ([]byte, error) {
	kind := value.Kind()
	if !(kind == reflect.Array || kind == reflect.Slice) &&
		value.Type().Elem().Kind() == reflect.Uint8 {
		return nil, wrongType("array or slice of bytes", value)
	}
	if kind == reflect.Slice {
		return value.Interface().([]byte), nil
	}
	data := make([]byte, value.Len())
	for i := 0; i < value.Len(); i++ {
		data[i] = value.Index(i).Interface().(byte)
	}
	return data, nil
}
func (ctx *Context) decodeOctetString(data []byte, value reflect.Value) error {
	kind := value.Kind()
	if !(kind == reflect.Array || kind == reflect.Slice) &&
		value.Type().Elem().Kind() == reflect.Uint8 {
		return wrongType("array or slice of bytes", value)
	}
	if value.Kind() == reflect.Array {
		if len(data) != value.Len() {
			t := fmt.Sprintf("[%d]uint8", value.Len())
			return wrongType(t, value)
		}
		dest := value.Slice(0, value.Len()).Interface().([]byte)
		copy(dest, data)
	} else {
		value.Set(reflect.ValueOf(append([]byte{}, data...)))
	}
	return nil
}
func (ctx *Context) encodeString(value reflect.Value) ([]byte, error) {
	if value.Kind() != reflect.String {
		return nil, wrongType(reflect.String.String(), value)
	}
	return []byte(value.String()), nil
}
func (ctx *Context) decodeString(data []byte, value reflect.Value) error {
	s := string(data)
	value.SetString(s)
	return nil
}
type Oid []uint