Browse Source

Add sha224sum

dtluna 4 months ago
parent
commit
65218af636
3 changed files with 16 additions and 1 deletions
  1. 1
    1
      README.md
  2. 6
    0
      hashsum.go
  3. 9
    0
      sha224sum/sha224sum.go

+ 1
- 1
README.md View File

@@ -68,7 +68,7 @@ Utilities:
68 68
  * [ ] `seq`
69 69
  * [ ] `setsid`
70 70
  * [x] `sha1sum`
71
- * [ ] `sha224sum`
71
+ * [x] `sha224sum`
72 72
  * [ ] `sha256sum`
73 73
  * [ ] `sha384sum`
74 74
  * [ ] `sha512-224sum`

+ 6
- 0
hashsum.go View File

@@ -4,6 +4,7 @@ import (
4 4
 	"bufio"
5 5
 	"crypto/md5"
6 6
 	"crypto/sha1"
7
+	"crypto/sha256"
7 8
 	"errors"
8 9
 	"fmt"
9 10
 	"hash"
@@ -16,6 +17,7 @@ import (
16 17
 
17 18
 var MD5Regex = regexp.MustCompile("^(?P<hash>[0-9a-f]{32})  (?P<filename>.*)$")
18 19
 var SHA1Regex = regexp.MustCompile("^(?P<hash>[0-9a-f]{40})  (?P<filename>.*)$")
20
+var SHA224Regex = regexp.MustCompile("^(?P<hash>[0-9a-f]{56})  (?P<filename>.*)$")
19 21
 
20 22
 // SumFunc is a type of function that computes a hash.Hash for data in io.Reader
21 23
 type SumFunc func(io.Reader) (hash.Hash, error)
@@ -35,6 +37,10 @@ func SHA1Sum(r io.Reader) (hash.Hash, error) {
35 37
 	return copyIntoHash(r, sha1.New())
36 38
 }
37 39
 
40
+func SHA224Sum(r io.Reader) (hash.Hash, error) {
41
+	return copyIntoHash(r, sha256.New224())
42
+}
43
+
38 44
 type CheckingResults struct {
39 45
 	ImproperlyFormattedCount uint
40 46
 	InvalidChecksumCount     uint

+ 9
- 0
sha224sum/sha224sum.go View File

@@ -0,0 +1,9 @@
1
+package main
2
+
3
+import (
4
+	common "source.heropunch.io/tomo/go-coreutils"
5
+)
6
+
7
+func main() {
8
+	common.SumMain(common.SHA224Regex, common.SHA224Sum)
9
+}

Loading…
Cancel
Save