From 01bd20286a53827714ad819a1c2f57d28a116156 Mon Sep 17 00:00:00 2001 From: Dimitri Sokolyuk Date: Fri, 27 Nov 2015 18:14:26 +0100 Subject: wip --- client.go | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) (limited to 'client.go') 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 } -- cgit v1.2.3