aboutsummaryrefslogtreecommitdiff
path: root/account.go
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2015-12-22 17:13:11 +0100
committerDimitri Sokolyuk <demon@dim13.org>2015-12-22 17:13:11 +0100
commit160a6c8f3ba267c94f4f75de1e33fe544f15769c (patch)
tree9e34f330bda914c9336184fbc136dd36a46e5f3e /account.go
parent31bfb0ae8f6ff862425da04867a3712333e2ae52 (diff)
Collapse
Diffstat (limited to 'account.go')
-rw-r--r--account.go49
1 files changed, 22 insertions, 27 deletions
diff --git a/account.go b/account.go
index e0d24b0..68dae50 100644
--- a/account.go
+++ b/account.go
@@ -2,6 +2,7 @@ package acme
import (
"crypto/rsa"
+ "errors"
"io"
"net/mail"
"strings"
@@ -20,52 +21,46 @@ type Account struct {
nonce chan string
}
-func newMail(email string) (Mail, error) {
- m, err := mail.ParseAddress(email)
- if err != nil {
- return "", err
- }
- mm := Mail(m.Address)
- return mm, nil
-}
-
-func newPhone(phone string) (Phone, error) {
- p := strings.TrimSpace(phone)
- return Phone(p), nil
-}
-
// NewAccount ...
func NewAccount(key *rsa.PrivateKey) (*Account, error) {
return &Account{PrivKey: key}, nil
}
-func (a *Account) AddMail(mail string) error {
- if m, _ := newMail(mail); m != "" {
- a.Contact = append(a.Contact, m)
+func (a *Account) AddMail(email string) error {
+ m, err := mail.ParseAddress(email)
+ if err != nil {
+ return err
}
+ a.Contact = append(a.Contact, Mail(m.Address))
return nil
}
func (a *Account) AddPhone(phone string) error {
- if ph, _ := newPhone(phone); ph != "" {
- a.Contact = append(a.Contact, ph)
+ if ph := strings.TrimSpace(phone); ph != "" {
+ a.Contact = append(a.Contact, Phone(ph))
}
return nil
}
// Signer describes a signing interface
type Signer interface {
- Sign([]byte, jose.NonceSource) (io.Reader, error)
+ Init(jose.NonceSource) error
+ Sign([]byte) (io.Reader, error)
+}
+
+func (a *Account) Init(n jose.NonceSource) error {
+ var err error
+ a.signer, err = jose.NewSigner(jose.RS256, a.PrivKey)
+ if err != nil {
+ return err
+ }
+ a.signer.SetNonceSource(n)
+ return nil
}
-func (a *Account) Sign(msg []byte, n jose.NonceSource) (io.Reader, error) {
+func (a *Account) Sign(msg []byte) (io.Reader, error) {
if a.signer == nil {
- var err error
- a.signer, err = jose.NewSigner(jose.RS256, a.PrivKey)
- if err != nil {
- return nil, err
- }
- a.signer.SetNonceSource(n)
+ return nil, errors.New("init first")
}
obj, err := a.signer.Sign(msg)
if err != nil {