enhance(hash):包装散列算法中的错误提示。
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
Reference in New Issue
Block a user