forked from yawn/ykoath
-
Notifications
You must be signed in to change notification settings - Fork 2
/
put.go
47 lines (36 loc) · 1.02 KB
/
put.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 ykoath
import "encoding/binary"
// Put sends a "PUT" instruction, storing a new / overwriting an existing OATH
// credentials with an algorithm and type, 6 or 8 digits one-time password,
// shared secrets and touch-required bit
func (o *OATH) Put(name string, a Algorithm, t Type, digits uint8, key []byte, touch bool, increasing bool, counter uint32) error {
var (
alg = (0xf0|byte(a))&0x0f | byte(t)
dig = digits
prp []byte
imf []byte
)
if touch || increasing {
var b2i = map[bool]byte{false: 0, true: 1}
prp = write(0x78, []byte{b2i[touch]<<1 | b2i[increasing]})
}
if counter != 0 {
imfVal := make([]byte, 4)
binary.BigEndian.PutUint32(imfVal, counter)
imf = write(0x7A, imfVal)
}
_, err := o.send(0x00, 0x01, 0x00, 0x00,
write(0x71, []byte(name)),
write(0x73, []byte{alg, dig}, key),
prp,
imf,
)
return err
}
func (o *OATH) Rename(oldName, newName string) error {
_, err := o.send(0x00, 0x05, 0x00, 0x00,
write(0x71, []byte(oldName)),
write(0x71, []byte(newName)),
)
return err
}