aboutsummaryrefslogtreecommitdiff
path: root/client.go
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2015-11-27 18:14:26 +0100
committerDimitri Sokolyuk <demon@dim13.org>2015-11-27 18:14:26 +0100
commit01bd20286a53827714ad819a1c2f57d28a116156 (patch)
treee900b49285e468c8901e733b7b87e4e7590ae0fa /client.go
parent0456617941c2508cf128a04ebfb58c8d2169586f (diff)
wip
Diffstat (limited to 'client.go')
-rw-r--r--client.go28
1 files changed, 17 insertions, 11 deletions
diff --git a/client.go b/client.go
index 8f7138a..e99bb74 100644
--- a/client.go
+++ b/client.go
@@ -3,24 +3,34 @@ package acme
import (
"bytes"
"encoding/json"
- "io/ioutil"
"log"
"net/http"
jose "github.com/square/go-jose"
)
+type Nonce []string
+
+var nonce = Nonce([]string{})
+
+func (n *Nonce) Parse(r *http.Response) {
+ nonce := r.Header.Get("Replay-Nonce")
+ *n = append(*n, nonce)
+}
+
+func (n Nonce) Nonce() (string, error) {
+ last := n[len(n)-1]
+ return last, nil
+}
+
func Get(uri string, v interface{}) error {
resp, err := http.Get(uri)
if err != nil {
return err
}
defer resp.Body.Close()
- body, err := ioutil.ReadAll(resp.Body)
- if err != nil {
- return err
- }
- return json.Unmarshal(body, v)
+ nonce.Parse(resp)
+ return json.NewDecoder(resp.Body).Decode(v)
}
func Post(uri string, v interface{}) error {
@@ -39,13 +49,9 @@ func Post(uri string, v interface{}) error {
return nil
}
-type Z struct{}
-
-func (Z) Nonce() (string, error) { return "test", nil }
-
func Sign(acc Account, body []byte) (string, error) {
signer, err := jose.NewSigner(jose.RS256, acc.PrivKey)
- signer.SetNonceSource(Z{})
+ signer.SetNonceSource(nonce)
if err != nil {
return "", err
}