Skip to content

Commit 4f12905

Browse files
committed
feat: get hash key from parent
Variation of GetHashKey() that can handle the root of the tree. Extracted from fork https://github.com/henrybear327/go-proton-api
1 parent 67bd01a commit 4f12905

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

link_types.go

+27
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,33 @@ func (l Link) GetHashKey(nodeKR *crypto.KeyRing) ([]byte, error) {
111111
return dec.GetBinary(), nil
112112
}
113113

114+
func (l Link) GetHashKeyFromParent(parentNodeKey, addrKRs *crypto.KeyRing) ([]byte, error) {
115+
if l.Type != LinkTypeFolder {
116+
return nil, errors.New("link is not a folder")
117+
}
118+
119+
enc, err := crypto.NewPGPMessageFromArmored(l.FolderProperties.NodeHashKey)
120+
if err != nil {
121+
return nil, err
122+
}
123+
124+
_, ok := enc.GetSignatureKeyIDs()
125+
var dec *crypto.PlainMessage
126+
if ok {
127+
dec, err = parentNodeKey.Decrypt(enc, addrKRs, crypto.GetUnixTime())
128+
if err != nil {
129+
return nil, err
130+
}
131+
} else {
132+
dec, err = parentNodeKey.Decrypt(enc, nil, 0)
133+
if err != nil {
134+
return nil, err
135+
}
136+
}
137+
138+
return dec.GetBinary(), nil
139+
}
140+
114141
func (l Link) GetSessionKey(nodeKR *crypto.KeyRing) (*crypto.SessionKey, error) {
115142
if l.Type != LinkTypeFile {
116143
return nil, errors.New("link is not a file")

0 commit comments

Comments
 (0)