From 26006592a75df616eed5f9214348c94687991f8d Mon Sep 17 00:00:00 2001 From: Dimitri Sokolyuk Date: Thu, 10 Dec 2015 16:39:12 +0100 Subject: Add helper contact --- account.go | 14 +++++++++++--- client.go | 2 ++ contact.go | 13 +++++++++++++ messages.go | 10 +++++----- registration.go | 2 +- 5 files changed, 32 insertions(+), 9 deletions(-) create mode 100644 contact.go 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, -- cgit v1.2.3