Refactor utils/utils, fixes #11923

Signed-off-by: Antonio Murdaca <me@runcom.ninja>
This commit is contained in:
Antonio Murdaca 2015-03-29 23:17:23 +02:00
parent b15e56b3ef
commit d7a5d5b94c
10 changed files with 328 additions and 10 deletions

View file

@ -3,6 +3,8 @@ package ioutils
import (
"bytes"
"crypto/rand"
"crypto/sha256"
"encoding/hex"
"io"
"math/big"
"sync"
@ -215,3 +217,11 @@ func (r *bufReader) Close() error {
}
return closer.Close()
}
func HashData(src io.Reader) (string, error) {
h := sha256.New()
if _, err := io.Copy(h, src); err != nil {
return "", err
}
return "sha256:" + hex.EncodeToString(h.Sum(nil)), nil
}