File: errata.go

package info (click to toggle)
golang-github-multiformats-go-multihash 0.2.3-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 376 kB
  • sloc: sh: 138; makefile: 39
file content (34 lines) | stat: -rw-r--r-- 677 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package multihash

import (
	"bytes"
	"crypto/sha256"
	"hash"
)

type identityMultihash struct {
	bytes.Buffer
}

func (identityMultihash) BlockSize() int {
	return 32 // A prefered block size is nonsense for the "identity" "hash".  An arbitrary but unsurprising and positive nonzero number has been chosen to minimize the odds of fascinating bugs.
}

func (x *identityMultihash) Size() int {
	return x.Len()
}

func (x *identityMultihash) Sum(digest []byte) []byte {
	return x.Bytes()
}

type doubleSha256 struct {
	hash.Hash
}

func (x doubleSha256) Sum(digest []byte) []byte {
	digest = x.Hash.Sum(digest)
	h2 := sha256.New()
	h2.Write(digest)
	return h2.Sum(digest[0:0])
}