/
setup.go
39 lines (34 loc) · 951 Bytes
/
setup.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
/*
* Cryptexly - Copyleft of Xavier D. Johnson.
* me at xavierdjohnson dot com
* http://www.xavierdjohnson.net/
*
* See LICENSE.
*/
package pgp
import (
_ "crypto/sha256"
"github.com/detroitcybersec/cryptexly/cryptexlyd/config"
"github.com/detroitcybersec/cryptexly/cryptexlyd/utils"
_ "golang.org/x/crypto/ripemd160"
"os"
"path"
)
func Setup(pgp *config.PGPConfig) error {
pgp.Keys.Public, _ = utils.ExpandPath(pgp.Keys.Public)
if err := LoadKey(pgp.Keys.Public, false); err != nil {
return err
}
if pgp.Keys.Private == "" {
cwd, _ := os.Getwd()
pgp.Keys.Private = path.Join(cwd, "cryptexlyd-pgp-private.key")
}
pgp.Keys.Private, _ = utils.ExpandPath(pgp.Keys.Private)
public := path.Join(path.Dir(pgp.Keys.Private), "cryptexlyd-pgp-public.key")
if utils.Exists(pgp.Keys.Private) == false {
if err := GenerateKeys(pgp.Keys.Private, public); err != nil {
return err
}
}
return LoadKey(pgp.Keys.Private, true)
}