Message:
Hello golang-dev@googlegroups.com,
I'd like you to review this change to
https://code.google.com/p/go
Description:
crypto/sha1: provide a top-level Sum function
Makes it easy to ask the simple question, what is the hash of this data?
Please review this at https://codereview.appspot.com/10571043/
Affected files:
M src/pkg/crypto/sha1/sha1.go
Index: src/pkg/crypto/sha1/sha1.go
===================================================================
--- a/src/pkg/crypto/sha1/sha1.go
+++ b/src/pkg/crypto/sha1/sha1.go
@@ -90,9 +90,13 @@
func (d0 *digest) Sum(in []byte) []byte {
// Make a copy of d0 so that caller can keep writing and summing.
d := *d0
+ hash := d.checkSum()
+ return append(in, hash[:]...)
+}
+func (d *digest) checkSum() [Size]byte {
+ len := d.len
// Padding. Add a 1 bit and 0 bits until 56 bytes mod 64.
- len := d.len
var tmp [64]byte
tmp[0] = 0x80
if len%64 < 56 {
@@ -120,5 +124,13 @@
digest[i*4+3] = byte(s)
}
- return append(in, digest[:]...)
+ return digest
}
+
+// Sum returns the SHA1 checksum of the data.
+func Sum(data []byte) [Size]byte {
+ var d digest
+ d.Reset()
+ d.Write(data)
+ return d.checkSum()
+}
--
---
You received this message because you are subscribed to the Google Groups "golang-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-dev+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.