aboutsummaryrefslogtreecommitdiff
path: root/client.go
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2015-12-04 17:40:32 +0100
committerDimitri Sokolyuk <demon@dim13.org>2015-12-04 17:40:32 +0100
commit605b1310fb6e1c1fa1382df76a1d52954fc82ba7 (patch)
treec5228d10b35829114f375ef37e1be43a1a2b0047 /client.go
parentb87c51d9fd46e446c620b13bf8e8c91f665fe8f4 (diff)
Update Signer
Diffstat (limited to 'client.go')
-rw-r--r--client.go57
1 files changed, 36 insertions, 21 deletions
diff --git a/client.go b/client.go
index b596906..27551ba 100644
--- a/client.go
+++ b/client.go
@@ -3,27 +3,52 @@ package acme
import (
"bytes"
"encoding/json"
+ "errors"
"log"
"net/http"
"net/textproto"
"regexp"
+)
+
+type Status int
- "github.com/square/go-jose"
+const (
+ StatusUnknown Status = iota
+ StatusPending
+ StatusProcessing
+ StatusValid
+ StatusInvalid
+ StatusRevoked
)
+func (s *Status) UnmarshalJSON(b []byte) error {
+ var status = map[string]Status{
+ "unknown": StatusUnknown,
+ "pending": StatusPending,
+ "processing": StatusProcessing,
+ "valid": StatusValid,
+ "invalid": StatusInvalid,
+ "revoked": StatusRevoked,
+ }
+ if st, ok := status[string(b)]; ok {
+ *s = st
+ return nil
+ }
+ return errors.New("unknown status")
+}
+
type Signer interface {
Sign([]byte) ([]byte, error)
+ parseNonce(*http.Response)
}
-var nonces = newNonce()
-
-func Get(uri string, v interface{}) error {
+func Get(s Signer, uri string, v interface{}) error {
resp, err := http.Get(uri)
if err != nil {
return err
}
defer resp.Body.Close()
- nonces.parse(resp)
+ s.parseNonce(resp)
return json.NewDecoder(resp.Body).Decode(v)
}
@@ -43,31 +68,21 @@ func Post(s Signer, uri string, v interface{}) (*http.Response, error) {
return nil, err
}
- resp, err := http.Post(uri, "application/jose+json", bytes.NewReader(signed))
+ resp, err := http.Post(uri, "application/jose+json",
+ bytes.NewReader(signed))
if err != nil {
return nil, err
}
- nonces.parse(resp)
- log.Printf("%+v\n", parseLinks(resp))
+
+ s.parseNonce(resp)
if resp.StatusCode >= http.StatusBadRequest {
return nil, handleError(resp)
}
- return resp, nil
-}
+ log.Printf("%+v\n", parseLinks(resp))
-func Sign(acc Account, body []byte) (string, error) {
- signer, err := jose.NewSigner(jose.RS256, acc.PrivKey)
- signer.SetNonceSource(nonces)
- if err != nil {
- return "", err
- }
- obj, err := signer.Sign(body)
- if err != nil {
- return "", err
- }
- return obj.FullSerialize(), nil
+ return resp, nil
}
func parseLinks(r *http.Response) map[string]string {