diff options
Diffstat (limited to 'src/gnunet/crypto/hash.go')
-rw-r--r-- | src/gnunet/crypto/hash.go | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/src/gnunet/crypto/hash.go b/src/gnunet/crypto/hash.go index bc715d4..049a8ef 100644 --- a/src/gnunet/crypto/hash.go +++ b/src/gnunet/crypto/hash.go | |||
@@ -19,6 +19,7 @@ | |||
19 | package crypto | 19 | package crypto |
20 | 20 | ||
21 | import ( | 21 | import ( |
22 | "bytes" | ||
22 | "crypto/sha512" | 23 | "crypto/sha512" |
23 | 24 | ||
24 | "gnunet/util" | 25 | "gnunet/util" |
@@ -29,11 +30,20 @@ type HashCode struct { | |||
29 | Bits []byte `size:"64"` | 30 | Bits []byte `size:"64"` |
30 | } | 31 | } |
31 | 32 | ||
32 | // NewHashCode creates a new, uninitalized hash value | 33 | // Equals tests if two hash results are equal. |
33 | func NewHashCode() *HashCode { | 34 | func (hc *HashCode) Equals(n *HashCode) bool { |
34 | return &HashCode{ | 35 | return bytes.Equal(hc.Bits, n.Bits) |
36 | } | ||
37 | |||
38 | // NewHashCode creates a new (initalized) hash value | ||
39 | func NewHashCode(buf []byte) *HashCode { | ||
40 | hc := &HashCode{ | ||
35 | Bits: make([]byte, 64), | 41 | Bits: make([]byte, 64), |
36 | } | 42 | } |
43 | if buf != nil { | ||
44 | util.CopyAlignedBlock(hc.Bits, buf) | ||
45 | } | ||
46 | return hc | ||
37 | } | 47 | } |
38 | 48 | ||
39 | // Hash returns the SHA-512 hash value of a given blob | 49 | // Hash returns the SHA-512 hash value of a given blob |