aboutsummaryrefslogtreecommitdiff
path: root/account.go
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2015-12-10 17:54:35 +0100
committerDimitri Sokolyuk <demon@dim13.org>2015-12-10 17:54:35 +0100
commit48e3361e2c7018acaafd6b90b85d042f8edc620b (patch)
tree85d48a9afd62b366779fdcf110467d0451e670f9 /account.go
parent54975553c4b67d2b2d9d6edcbf18dbcbdc508fec (diff)
Play with interfaces
Diffstat (limited to 'account.go')
-rw-r--r--account.go27
1 files changed, 22 insertions, 5 deletions
diff --git a/account.go b/account.go
index 85092de..86f44cc 100644
--- a/account.go
+++ b/account.go
@@ -3,7 +3,9 @@ package acme
import (
"crypto/rand"
"crypto/rsa"
+ "encoding/json"
"fmt"
+ "io/ioutil"
"net/mail"
"github.com/square/go-jose"
@@ -14,7 +16,7 @@ const KeySize = 2048
// Account ...
type Account struct {
- Contact []Contact `json:"contact"`
+ Contact Contacts `json:"contact"`
PrivKey *rsa.PrivateKey `json:"key"`
signer jose.Signer
nonce chan string
@@ -25,7 +27,8 @@ func newMail(email string) (Mail, error) {
if err != nil {
return "", err
}
- return Mail(m.Address), nil
+ mm := Mail(m.Address)
+ return mm, nil
}
// NewAccount ...
@@ -39,13 +42,27 @@ func NewAccount(email string, bits int) (*Account, error) {
return nil, err
}
return &Account{
- Contact: []Contact{m},
+ Contact: Contacts{m},
PrivKey: key,
}, nil
}
-func LoadAccount(email string) (*Account, error) {
- return nil, nil
+func LoadAccount(fname string) (*Account, error) {
+ body, err := ioutil.ReadFile(fname)
+ if err != nil {
+ return nil, err
+ }
+ a := new(Account)
+ err = json.Unmarshal(body, a)
+ return a, err
+}
+
+func (a Account) SaveAccount(fname string) error {
+ body, err := json.MarshalIndent(a, "", "\t")
+ if err != nil {
+ return err
+ }
+ return ioutil.WriteFile(fname, body, 0600)
}
func (a *Account) Sign(msg []byte, n jose.NonceSource) ([]byte, error) {