ahash: add SumLimitedReader

This commit is contained in:
2023-05-04 13:41:33 -07:00
parent 90318f861b
commit 078230217d
2 changed files with 29 additions and 1 deletions

View File

@@ -1,5 +1,6 @@
// Package ahash provides support for hashing data with a selectable
// hash function.
//
// hash function.
package ahash
import (
@@ -213,6 +214,17 @@ func SumReader(algo string, r io.Reader) ([]byte, error) {
return h.Sum(nil), nil
}
// SumLimitedReader reads n bytes of data from the io.reader and returns the
// digest (not the hex digest) from the specified algorithm.
func SumLimitedReader(algo string, r io.Reader, n int64) ([]byte, error) {
limit := &io.LimitedReader{
R: r,
N: n,
}
return SumReader(algo, limit)
}
var insecureHashList, secureHashList, hashList []string
func init() {