Browse Source

Add sha384sum

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

+ 1
- 1
README.md View File

@@ -70,7 +70,7 @@ Utilities:
70 70
  * [x] `sha1sum`
71 71
  * [x] `sha224sum`
72 72
  * [x] `sha256sum`
73
- * [ ] `sha384sum`
73
+ * [x] `sha384sum`
74 74
  * [ ] `sha512-224sum`
75 75
  * [ ] `sha512-256sum`
76 76
  * [ ] `sha512sum`

+ 6
- 0
hashsum.go View File

@@ -5,6 +5,7 @@ import (
5 5
 	"crypto/md5"
6 6
 	"crypto/sha1"
7 7
 	"crypto/sha256"
8
+	"crypto/sha512"
8 9
 	"errors"
9 10
 	"fmt"
10 11
 	"hash"
@@ -19,6 +20,7 @@ var MD5Regex = regexp.MustCompile("^(?P<hash>[0-9a-f]{32})  (?P<filename>.*)$")
19 20
 var SHA1Regex = regexp.MustCompile("^(?P<hash>[0-9a-f]{40})  (?P<filename>.*)$")
20 21
 var SHA224Regex = regexp.MustCompile("^(?P<hash>[0-9a-f]{56})  (?P<filename>.*)$")
21 22
 var SHA256Regex = regexp.MustCompile("^(?P<hash>[0-9a-f]{64})  (?P<filename>.*)$")
23
+var SHA384Regex = regexp.MustCompile("^(?P<hash>[0-9a-f]{96})  (?P<filename>.*)$")
22 24
 
23 25
 // SumFunc is a type of function that computes a hash.Hash for data in io.Reader
24 26
 type SumFunc func(io.Reader) (hash.Hash, error)
@@ -46,6 +48,10 @@ func SHA256Sum(r io.Reader) (hash.Hash, error) {
46 48
 	return copyIntoHash(r, sha256.New())
47 49
 }
48 50
 
51
+func SHA384Sum(r io.Reader) (hash.Hash, error) {
52
+	return copyIntoHash(r, sha512.New384())
53
+}
54
+
49 55
 type CheckingResults struct {
50 56
 	ImproperlyFormattedCount uint
51 57
 	InvalidChecksumCount     uint

+ 9
- 0
sha384sum/sha384sum.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.SHA384Regex, common.SHA384Sum)
9
+}

Loading…
Cancel
Save