-
-
Notifications
You must be signed in to change notification settings - Fork 17
/
v2_payloads.go
49 lines (37 loc) · 1.05 KB
/
v2_payloads.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
package paseto
import t "aidanwoods.dev/go-result"
type v2PublicPayload struct {
message []byte
signature [64]byte
}
func (p v2PublicPayload) bytes() []byte {
return append(p.message, p.signature[:]...)
}
func newV2PublicPayload(bytes []byte) t.Result[v2PublicPayload] {
signatureOffset := len(bytes) - 64
if signatureOffset < 0 {
return t.Err[v2PublicPayload](errorPayloadShort)
}
message := make([]byte, len(bytes)-64)
copy(message, bytes[:signatureOffset])
var signature [64]byte
copy(signature[:], bytes[signatureOffset:])
return t.Ok(v2PublicPayload{message, signature})
}
type v2LocalPayload struct {
nonce [24]byte
cipherText []byte
}
func (p v2LocalPayload) bytes() []byte {
return append(p.nonce[:], p.cipherText...)
}
func newV2LocalPayload(bytes []byte) t.Result[v2LocalPayload] {
if len(bytes) <= 24 {
return t.Err[v2LocalPayload](errorPayloadShort)
}
var nonce [24]byte
copy(nonce[:], bytes[0:24])
cipherText := make([]byte, len(bytes)-24)
copy(cipherText, bytes[24:])
return t.Ok(v2LocalPayload{nonce, cipherText})
}