/
token_request.go
57 lines (45 loc) · 1.02 KB
/
token_request.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
package type2
import (
"bytes"
"golang.org/x/crypto/cryptobyte"
)
var (
BasicPublicTokenType = uint16(0x0002)
)
type BasicPublicTokenRequest struct {
raw []byte
TokenKeyID uint8
BlindedReq []byte // 256 bytes
}
func (r BasicPublicTokenRequest) Type() uint16 {
return BasicPublicTokenType
}
func (r BasicPublicTokenRequest) Equal(r2 BasicPublicTokenRequest) bool {
if r.TokenKeyID == r2.TokenKeyID &&
bytes.Equal(r.BlindedReq, r2.BlindedReq) {
return true
}
return false
}
func (r *BasicPublicTokenRequest) Marshal() []byte {
if r.raw != nil {
return r.raw
}
b := cryptobyte.NewBuilder(nil)
b.AddUint16(BasicPublicTokenType)
b.AddUint8(r.TokenKeyID)
b.AddBytes(r.BlindedReq)
r.raw = b.BytesOrPanic()
return r.raw
}
func (r *BasicPublicTokenRequest) Unmarshal(data []byte) bool {
s := cryptobyte.String(data)
var tokenType uint16
if !s.ReadUint16(&tokenType) ||
tokenType != BasicPublicTokenType ||
!s.ReadUint8(&r.TokenKeyID) ||
!s.ReadBytes(&r.BlindedReq, 256) {
return false
}
return true
}