aboutsummaryrefslogtreecommitdiff
path: root/rose/rose.go
blob: 1e670cc3face7c9380e93aef3d590b32baee3e3a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package rose

import "github.com/dim13/asn1"

// 2.4.6.0

// Invoke is Context-specific Constructed 1
type Invoke struct {
	asn1.Tag      `asn1:"tag:1"`
	InvokeID      int
	Opcode        int `asn1:"optional"`
	asn1.RawValue `asn1:"optional"`
}

type Result struct {
	Opcode        int `asn1:"optional"`
	asn1.RawValue `asn1:"optional"`
}

// ReturnResult it Context-specific Constructed 2
type ReturnResult struct {
	asn1.Tag `asn1:"tag:2"`
	InvokeID int
	Result   `asn1:"optional,expicit"`
}

func Unmarshal(b []byte) (int, int, []byte, error) {
	v := &Invoke{}
	_, err := asn1.Unmarshal(b, v)
	if err != nil {
		return 0, 0, nil, err
	}
	return v.InvokeID, v.Opcode, v.RawValue.FullBytes, nil
}

func Marshal(id, opcode int, b []byte) ([]byte, error) {
	v := ReturnResult{
		InvokeID: id,
		Result: Result{
			Opcode: opcode,
			RawValue: asn1.RawValue{
				FullBytes: b,
			},
		},
	}
	return asn1.Marshal(v)
}