enhance(hash):包装散列算法中的错误提示。

This commit is contained in:
徐涛
2023-07-13 13:58:53 +08:00
parent 2e276ca33c
commit 955d3a96f2
9 changed files with 27 additions and 18 deletions

View File

@@ -4,6 +4,7 @@ package sha512
import (
"crypto/sha512"
"encoding/hex"
"fmt"
"hash"
"io"
"os"
@@ -76,14 +77,14 @@ func Sum512Hex(data []byte, bitSize ...int) string {
func SumFile512(path string, bitSize ...int) ([]byte, error) {
f, err := os.Open(path)
if err != nil {
return nil, err
return nil, fmt.Errorf("未能打开指定文件,%w", err)
}
defer f.Close()
length := append(bitSize, 512)
var hasher = hasherSelect(length[0])
if _, err := io.Copy(hasher, f); err != nil {
return nil, err
return nil, fmt.Errorf("未能读取指定文件的内容,%w", err)
}
return hasher.Sum(nil), nil
}