forked from ProtonMail/go-proton-api
-
Notifications
You must be signed in to change notification settings - Fork 4
/
link_folder_types.go
69 lines (50 loc) · 1.24 KB
/
link_folder_types.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
package proton
import (
"github.com/ProtonMail/gopenpgp/v2/crypto"
)
type CreateFolderReq struct {
ParentLinkID string
Name string
Hash string
NodeKey string
NodeHashKey string
NodePassphrase string
NodePassphraseSignature string
SignatureAddress string
}
func (createFolderReq *CreateFolderReq) SetName(name string, addrKR, nodeKR *crypto.KeyRing) error {
encNameString, err := getEncryptedName(name, addrKR, nodeKR)
if err != nil {
return err
}
createFolderReq.Name = encNameString
return nil
}
func (createFolderReq *CreateFolderReq) SetHash(name string, hashKey []byte) error {
nameHash, err := GetNameHash(name, hashKey)
if err != nil {
return err
}
createFolderReq.Hash = nameHash
return nil
}
func (createFolderReq *CreateFolderReq) SetNodeHashKey(parentNodeKey *crypto.KeyRing) error {
token, err := crypto.RandomToken(32)
if err != nil {
return err
}
tokenMessage := crypto.NewPlainMessage(token)
encToken, err := parentNodeKey.Encrypt(tokenMessage, parentNodeKey)
if err != nil {
return err
}
nodeHashKey, err := encToken.GetArmored()
if err != nil {
return err
}
createFolderReq.NodeHashKey = nodeHashKey
return nil
}
type CreateFolderRes struct {
ID string // Encrypted Link ID
}