From 6bf54a7a20b7a3e3d05c6a4cf24d7013c296eb23 Mon Sep 17 00:00:00 2001 From: Dimitri Sokolyuk Date: Fri, 21 Jul 2017 14:30:51 +0200 Subject: hash.Hash --- zsig/sum.go | 9 +++++---- zsig/zsig_test.go | 4 +++- 2 files changed, 8 insertions(+), 5 deletions(-) (limited to 'zsig') diff --git a/zsig/sum.go b/zsig/sum.go index 4843903..778d1f2 100644 --- a/zsig/sum.go +++ b/zsig/sum.go @@ -1,7 +1,7 @@ package zsig import ( - "crypto/sha512" + "hash" "io" ) @@ -11,7 +11,7 @@ const ( ) // Sum calculates SHA512/256 -func Sum(r io.Reader, blockSize int) chan []byte { +func Sum(r io.Reader, blockSize int, h hash.Hash) chan []byte { c := make(chan []byte, 1) if blockSize == 0 { blockSize = BlockSize @@ -24,8 +24,9 @@ func Sum(r io.Reader, blockSize int) chan []byte { if err == io.EOF { return } - sum := sha512.Sum512_256(buf[:n]) - c <- sum[:] + h.Reset() + h.Write(buf[:n]) + c <- h.Sum(nil) } }() return c diff --git a/zsig/zsig_test.go b/zsig/zsig_test.go index 001d11d..f724078 100644 --- a/zsig/zsig_test.go +++ b/zsig/zsig_test.go @@ -1,6 +1,7 @@ package zsig import ( + "crypto/sha512" "os" "path" "testing" @@ -25,7 +26,8 @@ func TestZsig(t *testing.T) { } t.Log(z.Header) - for block := range Sum(z, BlockSize) { + h := sha512.New512_256() + for block := range Sum(z, BlockSize, h) { t.Logf("%x", block) } }) -- cgit v1.2.3