-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathisv.go
57 lines (44 loc) · 1.13 KB
/
isv.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 srp
import (
"bytes"
"io"
)
// ISV holds the triplet of the Identity, Salt, and Verifier. It implements
// encoding.BinaryMarshaler and encoding.BinaryUnmarshaler so it can be
// serialized to and from persistent storage.
type ISV struct {
Identity []byte `json:"identity"`
Salt []byte `json:"salt"`
Verifier []byte `json:"verifier"`
}
// MarshalBinary satisfies the encoding.BinaryMarshaler interface.
func (i *ISV) MarshalBinary() ([]byte, error) {
b := new(bytes.Buffer)
if err := writeBytes(b, i.Identity); err != nil {
return nil, err
}
if err := writeBytes(b, i.Salt); err != nil {
return nil, err
}
if err := writeBytes(b, i.Verifier); err != nil {
return nil, err
}
return b.Bytes(), nil
}
// UnmarshalBinary satisfies the encoding.BinaryUnmarshaler interface.
func (i *ISV) UnmarshalBinary(b []byte) (err error) {
r := bytes.NewReader(b)
if i.Identity, err = readBytes(r); err != nil {
return
}
if i.Salt, err = readBytes(r); err != nil {
return
}
if i.Verifier, err = readBytes(r); err != nil {
return
}
if n, _ := io.CopyN(io.Discard, r, 1); n > 0 {
return ErrTrailingBytes
}
return nil
}