aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2017-07-21 14:30:51 +0200
committerDimitri Sokolyuk <demon@dim13.org>2017-07-21 14:30:51 +0200
commit6bf54a7a20b7a3e3d05c6a4cf24d7013c296eb23 (patch)
tree9f7535c6b04a9acb86a729749a7bd70f4e868cb6
parentc9e595e61bcde6a0b90fbebe0becb39bf1c6f618 (diff)
hash.Hash
-rw-r--r--zsig/sum.go9
-rw-r--r--zsig/zsig_test.go4
2 files changed, 8 insertions, 5 deletions
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)
}
})