aboutsummaryrefslogtreecommitdiff
path: root/crypto.go
diff options
context:
space:
mode:
Diffstat (limited to 'crypto.go')
-rw-r--r--crypto.go37
1 files changed, 30 insertions, 7 deletions
diff --git a/crypto.go b/crypto.go
index c0fbfd0..c8fc656 100644
--- a/crypto.go
+++ b/crypto.go
@@ -13,6 +13,15 @@ import (
"path"
)
+func LoadKeyFile(fname string) (*rsa.PrivateKey, error) {
+ fd, err := os.Open(fname)
+ if err != nil {
+ return nil, err
+ }
+ defer fd.Close()
+ return LoadKey(fd)
+}
+
func LoadKey(r io.Reader) (*rsa.PrivateKey, error) {
der, err := ioutil.ReadAll(r)
if err != nil {
@@ -54,21 +63,35 @@ func NewCSR(altnames []string, key *rsa.PrivateKey) (string, error) {
return base64.RawURLEncoding.EncodeToString(der), nil
}
-func SaveCert(w io.Writer, crt *x509.Certificate) error {
- block := &pem.Block{
- Type: "CERTIFICATE",
- Bytes: crt.Raw,
+func SaveCert(w io.Writer, crt []*x509.Certificate) error {
+ for _, c := range crt {
+ block := &pem.Block{
+ Type: "CERTIFICATE",
+ Bytes: c.Raw,
+ }
+ if err := pem.Encode(w, block); err != nil {
+ return err
+ }
}
- return pem.Encode(w, block)
+ return nil
+}
+
+func LoadCertFile(fname string) ([]*x509.Certificate, error) {
+ fd, err := os.Open(fname)
+ if err != nil {
+ return nil, err
+ }
+ defer fd.Close()
+ return LoadCert(fd)
}
-func LoadCert(r io.Reader) (*x509.Certificate, error) {
+func LoadCert(r io.Reader) ([]*x509.Certificate, error) {
der, err := ioutil.ReadAll(r)
if err != nil {
return nil, err
}
block, _ := pem.Decode(der)
- return x509.ParseCertificate(block.Bytes)
+ return x509.ParseCertificates(block.Bytes)
}
func CreateKeyFile(fname string) (io.WriteCloser, error) {