From e0c6bca892b25ca06e1a1444f182c684574bdb4b Mon Sep 17 00:00:00 2001 From: Rasmus Dahlberg Date: Thu, 29 Oct 2020 11:18:54 +0100 Subject: refactored and added sth error-checking --- handler.go | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) (limited to 'handler.go') diff --git a/handler.go b/handler.go index 8f36e50..0bc5a53 100644 --- a/handler.go +++ b/handler.go @@ -9,7 +9,6 @@ import ( "github.com/golang/glog" "github.com/google/trillian" - "github.com/google/trillian/types" ) // appHandler implements the http.Handler interface, and contains a reference @@ -211,16 +210,11 @@ func getSth(ctx context.Context, i *Instance, w http.ResponseWriter, _ *http.Req if err != nil { return http.StatusInternalServerError, fmt.Errorf("failed fetching signed tree head from Trillian backend: %v", err) } - if trillianResponse.SignedLogRoot == nil { - return http.StatusInternalServerError, fmt.Errorf("Trillian returned no tree head") - } - var lr types.LogRootV1 - if err := lr.UnmarshalBinary(trillianResponse.SignedLogRoot.GetLogRoot()); err != nil { - return http.StatusInternalServerError, fmt.Errorf("failed unmarshaling tree head: %v", err) + th, err := NewTreeHeadV1(i.LogParameters, trillianResponse.SignedLogRoot) + if err != nil { + return http.StatusInternalServerError, fmt.Errorf("failed creating tree head: %v", err) } - - th := NewTreeHeadV1(uint64(lr.TimestampNanos/1000/1000), uint64(lr.TreeSize), lr.RootHash) sth, err := GenV1STH(i.LogParameters, th) if err != nil { return http.StatusInternalServerError, fmt.Errorf("failed creating signed tree head: %v", err) -- cgit v1.2.3