der

package
v0.0.0-...-116e3e9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 7, 2022 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CLASS_UNIVERSAL        = 0
	CLASS_APPLICATION      = 1
	CLASS_CONTEXT_SPECIFIC = 2
	CLASS_PRIVATE          = 3
)
View Source
const (
	TAG_END_OF_CONTENT   = 0  // 0x00
	TAG_BOOLEAN          = 1  // 0x01
	TAG_INTEGER          = 2  // 0x02
	TAG_BIT_STRING       = 3  // 0x03
	TAG_OCTET_STRING     = 4  // 0x04
	TAG_NULL             = 5  // 0x05
	TAG_OID              = 6  // 0x06
	TAG_REAL             = 9  //0x09
	TAG_ENUMERATED       = 10 // 0x0A
	TAG_UTF8_STRING      = 12 // 0x0C
	TAG_TIME             = 14 // 0x0E
	TAG_SEQUENCE         = 16 // 0x10
	TAG_SET              = 17 // 0x11
	TAG_NUMBERIC_STRING  = 18 // 0x12
	TAG_PRINTABLE_STRING = 19 // 0x13
	TAG_T61_STRING       = 20 // 0x14
	TAG_VIDEOTEX_STRING  = 21 // 0x15
	TAG_IA5_STRING       = 22 // 0x16
	TAG_UTC_TIME         = 23 // 0x17
	TAG_GENERALIZED_TIME = 24 // 0x18
	TAG_BMP_STRING       = 30 // 0x1E
)

Universal types (tags) https://en.wikipedia.org/wiki/X.690#Types Permitted Construction is Primitive or Both

Variables

View Source
var (
	ErrNodeIsConstructed    = errors.New("node is constructed")
	ErrNodeIsNotConstructed = errors.New("node is not constructed")
)

Functions

func BoolDeserialize

func BoolDeserialize(n *Node, params ...Parameter) (bool, error)

func BytesDeserialize

func BytesDeserialize(n *Node, params ...Parameter) ([]byte, error)

func CheckConstructed

func CheckConstructed(n *Node, params ...Parameter) error

func CheckNode

func CheckNode(n *Node, class int, tag int) error

func ChoiceDeserializeDER

func ChoiceDeserializeDER(c Choice, n *Node, params ...Parameter) error

func ConvertToString

func ConvertToString(n *Node) (string, error)

func DecodeNode

func DecodeNode(data []byte, n *Node) (rest []byte, err error)

func Deserialize

func Deserialize(v interface{}, n *Node, params ...Parameter) error

func EncodeNode

func EncodeNode(data []byte, n *Node) (rest []byte, err error)

func EnumDeserialize

func EnumDeserialize(n *Node, params ...Parameter) (int, error)

func IntDeserialize

func IntDeserialize(n *Node, params ...Parameter) (int64, error)

func Marshal

func Marshal(v interface{}, params ...Parameter) ([]byte, error)

func NullDeserialize

func NullDeserialize(n *Node, params ...Parameter) error

func RandomUTCTime

func RandomUTCTime(r *rand.Rand) time.Time

func StringDeserialize

func StringDeserialize(n *Node, params ...Parameter) (string, error)

func UTCTimeDeserialize

func UTCTimeDeserialize(n *Node, params ...Parameter) (time.Time, error)

func UintDeserialize

func UintDeserialize(n *Node, params ...Parameter) (uint64, error)

func Unmarshal

func Unmarshal(data []byte, v interface{}, params ...Parameter) error

Types

type Choice

type Choice interface {
	GetTag() (tag int, err error)
	SetTag(tag int) error

	Value() interface{}
}

type Deserializer

type Deserializer interface {
	DeserializeDER(n *Node, params ...Parameter) error
}

type ErrorUnmarshalBytes

type ErrorUnmarshalBytes struct {
	// contains filtered or unexported fields
}

func (ErrorUnmarshalBytes) Bytes

func (e ErrorUnmarshalBytes) Bytes() []byte

func (ErrorUnmarshalBytes) Error

func (e ErrorUnmarshalBytes) Error() string

type ErrorUnmarshalInt

type ErrorUnmarshalInt struct {
	// contains filtered or unexported fields
}

func (ErrorUnmarshalInt) Error

func (e ErrorUnmarshalInt) Error() string

type ErrorUnmarshalString

type ErrorUnmarshalString struct {
	// contains filtered or unexported fields
}

func (ErrorUnmarshalString) Bytes

func (e ErrorUnmarshalString) Bytes() []byte

func (ErrorUnmarshalString) Error

func (e ErrorUnmarshalString) Error() string

type ErrorUnmarshalUint

type ErrorUnmarshalUint struct {
	// contains filtered or unexported fields
}

func (ErrorUnmarshalUint) Error

func (e ErrorUnmarshalUint) Error() string

type Explicit

type Explicit struct{}

type Name

type Name string

type Node

type Node struct {
	Data  []byte      `json:"-"`               // Primitive:   (isCompound = false)
	Value interface{} `json:"value,omitempty"` // Primitive:  int/bool/string/time... (isCompound = false)
	Nodes []*Node     `json:"nodes,omitempty"` // Constructed: (isCompound = true)
	// contains filtered or unexported fields
}

func BoolSerialize

func BoolSerialize(b bool, params ...Parameter) (*Node, error)

func BytesSerialize

func BytesSerialize(bs []byte, params ...Parameter) (*Node, error)

func ChoiceSerializeDER

func ChoiceSerializeDER(c Choice, params ...Parameter) (*Node, error)

func EnumSerialize

func EnumSerialize(e int, params ...Parameter) (*Node, error)

func IntSerialize

func IntSerialize(x int64, params ...Parameter) (*Node, error)

func NewConstructed

func NewConstructed(params ...Parameter) (n *Node)

func NewNode

func NewNode(class int, tag int) *Node
func (n *Node) MarshalJSON() ([]byte, error) {
	if !n.constructed {
		jsonKey, jsonValue, err := n.toJsonKeyValue()
		if err != nil {
			fmt.Println("MarshalJSON fail:", err)
			return nil, err
		}
		ret := `{"` + jsonKey + `":"` + jsonValue + `"},`
		return []byte(ret), nil
	} else {
		for i, child := range n.Nodes {
			if b, err := child.MarshalJSON(); err != nil {
				fmt.Println("MarshalJSON child fail:", i, err)
				return nil, err
			}
		}
	}
	return []byte(strconv.FormatFloat(float64(f), 'f', -1, 64)), nil
}

func NodeByTag

func NodeByTag(ns []*Node, tag int) *Node

func NullSerialize

func NullSerialize(params ...Parameter) (*Node, error)

func Serialize

func Serialize(v interface{}, params ...Parameter) (*Node, error)

func StringSerialize

func StringSerialize(s string, params ...Parameter) (*Node, error)

func UTCTimeSerialize

func UTCTimeSerialize(t time.Time, params ...Parameter) (*Node, error)

func UintSerialize

func UintSerialize(x uint64, params ...Parameter) (*Node, error)

func (*Node) GetBool

func (n *Node) GetBool() (bool, error)

func (*Node) GetBytes

func (n *Node) GetBytes() ([]byte, error)

func (*Node) GetClass

func (n *Node) GetClass() int

func (*Node) GetEnumerated

func (n *Node) GetEnumerated() (int64, error)

func (*Node) GetGeneralizedTime

func (n *Node) GetGeneralizedTime() (time.Time, error)

func (*Node) GetInt

func (n *Node) GetInt() (int64, error)

func (*Node) GetNodes

func (n *Node) GetNodes() ([]*Node, error)

func (*Node) GetOid

func (n *Node) GetOid() (string, error)

func (*Node) GetReal

func (n *Node) GetReal() (float64, error)

func (*Node) GetString

func (n *Node) GetString() (string, error)

func (*Node) GetTag

func (n *Node) GetTag() int

func (*Node) GetUTCTime

func (n *Node) GetUTCTime() (time.Time, error)

func (*Node) GetUint

func (n *Node) GetUint() (uint64, error)

func (*Node) IsConstructed

func (n *Node) IsConstructed() bool

func (*Node) IsPrimitive

func (n *Node) IsPrimitive() bool

func (*Node) SetBool

func (n *Node) SetBool(b bool)

func (*Node) SetBytes

func (n *Node) SetBytes(bs []byte)

func (*Node) SetInt

func (n *Node) SetInt(i int64)

func (*Node) SetNodes

func (n *Node) SetNodes(ns []*Node)

func (*Node) SetString

func (n *Node) SetString(s string)

func (*Node) SetUTCTime

func (n *Node) SetUTCTime(t time.Time) error

func (*Node) SetUint

func (n *Node) SetUint(u uint64)

type Optional

type Optional struct{}

type Parameter

type Parameter interface {
	// contains filtered or unexported methods
}

type Serializer

type Serializer interface {
	SerializeDER(params ...Parameter) (*Node, error)
}

type Tag

type Tag int

Directories

Path Synopsis
v1
v2
v3
v4

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL