-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #198 from ste93cry/add-hashfiles-template-func
Add the `hashFiles` template func to calculate the SHA256 hash of multiple files
- Loading branch information
Showing
9 changed files
with
120 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,19 @@ | ||
package generator | ||
|
||
import ( | ||
"crypto/md5" // #nosec | ||
"fmt" | ||
hash2 "hash" | ||
"io" | ||
) | ||
|
||
// readerHasher generic md5 hash generater from io.Reader. | ||
func readerHasher(readers ...io.Reader) (string, error) { | ||
// Use go1.14 new hashmap functions. | ||
h := md5.New() // #nosec | ||
func readerHasher(hasher func() hash2.Hash, readers ...io.Reader) ([]byte, error) { | ||
h := hasher() | ||
|
||
for _, r := range readers { | ||
if _, err := io.Copy(h, r); err != nil { | ||
return "", fmt.Errorf("write reader as hash, %w", err) | ||
return nil, fmt.Errorf("write reader as hash, %w", err) | ||
} | ||
} | ||
|
||
return fmt.Sprintf("%x", h.Sum(nil)), nil | ||
return h.Sum(nil), nil | ||
} |