FAQ
Reviewers: golang-dev1,

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.

Search Discussions

  • R at Jun 25, 2013 at 9:37 pm
    Hello golang-dev@googlegroups.com (cc: golang-dev@googlegroups.com),

    Please take another look.


    https://codereview.appspot.com/10571043/

    --

    ---
    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.
  • Rsc at Jun 25, 2013 at 9:44 pm
    LGTM


    https://codereview.appspot.com/10571043/

    --

    ---
    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.
  • Bradfitz at Jun 25, 2013 at 9:45 pm
    https://codereview.appspot.com/10571043/diff/4001/src/pkg/crypto/sha1/sha1.go
    File src/pkg/crypto/sha1/sha1.go (right):

    https://codereview.appspot.com/10571043/diff/4001/src/pkg/crypto/sha1/sha1.go#newcode131
    src/pkg/crypto/sha1/sha1.go:131: func Sum(data []byte) [Size]byte {
    goapi doesn't handle this:

    +pkg crypto/sha1, func Sum([]uint8) [Size]uint8

    But why in just sha1? Why not md5, sha256, sha512?

    https://codereview.appspot.com/10571043/

    --

    ---
    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.
  • R at Jun 25, 2013 at 9:49 pm
    https://codereview.appspot.com/10571043/diff/4001/src/pkg/crypto/sha1/sha1.go
    File src/pkg/crypto/sha1/sha1.go (right):

    https://codereview.appspot.com/10571043/diff/4001/src/pkg/crypto/sha1/sha1.go#newcode131
    src/pkg/crypto/sha1/sha1.go:131: func Sum(data []byte) [Size]byte {
    On 2013/06/25 21:45:17, bradfitz wrote:
    goapi doesn't handle this:
    +pkg crypto/sha1, func Sum([]uint8) [Size]uint8
    But why in just sha1? Why not md5, sha256, sha512?
    i plan to put its analog in all the hash packages. if all you need is a
    hash, the current API is clunky.

    what do you mean, goapi doesn't handle it? it prints out the addition
    just fine.

    https://codereview.appspot.com/10571043/

    --

    ---
    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.
  • Brad Fitzpatrick at Jun 25, 2013 at 10:18 pm

    On Tue, Jun 25, 2013 at 2:49 PM, wrote:
    https://codereview.appspot.**com/10571043/diff/4001/src/**
    pkg/crypto/sha1/sha1.go<https://codereview.appspot.com/10571043/diff/4001/src/pkg/crypto/sha1/sha1.go>
    File src/pkg/crypto/sha1/sha1.go (right):

    https://codereview.appspot.**com/10571043/diff/4001/src/**
    pkg/crypto/sha1/sha1.go#**newcode131<https://codereview.appspot.com/10571043/diff/4001/src/pkg/crypto/sha1/sha1.go#newcode131>
    src/pkg/crypto/sha1/sha1.go:**131: func Sum(data []byte) [Size]byte {
    On 2013/06/25 21:45:17, bradfitz wrote:

    goapi doesn't handle this:
    +pkg crypto/sha1, func Sum([]uint8) [Size]uint8

    But why in just sha1? Why not md5, sha256, sha512?
    what do you mean, goapi doesn't handle it? it prints out the addition
    just fine.
    [Size]uint8 isn't a Go type.

    It should say [20]uint8.

    --

    ---
    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.
  • Rob Pike at Jun 25, 2013 at 10:47 pm
    Size is a constant, so [Size]uint8 is a Go type. goapi isn't resolving
    the name right.

    It should not say [20]uint8 since the constant is defined in the
    package for a reason: it is the size of this return value.
    -rob

    --

    ---
    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.
  • Brad Fitzpatrick at Jun 25, 2013 at 11:02 pm
    Yes, I'm just saying that goapi is broken.


    On Tue, Jun 25, 2013 at 3:45 PM, Rob Pike wrote:

    Size is a constant, so [Size]uint8 is a Go type. goapi isn't resolving
    the name right.

    It should not say [20]uint8 since the constant is defined in the
    package for a reason: it is the size of this return value.
    -rob
    --

    ---
    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.
  • Russ Cox at Jun 25, 2013 at 10:56 pm
    [Size]byte is probably fine even for goapi. If Size changes, goapi will
    tell us.
    There's a false positive if we rewrite [Size]byte to [20]byte later, but no
    big deal.

    Russ

    --

    ---
    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.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-dev @
categoriesgo
postedJun 25, '13 at 9:29p
activeJun 25, '13 at 11:02p
posts9
users3
websitegolang.org

People

Translate

site design / logo © 2022 Grokbase