-
Notifications
You must be signed in to change notification settings - Fork 0
/
list.go
48 lines (38 loc) · 1019 Bytes
/
list.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
// SPDX-FileCopyrightText: 2018 Joern Barthel <[email protected]>
// SPDX-License-Identifier: Apache-2.0
package ykoath
import (
"fmt"
)
// Name encapsulates the result of the "LIST" instruction
type Name struct {
Algorithm Algorithm
Type Type
Name string
}
// String returns a string representation of the algorithm
func (n *Name) String() string {
return fmt.Sprintf("%s (%s %s)", n.Name, n.Algorithm.String(), n.Type.String())
}
// List sends a "LIST" instruction, return a list of OATH credentials
func (c *Card) List() ([]*Name, error) {
var names []*Name
tvs, err := c.send(insList, 0x00, 0x00)
if err != nil {
return nil, err
}
for _, tv := range tvs {
switch tv.Tag {
case tagNameList:
name := &Name{
Algorithm: Algorithm(tv.Value[0] & 0x0f),
Name: string(tv.Value[1:]),
Type: Type(tv.Value[0] & 0xf0),
}
names = append(names, name)
default:
return nil, fmt.Errorf("%w (%#x)", errUnknownTag, tv.Tag)
}
}
return names, nil
}