Skip to content

Commit

Permalink
add hashonly format output
Browse files Browse the repository at this point in the history
  • Loading branch information
boyter committed Sep 29, 2022
1 parent 188e138 commit 319f20f
Show file tree
Hide file tree
Showing 13 changed files with 166 additions and 89 deletions.
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func main() {
"format",
"f",
"text",
"set output format [text, json, sum, hashdeep]",
"set output format [text, json, sum, hashdeep, hashonly]",
)
flags.BoolVarP(
&processor.Recursive,
Expand Down
53 changes: 53 additions & 0 deletions processor/formatters.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ func fileSummarize(input chan Result) (string, bool) {
return toHashDeep(input), true
case strings.ToLower(Format) == "sum": // Similar to md5sum sha1sum output format
return toSum(input), true
case strings.ToLower(Format) == "hashonly":
return toHashOnly(input)
}

return toText(input)
Expand Down Expand Up @@ -122,6 +124,57 @@ func toSum(input chan Result) string {
return str.String()
}

func toHashOnly(input chan Result) (string, bool) {
var str strings.Builder
valid := true

for res := range input {
if hasHash(HashNames.MD4) {
str.WriteString(res.MD4 + "\n")
}
if hasHash(HashNames.MD5) {
str.WriteString(res.MD5 + "\n")
}
if hasHash(HashNames.SHA1) {
str.WriteString(res.SHA1 + "\n")
}
if hasHash(HashNames.SHA256) {
str.WriteString(res.SHA256 + "\n")
}
if hasHash(HashNames.SHA512) {
str.WriteString(res.SHA512 + "\n")
}
if hasHash(HashNames.Blake2b256) {
str.WriteString(res.Blake2b256 + "\n")
}
if hasHash(HashNames.Blake2b512) {
str.WriteString(res.Blake2b512 + "\n")
}
if hasHash(HashNames.Blake3) {
str.WriteString(res.Blake3 + "\n")
}
if hasHash(HashNames.Sha3224) {
str.WriteString(res.Sha3224 + "\n")
}
if hasHash(HashNames.Sha3256) {
str.WriteString(res.Sha3256 + "\n")
}
if hasHash(HashNames.Sha3384) {
str.WriteString(res.Sha3384 + "\n")
}
if hasHash(HashNames.Sha3512) {
str.WriteString(res.Sha3512 + "\n")
}

if NoStream == false && FileOutput == "" {
fmt.Print(str.String())
str.Reset()
}
}

return str.String(), valid
}

func toText(input chan Result) (string, bool) {
var str strings.Builder
valid := true
Expand Down
2 changes: 1 addition & 1 deletion processor/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
)

// Global Version
var Version = "1.1.0"
var Version = "1.2.0"

// Verbose enables verbose logging output
var Verbose = false
Expand Down
3 changes: 2 additions & 1 deletion vendor/github.com/mattn/go-isatty/isatty_windows.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 16 additions & 3 deletions vendor/github.com/spf13/pflag/flag.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 20 additions & 8 deletions vendor/github.com/spf13/pflag/string_slice.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 4 additions & 8 deletions vendor/golang.org/x/crypto/sha3/doc.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions vendor/golang.org/x/crypto/sha3/sha3_s390x.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions vendor/golang.org/x/sys/cpu/cpu.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions vendor/golang.org/x/sys/unix/syscall_aix.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions vendor/golang.org/x/sys/unix/syscall_dragonfly.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 319f20f

Please sign in to comment.