aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2015-12-10 16:39:12 +0100
committerDimitri Sokolyuk <demon@dim13.org>2015-12-10 16:39:12 +0100
commit26006592a75df616eed5f9214348c94687991f8d (patch)
tree2f529b3ca2532cc1b88568822457de5edc962ef9
parent32215b65656e77c2064fd0f0318bbc30ca96ce29 (diff)
Add helper contact
-rw-r--r--account.go14
-rw-r--r--client.go2
-rw-r--r--contact.go13
-rw-r--r--messages.go10
-rw-r--r--registration.go2
5 files changed, 32 insertions, 9 deletions
diff --git a/account.go b/account.go
index 33f4e12..c0f76a1 100644
--- a/account.go
+++ b/account.go
@@ -14,15 +14,23 @@ const KeySize = 2048
// Account ...
type Account struct {
- Contact []string `json:"contact"`
+ Contact []Contact `json:"contact"`
PrivKey *rsa.PrivateKey `json:"key"`
signer jose.Signer
nonce chan string
}
+func newMail(email string) (Mail, error) {
+ m, err := mail.ParseAddress(email)
+ if err != nil {
+ return "", err
+ }
+ return Mail(m.Address), nil
+}
+
// NewAccount ...
func NewAccount(email string, bits int) (*Account, error) {
- m, err := mail.ParseAddress(email)
+ m, err := newMail(email)
if err != nil {
return nil, err
}
@@ -31,7 +39,7 @@ func NewAccount(email string, bits int) (*Account, error) {
return nil, err
}
return &Account{
- Contact: []string{"mailto:" + m.Address},
+ Contact: []Contact{m},
PrivKey: key,
}, nil
}
diff --git a/client.go b/client.go
index 238543c..c615066 100644
--- a/client.go
+++ b/client.go
@@ -4,6 +4,7 @@ import (
"bytes"
"encoding/json"
"errors"
+ "log"
"net/http"
"net/textproto"
"regexp"
@@ -75,6 +76,7 @@ func (c *Client) Post(s Signer, uri string, v interface{}) (*http.Response, erro
if err != nil {
return nil, err
}
+ log.Println(string(body))
signed, err := s.Sign(body, c)
if err != nil {
diff --git a/contact.go b/contact.go
new file mode 100644
index 0000000..ea0b780
--- /dev/null
+++ b/contact.go
@@ -0,0 +1,13 @@
+package acme
+
+import "encoding"
+
+type Mail string
+type Phone string
+
+type Contact interface {
+ encoding.TextMarshaler
+}
+
+func (m Mail) MarshalText() ([]byte, error) { return []byte("mailto:" + m), nil }
+func (ph Phone) MarshalText() ([]byte, error) { return []byte("tel:" + ph), nil }
diff --git a/messages.go b/messages.go
index 18fe0fb..33f5873 100644
--- a/messages.go
+++ b/messages.go
@@ -24,11 +24,11 @@ type Directory struct {
// Registration Objects
type Registration struct {
- Resource string `json:"resource"` // new-reg
- Contact []string `json:"contact,omitempty"`
- Agreement string `json:"agreement,omitempty"`
- Authorizations string `json:"authorizations,omitempty"`
- Certificates string `json:"certificates,omitempty"`
+ Resource string `json:"resource"` // new-reg
+ Contact []Contact `json:"contact,omitempty"`
+ Agreement string `json:"agreement,omitempty"`
+ Authorizations string `json:"authorizations,omitempty"`
+ Certificates string `json:"certificates,omitempty"`
}
// RegistrationResp ...
diff --git a/registration.go b/registration.go
index 1b2baf7..da492f8 100644
--- a/registration.go
+++ b/registration.go
@@ -1,6 +1,6 @@
package acme
-func NewRegistration(contact []string, r ResourceValue) Registration {
+func NewRegistration(contact []Contact, r ResourceValue) Registration {
return Registration{
Resource: r.Value(),
Contact: contact,