2020-08-01 23:59:20 +00:00
|
|
|
package xkeypairs
|
2020-07-25 09:13:19 +00:00
|
|
|
|
2020-08-01 07:32:17 +00:00
|
|
|
import (
|
2020-09-16 22:32:46 +00:00
|
|
|
"io/ioutil"
|
2020-08-01 07:32:17 +00:00
|
|
|
|
|
|
|
"git.rootprojects.org/root/keypairs"
|
|
|
|
)
|
|
|
|
|
2020-08-01 23:59:20 +00:00
|
|
|
// ParsePEMPrivateKey will parse a PEM Private Key (or JWK or DER) but in future versions will fail to parse other key input types
|
2020-08-01 07:32:17 +00:00
|
|
|
func ParsePEMPrivateKey(block []byte) (keypairs.PrivateKey, error) {
|
|
|
|
// TODO do not parse DER or JWK
|
|
|
|
return keypairs.ParsePrivateKey(block)
|
|
|
|
}
|
2020-07-25 09:13:19 +00:00
|
|
|
|
2020-09-16 22:32:46 +00:00
|
|
|
// ParsePrivateKeyFile returns the private key from the given file path, if available
|
|
|
|
func ParsePrivateKeyFile(pathname string) (keypairs.PrivateKey, error) {
|
|
|
|
block, err := ioutil.ReadFile(pathname)
|
2020-07-25 09:13:19 +00:00
|
|
|
if nil != err {
|
2020-09-16 22:32:46 +00:00
|
|
|
return nil, err
|
2020-07-25 09:13:19 +00:00
|
|
|
}
|
2020-09-16 22:32:46 +00:00
|
|
|
return keypairs.ParsePrivateKey(block)
|
2020-07-25 09:13:19 +00:00
|
|
|
}
|