-
Notifications
You must be signed in to change notification settings - Fork 0
/
berany.go
47 lines (39 loc) · 859 Bytes
/
berany.go
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 asn1ber
import (
"bytes"
"encoding/hex"
"io"
)
// BerAny Any BER object
type BerAny struct {
value []byte
}
func (b *BerAny) Decode(r io.Reader, withTagList ...bool) (int, error) {
return b.DecodeWithTag(r, nil)
}
func (b *BerAny) DecodeWithTag(r io.Reader, tag *BerTag) (int, error) {
os := &bytes.Buffer{}
byteCount := 0
if tag == nil {
tag = new(BerTag)
n, err := tag.Decode(r)
byteCount += n
if err != nil {
return byteCount, err
}
}
_, _ = tag.Encode(os)
n, err := DecodeUnknownComponent(r, os)
byteCount += n
if err != nil {
return byteCount, err
}
b.value = os.Bytes() // get the bytes
return byteCount, nil
}
func (b *BerAny) Encode(reversedWriter io.Writer, withTagList ...bool) (int, error) {
return reversedWriter.Write(b.value)
}
func (b *BerAny) S() string {
return hex.EncodeToString(b.value)
}