aboutsummaryrefslogtreecommitdiff
path: root/crypto.go
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2016-06-05 02:09:33 +0200
committerDimitri Sokolyuk <demon@dim13.org>2016-06-05 02:09:33 +0200
commit2915c9453086366c970c9ab602f2ec670ca29234 (patch)
treefef792034e861fdbbad8814603e4e07c2e61201d /crypto.go
parentd3bd76f5c8a0509869e749e13d6a6edafdd3af66 (diff)
Extract Thumb
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 {