aboutsummaryrefslogtreecommitdiff
path: root/crypto.go
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2016-01-19 02:26:06 +0100
committerDimitri Sokolyuk <demon@dim13.org>2016-01-19 02:26:06 +0100
commit347aee40f3dc38122f3cf1144673db089e71512c (patch)
treebf6e569302ec93a57443ef1040a7d51f104a3b99 /crypto.go
parent87f07899673323164bd5ba5e47109144d8f0d2df (diff)
crpyto.PrivateKey
Diffstat (limited to 'crypto.go')
-rw-r--r--crypto.go24
1 files changed, 20 insertions, 4 deletions
diff --git a/crypto.go b/crypto.go
index f857a78..cbe47fd 100644
--- a/crypto.go
+++ b/crypto.go
@@ -1,6 +1,8 @@
package acme
import (
+ "crypto"
+ "crypto/ecdsa"
"crypto/rsa"
"crypto/x509"
"encoding/pem"
@@ -28,10 +30,24 @@ func LoadKey(r io.Reader) (*rsa.PrivateKey, error) {
return x509.ParsePKCS1PrivateKey(block.Bytes)
}
-func SaveKey(w io.Writer, key *rsa.PrivateKey) error {
- block := &pem.Block{
- Type: "RSA PRIVATE KEY",
- Bytes: x509.MarshalPKCS1PrivateKey(key),
+func SaveKey(w io.Writer, key crypto.PrivateKey) error {
+ var block *pem.Block
+ switch k := key.(type) {
+ case *rsa.PrivateKey:
+ der := x509.MarshalPKCS1PrivateKey(k)
+ block = &pem.Block{
+ Type: "RSA PRIVATE KEY",
+ Bytes: der,
+ }
+ case *ecdsa.PrivateKey:
+ der, err := x509.MarshalECPrivateKey(k)
+ if err != nil {
+ return err
+ }
+ block = &pem.Block{
+ Type: "EC PRIVATE KEY",
+ Bytes: der,
+ }
}
return pem.Encode(w, block)
}