-
Notifications
You must be signed in to change notification settings - Fork 0
/
com.go
64 lines (49 loc) · 1.24 KB
/
com.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package gmrtd
import (
"bytes"
"fmt"
"slices"
)
const COMTag = 0x60
// Note: EF.COM is largely deprecated by EF.SOD, to access LDS/Unicode version the helpers on Document
// should be used as these will give priority to data within EF.SOD
type COM struct {
RawData []byte
LdsVersion string
UnicodeVersion string
TagList []TlvTag
}
func NewCOM(data []byte) (*COM, error) {
if len(data) < 1 {
return nil, nil
}
var out *COM = new(COM)
out.RawData = slices.Clone(data)
nodes := TlvDecode(out.RawData)
rootNode := nodes.GetNode(COMTag)
if !rootNode.IsValidNode() {
return nil, fmt.Errorf("root node (%x) missing", COMTag)
}
// LDS version
out.LdsVersion = string(rootNode.GetNode(0x5F01).GetValue())
if len(out.LdsVersion) != 4 {
return nil, fmt.Errorf("LdsVersion must be 4 characters")
}
// Unicode version
out.UnicodeVersion = string(rootNode.GetNode(0x5F36).GetValue())
if len(out.UnicodeVersion) != 6 {
return nil, fmt.Errorf("UnicodeVersion must be 6 characters")
}
// Tag list
{
tagListBytes := rootNode.GetNode(0x5C).GetValue()
buf := bytes.NewBuffer(tagListBytes)
for {
if buf.Len() <= 0 {
break
}
out.TagList = append(out.TagList, TlvGetTag(buf))
}
}
return out, nil
}