aboutsummaryrefslogtreecommitdiff
path: root/trillian.go
diff options
context:
space:
mode:
Diffstat (limited to 'trillian.go')
-rw-r--r--trillian.go32
1 files changed, 32 insertions, 0 deletions
diff --git a/trillian.go b/trillian.go
new file mode 100644
index 0000000..e5117da
--- /dev/null
+++ b/trillian.go
@@ -0,0 +1,32 @@
+package stfe
+
+import (
+ "fmt"
+
+ "net/http"
+
+ "github.com/google/trillian"
+ "github.com/google/trillian/types"
+)
+
+// checkGetLeavesByRange does santity-checking on a Trillian response
+func checkGetLeavesByRange(rsp *trillian.GetLeavesByRangeResponse, req GetEntriesRequest) (int, error) {
+ if len(rsp.Leaves) > int(req.End-req.Start+1) {
+ return http.StatusInternalServerError, fmt.Errorf("backend GetLeavesByRange returned too many leaves: %d for [%d,%d]", len(rsp.Leaves), req.Start, req.End)
+ }
+
+ var lr types.LogRootV1
+ if err := lr.UnmarshalBinary(rsp.GetSignedLogRoot().GetLogRoot()); err != nil {
+ return http.StatusInternalServerError, fmt.Errorf("failed unmarshaling log root: %v", err)
+ }
+ if uint64(req.Start) >= lr.TreeSize {
+ return http.StatusBadRequest, fmt.Errorf("invalid start(%d): tree size is %d", req.Start, lr.TreeSize)
+ }
+
+ for i, leaf := range rsp.Leaves {
+ if leaf.LeafIndex != req.Start+int64(i) {
+ return http.StatusInternalServerError, fmt.Errorf("backend GetLeavesByRange returned unexpected leaf index: wanted %d, got %d", req.Start+int64(i), leaf.LeafIndex)
+ }
+ }
+ return 0, nil
+}