Debian Codegraph @

server/backend/address.go

raw
1 package backend
2
3 import (
4 "github.com/ProtonMail/gopenpgp/v2/crypto"
5 "github.com/bradenaw/juniper/xslices"
6 "github.com/henrybear327/go-proton-api"
7 )
8
9 type address struct {
10 addrID string
11 email string
12 order int
13 status proton.AddressStatus
14 addrType proton.AddressType
15 keys []key
16 }
17
18 func (add *address) toAddress() proton.Address {
19 return proton.Address{
20 ID: add.addrID,
21 Email: add.email,
22
23 Send: true,
24 Receive: true,
25 Status: add.status,
26 Type: add.addrType,
27
28 Order: add.order,
29 DisplayName: add.email,
30
31 Keys: xslices.Map(add.keys, func(key key) proton.Key {
32 privKey, err := crypto.NewKeyFromArmored(key.key)
33 if err != nil {
34 panic(err)
35 }
36
37 rawKey, err := privKey.Serialize()
38 if err != nil {
39 panic(err)
40 }
41
42 return proton.Key{
43 ID: key.keyID,
44 PrivateKey: rawKey,
45 Token: key.tok,
46 Signature: key.sig,
47 Primary: key == add.keys[0],
48 Active: true,
49 }
50 }),
51 }
52 }