diff --git a/README.md b/README.md index a979d16..83ee059 100644 --- a/README.md +++ b/README.md @@ -68,7 +68,7 @@ Utilities: * [ ] `seq` * [ ] `setsid` * [x] `sha1sum` - * [ ] `sha224sum` + * [x] `sha224sum` * [ ] `sha256sum` * [ ] `sha384sum` * [ ] `sha512-224sum` diff --git a/hashsum.go b/hashsum.go index e15ecc2..9a6f3a1 100644 --- a/hashsum.go +++ b/hashsum.go @@ -4,6 +4,7 @@ import ( "bufio" "crypto/md5" "crypto/sha1" + "crypto/sha256" "errors" "fmt" "hash" @@ -16,6 +17,7 @@ import ( var MD5Regex = regexp.MustCompile("^(?P[0-9a-f]{32}) (?P.*)$") var SHA1Regex = regexp.MustCompile("^(?P[0-9a-f]{40}) (?P.*)$") +var SHA224Regex = regexp.MustCompile("^(?P[0-9a-f]{56}) (?P.*)$") // SumFunc is a type of function that computes a hash.Hash for data in io.Reader type SumFunc func(io.Reader) (hash.Hash, error) @@ -35,6 +37,10 @@ func SHA1Sum(r io.Reader) (hash.Hash, error) { return copyIntoHash(r, sha1.New()) } +func SHA224Sum(r io.Reader) (hash.Hash, error) { + return copyIntoHash(r, sha256.New224()) +} + type CheckingResults struct { ImproperlyFormattedCount uint InvalidChecksumCount uint diff --git a/sha224sum/sha224sum.go b/sha224sum/sha224sum.go new file mode 100644 index 0000000..6b3f46b --- /dev/null +++ b/sha224sum/sha224sum.go @@ -0,0 +1,9 @@ +package main + +import ( + common "source.heropunch.io/tomo/go-coreutils" +) + +func main() { + common.SumMain(common.SHA224Regex, common.SHA224Sum) +}