forked from yawn/ykoath
-
Notifications
You must be signed in to change notification settings - Fork 2
/
code.go
36 lines (28 loc) · 816 Bytes
/
code.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
package ykoath
import (
"bytes"
"fmt"
)
// code encapsulates (some) response codes from the spec
type code []byte
// Error return the encapsulated error string
func (c code) Error() string {
if bytes.Equal(c, []byte{0x6a, 0x80}) {
return "wrong syntax"
} else if bytes.Equal(c, []byte{0x69, 0x84}) {
return "no such object"
} else if bytes.Equal(c, []byte{0x69, 0x82}) {
return "auth required"
} else if bytes.Equal(c, []byte{0x69, 0x85}) {
return "conditions not satisfied"
}
return fmt.Sprintf("unknown (% x)", []byte(c))
}
// IsMore indicates more data that needs to be fetched
func (c code) IsMore() bool {
return len(c) == 2 && c[0] == 0x61
}
// IsSuccess indicates that all data has been successfully fetched
func (c code) IsSuccess() bool {
return bytes.Equal([]byte{0x90, 00}, c)
}