-
Notifications
You must be signed in to change notification settings - Fork 16
/
keys.go
62 lines (49 loc) · 1.72 KB
/
keys.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
package proton
import (
"context"
"github.com/go-resty/resty/v2"
)
func (c *Client) GetPublicKeys(ctx context.Context, address string) (PublicKeys, RecipientType, error) {
var res struct {
Keys []PublicKey
RecipientType RecipientType
}
if err := c.do(ctx, func(r *resty.Request) (*resty.Response, error) {
return r.SetResult(&res).SetQueryParam("Email", address).Get("/core/v4/keys")
}); err != nil {
return nil, RecipientTypeExternal, err
}
return res.Keys, res.RecipientType, nil
}
func (c *Client) CreateAddressKey(ctx context.Context, req CreateAddressKeyReq) (Key, error) {
var res struct {
Key Key
}
if err := c.do(ctx, func(r *resty.Request) (*resty.Response, error) {
return r.SetBody(req).SetResult(&res).Post("/core/v4/keys/address")
}); err != nil {
return Key{}, err
}
return res.Key, nil
}
func (c *Client) CreateLegacyAddressKey(ctx context.Context, req CreateAddressKeyReq) (Key, error) {
var res struct {
Key Key
}
if err := c.do(ctx, func(r *resty.Request) (*resty.Response, error) {
return r.SetBody(req).SetResult(&res).Post("/core/v4/keys")
}); err != nil {
return Key{}, err
}
return res.Key, nil
}
func (c *Client) MakeAddressKeyPrimary(ctx context.Context, keyID string, keyList KeyList) error {
return c.do(ctx, func(r *resty.Request) (*resty.Response, error) {
return r.SetBody(struct{ SignedKeyList KeyList }{SignedKeyList: keyList}).Put("/core/v4/keys/" + keyID + "/primary")
})
}
func (c *Client) DeleteAddressKey(ctx context.Context, keyID string, keyList KeyList) error {
return c.do(ctx, func(r *resty.Request) (*resty.Response, error) {
return r.SetBody(struct{ SignedKeyList KeyList }{SignedKeyList: keyList}).Post("/core/v4/keys/" + keyID + "/delete")
})
}