hash: document that Sum does not change hash state
crypto/*: implement and test proper Sum
Fixes #216.
R=agl1
CC=golang-dev
https://golang.org/cl/186210
diff --git a/src/pkg/crypto/sha1/sha1_test.go b/src/pkg/crypto/sha1/sha1_test.go
index 8d44852..f18c7b0 100644
--- a/src/pkg/crypto/sha1/sha1_test.go
+++ b/src/pkg/crypto/sha1/sha1_test.go
@@ -55,12 +55,17 @@
for i := 0; i < len(golden); i++ {
g := golden[i]
c := New()
- for j := 0; j < 2; j++ {
- io.WriteString(c, g.in)
+ for j := 0; j < 3; j++ {
+ if j < 2 {
+ io.WriteString(c, g.in)
+ } else {
+ io.WriteString(c, g.in[0:len(g.in)/2])
+ c.Sum()
+ io.WriteString(c, g.in[len(g.in)/2:])
+ }
s := fmt.Sprintf("%x", c.Sum())
if s != g.out {
- t.Errorf("sha1[%d](%s) = %s want %s", j, g.in, s, g.out)
- t.FailNow()
+ t.Fatalf("sha1[%d](%s) = %s want %s", j, g.in, s, g.out)
}
c.Reset()
}