From 6ceefc11cf186adde6f27b997a33e72fa2509d4f Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Tue, 9 May 2023 12:48:48 -0400 Subject: [PATCH] refactor: make encode fixed method to take a [32]byte, and change Encode to take a byte array that just copies and calls EncodeFixed --- cid/cid.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/cid/cid.go b/cid/cid.go index c690af5..111b7a9 100644 --- a/cid/cid.go +++ b/cid/cid.go @@ -14,7 +14,14 @@ type CID struct { Size uint64 } -func Encode(hash [32]byte, size uint64) (string, error) { +func Encode(hash []byte, size uint64) (string, error) { + var hashBytes [32]byte + copy(hashBytes[:], hash) + + return EncodeFixed(hashBytes, size) +} + +func EncodeFixed(hash [32]byte, size uint64) (string, error) { sizeBytes := make([]byte, 8) binary.LittleEndian.PutUint64(sizeBytes, size)