aboutsummaryrefslogtreecommitdiff
path: root/crypto.go
diff options
context:
space:
mode:
Diffstat (limited to 'crypto.go')
-rw-r--r--crypto.go19
1 files changed, 19 insertions, 0 deletions
diff --git a/crypto.go b/crypto.go
index d9384b1..39c48fe 100644
--- a/crypto.go
+++ b/crypto.go
@@ -14,6 +14,7 @@ import (
"errors"
"io"
"io/ioutil"
+ "os"
)
const (
@@ -50,6 +51,15 @@ func SaveKey(w io.Writer, key crypto.PrivateKey) error {
return pem.Encode(w, block)
}
+func LoadKeyFile(fname string) (crypto.PrivateKey, error) {
+ fd, err := os.Open(fname)
+ if err != nil {
+ return nil, err
+ }
+ defer fd.Close()
+ return LoadKey(fd)
+}
+
func LoadKey(r io.Reader) (crypto.PrivateKey, error) {
der, err := ioutil.ReadAll(r)
if err != nil {
@@ -71,6 +81,15 @@ func SaveCert(w io.Writer, cert []byte) error {
return pem.Encode(w, block)
}
+func LoadCertFile(fname string) ([]*x509.Certificate, error) {
+ fd, err := os.Open(fname)
+ if err != nil {
+ return nil, err
+ }
+ defer fd.Close()
+ return LoadCerts(fd)
+}
+
func LoadCerts(r io.Reader) ([]*x509.Certificate, error) {
der, err := ioutil.ReadAll(r)
if err != nil {