diff options
author | Rasmus Dahlberg <rasmus.dahlberg@kau.se> | 2020-10-22 15:08:47 +0200 |
---|---|---|
committer | Rasmus Dahlberg <rasmus.dahlberg@kau.se> | 2020-10-22 15:08:47 +0200 |
commit | 2793442e21f19fc3f764e1f848b83d96076dcfb0 (patch) | |
tree | 8b2adfcca8c9753fe463dc4ad47224c178bbe73e | |
parent | ec4741e374beeb085579ba896fdee2cd6f0f8848 (diff) |
added parameter parsing for get-entries
-rw-r--r-- | handler.go | 9 | ||||
-rw-r--r-- | type.go | 31 |
2 files changed, 39 insertions, 1 deletions
@@ -112,9 +112,16 @@ func unpackRequest(r *http.Request, unpack interface{}) error { return nil } -// getEntries provides with a list of entries from the Trillian backend +// getEntries provides a list of entries from the Trillian backend func getEntries(ctx context.Context, i *instance, w http.ResponseWriter, r *http.Request) (int, error) { glog.Info("in getEntries") + + var request GetEntriesRequest + if err := request.Unpack(r); err != nil { + return http.StatusBadRequest, err + } + glog.Infof("valid request: %v", request) + return http.StatusOK, nil // TODO } @@ -2,8 +2,10 @@ package stfe import ( "fmt" + "strconv" "encoding/base64" + "net/http" "github.com/google/certificate-transparency-go/tls" ) @@ -98,3 +100,32 @@ type AddEntryRequest struct { Signature string `json:"signature"` Certificate string `json:"certificate"` } + +// GetEntriesRequest is a collection of get-entry input parameters +type GetEntriesRequest struct { + Start int64 + End int64 +} + +func (r *GetEntriesRequest) Unpack(httpRequest *http.Request) error { + var err error + + r.Start, err = strconv.ParseInt(httpRequest.FormValue("start"), 10, 64) + if err != nil { + return fmt.Errorf("bad start parameter: %v", err) + } + r.End, err = strconv.ParseInt(httpRequest.FormValue("end"), 10, 64) + if err != nil { + return fmt.Errorf("bad end parameter: %v", err) + } + + if r.Start < 0 { + return fmt.Errorf("bad parameters: start(%v) must have a non-negative value", r.Start) + } + if r.Start > r.End { + return fmt.Errorf("bad parameters: start(%v) must be larger than end(%v)", r.Start, r.End) + } + // TODO: check that range is not larger than the max range. Yes -> truncate + // TODO: check that end is not past the most recent STH. Yes -> truncate + return nil +} |