Skip to content

Commit 1c57d60

Browse files
committed
feat: link_file_types
Initial support for extending the link_file interfaces. This change attempts to follow pre-existing dev patterns. Extracted from fork https://github.com/henrybear327/go-proton-api
1 parent 98a73ff commit 1c57d60

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

link_file_types.go

+35
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,40 @@
11
package proton
22

3+
import (
4+
"crypto/hmac"
5+
"crypto/sha256"
6+
"encoding/hex"
7+
8+
"github.com/ProtonMail/gopenpgp/v2/crypto"
9+
)
10+
11+
/* Helper function */
12+
func getEncryptedName(name string, addrKR, nodeKR *crypto.KeyRing) (string, error) {
13+
clearTextName := crypto.NewPlainMessageFromString(name)
14+
15+
encName, err := nodeKR.Encrypt(clearTextName, addrKR)
16+
if err != nil {
17+
return "", err
18+
}
19+
20+
encNameString, err := encName.GetArmored()
21+
if err != nil {
22+
return "", err
23+
}
24+
25+
return encNameString, nil
26+
}
27+
28+
func GetNameHash(name string, hashKey []byte) (string, error) {
29+
mac := hmac.New(sha256.New, hashKey)
30+
_, err := mac.Write([]byte(name))
31+
if err != nil {
32+
return "", err
33+
}
34+
35+
return hex.EncodeToString(mac.Sum(nil)), nil
36+
}
37+
338
type CreateFileReq struct {
439
ParentLinkID string
540

0 commit comments

Comments
 (0)