On 01/02/2014 11:41 AM, Yves Junqueira wrote:
>> @@ -102,7 +102,9 @@ func obtainPeers(d *dht.DHT, passphrase []byte, c chan Peer) {
>>  // but it's not exactly a secret.
>>  func infoHash(passphrase []byte) (dht.InfoHash, error) {
>>  	// SHA256 of the passphrase.
>> -	h := sha256.Sum256(passphrase)
>> +	h256 := sha256.New()
> 
> Not sure if it works on 1.1, but wouldn't this be a bit better?
> 
> sha256.New().Sum(passphrase)

The old functionality doesn't seem to work that way.  It's
.Write(passphrase) then calling .Sum(nil).

It's odd, probably why they changed it.

My attempt at sha256.New().Sum(passphrase) didn't work.  For this line:
h := sha256.New().Sum(buffer)

I get:
./sha256-test.go:40: h.Sum undefined (type []byte has no field or method
Sum)

Here's a discussion of the old and new method:
http://dominik.honnef.co/go-tip/2013-08-30/#hash

Similar was is in the go docs and the examples I find.

So if you want an easy self contained example of this working:
https://raw.github.com/spikebike/Backups-Done-Right/master/src/examples/sha256-test.go

When compiled/run:
bill@kona:~/tmp/go/Backups-Done-Right/src/examples$ go version
go version go1.1.2 linux/amd64
bill@kona:~/tmp/go/Backups-Done-Right/src/examples$ go run sha256-test.go
88979a713923e6b1f266c91e9458ba136a4fa0ebab7143e6a0b097d5e8af8abd
sha256-test.go
bill@kona:~/tmp/go/Backups-Done-Right/src/examples$ go version
go version go1.2 linux/amd64
bill@kona:~/tmp/go/Backups-Done-Right/src/examples$ go run sha256-test.go
88979a713923e6b1f266c91e9458ba136a4fa0ebab7143e6a0b097d5e8af8abd
sha256-test.go
bill@kona:~/tmp/go/Backups-Done-Right/src/examples$ sha256sum
sha256-test.go
88979a713923e6b1f266c91e9458ba136a4fa0ebab7143e6a0b097d5e8af8abd
sha256-test.go

So the method in my pull request works with go 1.1, go 1.2, and gives
the same answer as the command line sha256 tool.