-
Notifications
You must be signed in to change notification settings - Fork 0
/
revocationrequest.go
71 lines (61 loc) · 2.08 KB
/
revocationrequest.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package document
import (
"encoding/json"
"time"
"gopkg.in/square/go-jose.v1"
)
const RevocationRequestType = SchemaLocation + "/revocation-request.json"
type RevocationRequest struct {
Base
SignedDocument *jose.JsonWebSignature `json:"jws"` // The signature from this document is to be revoked
RevocationChecksum *jose.JsonWebSignature `json:"revocationchecksum"` // The hashed SignedDocument wrapped in a jws signed by the same key
Priority int `json:"priority"`
}
func NewRevocationRequest(jws, checksum *jose.JsonWebSignature, prio int) *RevocationRequest {
r := &RevocationRequest{
Base: Base{
Type: RevocationRequestType,
Timestamp: time.Now().UTC(),
},
SignedDocument: jws,
RevocationChecksum: checksum,
Priority: prio,
}
return r
}
func (r *RevocationRequest) MarshalJSON() ([]byte, error) {
return json.Marshal(&struct {
Base
SignedDocument string `json:"jws"` // The signature from this document is to be revoked
RevocationChecksum string `json:"revocationchecksum"` // The hashed SignedDocument wrapped in a jws signed by the same key
Priority int `json:"priority"`
}{
Base: r.Base,
SignedDocument: r.SignedDocument.FullSerialize(),
RevocationChecksum: r.RevocationChecksum.FullSerialize(),
Priority: r.Priority,
})
}
func (r *RevocationRequest) UnmarshalJSON(data []byte) error {
aux := &struct {
Base
SignedDocument string `json:"jws"` // The signature from this document is to be revoked
RevocationChecksum string `json:"revocationchecksum"` // The hashed SignedDocument wrapped in a jws signed by the same key
Priority int `json:"priority"`
}{}
if err := json.Unmarshal(data, &aux); err != nil {
return err
}
var err error
r.Base = aux.Base
r.SignedDocument, err = jose.ParseSigned(aux.SignedDocument)
if err != nil {
return err
}
r.RevocationChecksum, err = jose.ParseSigned(aux.RevocationChecksum)
if err != nil {
return err
}
r.Priority = aux.Priority
return nil
}