From 36cc7fa9c21f11e1b88084fdc2923522ebcba043 Mon Sep 17 00:00:00 2001 From: Martin Hutchinson Date: Thu, 16 May 2024 13:36:09 +0000 Subject: [PATCH] Make the client decode b64 in all cases --- hammer/clients.go | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/hammer/clients.go b/hammer/clients.go index bb45d93..848261e 100644 --- a/hammer/clients.go +++ b/hammer/clients.go @@ -95,7 +95,7 @@ func (r *LeafReader) getLeaf(ctx context.Context, i uint64, logSize uint64) ([]b if i >= logSize { return nil, fmt.Errorf("requested leaf %d >= log size %d", i, logSize) } - if cached := r.c.get(i); cached != nil { + if cached, _ := r.c.get(i); cached != nil { klog.V(2).Infof("Using cached result for index %d", i) return cached, nil } @@ -125,7 +125,7 @@ func (r *LeafReader) getLeaf(ctx context.Context, i uint64, logSize uint64) ([]b leaves: bs, } - return base64.StdEncoding.DecodeString(string(bs[br])) + return r.c.get(i) } // Kills this leaf reader at the next opportune moment. @@ -144,12 +144,13 @@ type leafBundleCache struct { leaves [][]byte } -func (tc leafBundleCache) get(i uint64) []byte { +func (tc leafBundleCache) get(i uint64) ([]byte, error) { end := tc.start + uint64(len(tc.leaves)) if i >= tc.start && i < end { - return tc.leaves[i-tc.start] + leaf := tc.leaves[i-tc.start] + return base64.StdEncoding.DecodeString(string(leaf)) } - return nil + return nil, errors.New("not found") } // RandomNextLeaf returns a function that fetches a random leaf available in the tree.