From ad2cd15c6cf2579faea829ca10a29ef9f7eaccf0 Mon Sep 17 00:00:00 2001 From: Roman Khimov Date: Wed, 28 Aug 2019 13:09:03 +0300 Subject: [PATCH] _pkg.dev: drop the last wire/util code SumSHA256() and ReaderToBuffer() are not used, CalculateHash() shouldn't be used and BufferLength() is just to easy with only one user. --- _pkg.dev/wire/message.go | 2 +- _pkg.dev/wire/util/util.go | 49 -------------------------------------- 2 files changed, 1 insertion(+), 50 deletions(-) delete mode 100644 _pkg.dev/wire/util/util.go diff --git a/_pkg.dev/wire/message.go b/_pkg.dev/wire/message.go index da0742c63..64904479d 100644 --- a/_pkg.dev/wire/message.go +++ b/_pkg.dev/wire/message.go @@ -47,7 +47,7 @@ func WriteMessage(w io.Writer, magic protocol.Magic, message Messager) error { return err } - payloadLen := util.BufferLength(buf) + payloadLen := uint32(buf.Len()) checksum := checksum.FromBytes(buf.Bytes()) bw.Write(payloadLen) diff --git a/_pkg.dev/wire/util/util.go b/_pkg.dev/wire/util/util.go deleted file mode 100644 index 58499562c..000000000 --- a/_pkg.dev/wire/util/util.go +++ /dev/null @@ -1,49 +0,0 @@ -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 -}