From a6bf2fce014f50726ced41c959aa2059bdff8322 Mon Sep 17 00:00:00 2001 From: Rasmus Dahlberg Date: Thu, 5 Nov 2020 10:53:26 +0100 Subject: unified base64-encoding of paths for printing --- type.go | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) (limited to 'type.go') diff --git a/type.go b/type.go index 037cedb..84eb011 100644 --- a/type.go +++ b/type.go @@ -141,21 +141,11 @@ func (i SignedDebugInfoV1) String() string { } func (i ConsistencyProofV1) String() string { - path := make([]string, 0, len(i.ConsistencyPath)) - for _, hash := range i.ConsistencyPath { - path = append(path, b64(hash.Data)) - } - - return fmt.Sprintf("LogID(%s) TreeSize1(%d) TreeSize2(%d) ConsistencyPath(%v)", b64(i.LogId), i.TreeSize1, i.TreeSize2, path) + return fmt.Sprintf("LogID(%s) TreeSize1(%d) TreeSize2(%d) ConsistencyPath(%v)", b64(i.LogId), i.TreeSize1, i.TreeSize2, B64EncodePath(i.ConsistencyPath)) } func (i InclusionProofV1) String() string { - path := make([]string, 0, len(i.InclusionPath)) - for _, hash := range i.InclusionPath { - path = append(path, b64(hash.Data)) - } - - return fmt.Sprintf("LogID(%s) TreeSize(%d) LeafIndex(%d) AuditPath(%v)", b64(i.LogId), i.TreeSize, i.LeafIndex, path) + return fmt.Sprintf("LogID(%s) TreeSize(%d) LeafIndex(%d) AuditPath(%v)", b64(i.LogId), i.TreeSize, i.LeafIndex, B64EncodePath(i.InclusionPath)) } func (i ChecksumV1) String() string { @@ -233,6 +223,15 @@ func (th *TreeHeadV1) Marshal() ([]byte, error) { return serialized, nil } +// B64EncodePath encodes a path of node hashes as a list of base64 strings +func B64EncodePath(path []NodeHash) []string { + p := make([]string, 0, len(path)) + for _, hash := range path { + p = append(p, b64(hash.Data)) + } + return p +} + // NewSignedTreeHead creates a new StItem of type signed_tree_head_v1 func NewSignedTreeHeadV1(th *TreeHeadV1, logId, signature []byte) *StItem { return &StItem{ -- cgit v1.2.3