-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathutils.go
More file actions
34 lines (28 loc) · 745 Bytes
/
Copy pathutils.go
File metadata and controls
34 lines (28 loc) · 745 Bytes
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
package main
import (
"errors"
"io/ioutil"
p2pcrypto "github.com/libp2p/go-libp2p-crypto"
)
const ProxyIDHeader = "Proxy-ID"
const ProxySignatureHeader = "Proxy-Signature"
var ErrEmptyPrivateKeyPath = errors.New("empty path to private key provided, a valid path is necessary")
func getPrivateKey(path string) (p2pcrypto.PrivKey, error) {
if path == "" {
return nil, ErrEmptyPrivateKeyPath
}
// Otherwise parse the key at the path given.
keyBytes, err := ioutil.ReadFile(path)
if err != nil {
return nil, err
}
decodedKey, err := p2pcrypto.ConfigDecodeKey(string(keyBytes))
if err != nil {
return nil, err
}
priv, err := p2pcrypto.UnmarshalPrivateKey(decodedKey)
if err != nil {
return nil, err
}
return priv, nil
}