File: address.go

package info (click to toggle)
golang-github-henrybear327-go-proton-api 1.0.0-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,088 kB
  • sloc: sh: 55; makefile: 26
file content (52 lines) | stat: -rw-r--r-- 978 bytes parent folder | download
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
package backend

import (
	"github.com/ProtonMail/gopenpgp/v2/crypto"
	"github.com/bradenaw/juniper/xslices"
	"github.com/henrybear327/go-proton-api"
)

type address struct {
	addrID   string
	email    string
	order    int
	status   proton.AddressStatus
	addrType proton.AddressType
	keys     []key
}

func (add *address) toAddress() proton.Address {
	return proton.Address{
		ID:    add.addrID,
		Email: add.email,

		Send:    true,
		Receive: true,
		Status:  add.status,
		Type:    add.addrType,

		Order:       add.order,
		DisplayName: add.email,

		Keys: xslices.Map(add.keys, func(key key) proton.Key {
			privKey, err := crypto.NewKeyFromArmored(key.key)
			if err != nil {
				panic(err)
			}

			rawKey, err := privKey.Serialize()
			if err != nil {
				panic(err)
			}

			return proton.Key{
				ID:         key.keyID,
				PrivateKey: rawKey,
				Token:      key.tok,
				Signature:  key.sig,
				Primary:    key == add.keys[0],
				Active:     true,
			}
		}),
	}
}