/
unseal.go
52 lines (40 loc) · 976 Bytes
/
unseal.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
package client
import (
"encoding/json"
"io/ioutil"
"strings"
"github.com/mdouchement/standardfile/pkg/libsf"
"github.com/pkg/errors"
)
// Unseal decrypt your backuped notes.
func Unseal(filename string) error {
cfg, err := Load()
if err != nil {
return errors.Wrap(err, "could not load config")
}
//
//
data, err := ioutil.ReadFile(filename)
if err != nil {
return errors.Wrap(err, "could not load file")
}
sync := libsf.NewSyncItems()
if err = json.Unmarshal(data, &sync.Retrieved); err != nil {
return errors.Wrap(err, "could not parse backuped notes")
}
//
//
var notes []libsf.Note
for _, rt := range sync.Retrieved {
if rt.ContentType != libsf.ContentTypeNote {
continue
}
err = rt.Unseal(cfg.Mk, cfg.Ak)
if err != nil {
return errors.Wrap(err, "could not unseal item")
}
notes = append(notes, *rt.Note)
}
err = backup(notes, strings.Replace(filename, "items_", "notes_", 1))
return errors.Wrap(err, "notes")
}