pkg: hide it by moving to _pkg.dev
The idea here is to preserve the history of `dev` branch development and its code when merging with the `master`. Later this code could be moved into the masters code where appropriate.
This commit is contained in:
parent
bb2568cc53
commit
ddd1d92ff1
183 changed files with 0 additions and 0 deletions
49
_pkg.dev/wire/util/util.go
Normal file
49
_pkg.dev/wire/util/util.go
Normal file
|
@ -0,0 +1,49 @@
|
|||
package util
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"crypto/sha256"
|
||||
|
||||
"io"
|
||||
"io/ioutil"
|
||||
)
|
||||
|
||||
// Convenience function
|
||||
|
||||
// BufferLength returns the length of a buffer as uint32
|
||||
func BufferLength(buf *bytes.Buffer) uint32 {
|
||||
|
||||
return uint32(buf.Len())
|
||||
}
|
||||
|
||||
// SumSHA256 returns the sha256 sum of the data
|
||||
func SumSHA256(b []byte) []byte {
|
||||
h := sha256.New()
|
||||
h.Write(b)
|
||||
return h.Sum(nil)
|
||||
}
|
||||
|
||||
// CalculateHash takes a function with a binary writer and returns
|
||||
// the double hash of the io.Writer
|
||||
func CalculateHash(f func(bw *BinWriter)) (Uint256, error) {
|
||||
buf := new(bytes.Buffer)
|
||||
bw := &BinWriter{W: buf}
|
||||
|
||||
f(bw)
|
||||
|
||||
var hash Uint256
|
||||
hash = sha256.Sum256(buf.Bytes())
|
||||
hash = sha256.Sum256(hash.Bytes())
|
||||
return hash, bw.Err
|
||||
|
||||
}
|
||||
|
||||
//ReaderToBuffer converts a io.Reader into a bytes.Buffer
|
||||
func ReaderToBuffer(r io.Reader) (*bytes.Buffer, error) {
|
||||
byt, err := ioutil.ReadAll(r)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
buf := bytes.NewBuffer(byt)
|
||||
return buf, nil
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue