script icon indicating copy to clipboard operation
script copied to clipboard

Added SHA-512 Hashing

Open terrorbyte opened this issue 3 years ago • 1 comments

See #113 for discussion

Added a SHA-512 hashing mechanism modeled off of the SHA-256 tools. The majority of this code is nearly copy and pasted from the function with the SHA-512 crypto code. The tests have also been added and utilizes the SHA-512 openssl dgst, the only file added was a input file for SHA-512, though it is exactly the same as the 256 test file (I will bring up in the issue that it may be better to create just a generic file for hashing algorithms vs just for each one as per the nature of hashing algorithms).

All tests passed on my first run:

$ go test -v | grep -i sha512
=== RUN   TestSHA512Sums_OutputsCorrectHashForEachSpecifiedFile
=== PAUSE TestSHA512Sums_OutputsCorrectHashForEachSpecifiedFile
=== RUN   TestSHA512Sum_OutputsCorrectHash
=== PAUSE TestSHA512Sum_OutputsCorrectHash
=== CONT  TestSHA512Sum_OutputsCorrectHash
=== RUN   TestSHA512Sum_OutputsCorrectHash/for_no_data
=== RUN   TestSHA512Sum_OutputsCorrectHash/for_short_string
=== RUN   TestSHA512Sum_OutputsCorrectHash/for_string_containing_newline
--- PASS: TestSHA512Sum_OutputsCorrectHash (0.00s)
    --- PASS: TestSHA512Sum_OutputsCorrectHash/for_no_data (0.00s)
    --- PASS: TestSHA512Sum_OutputsCorrectHash/for_short_string (0.00s)
    --- PASS: TestSHA512Sum_OutputsCorrectHash/for_string_containing_newline (0.00s)
=== CONT  TestSHA512Sums_OutputsCorrectHashForEachSpecifiedFile
--- PASS: TestSHA512Sums_OutputsCorrectHashForEachSpecifiedFile (0.00s)
=== RUN   ExamplePipe_SHA512Sum
--- PASS: ExamplePipe_SHA512Sum (0.00s)
=== RUN   ExamplePipe_SHA512Sums
--- PASS: ExamplePipe_SHA512Sums (0.00s)

terrorbyte avatar Apr 26 '22 22:04 terrorbyte

Yes, this is great, but it seems a shame to duplicate all the SHA-256 code. Since both SHA-256 and SHA-512 implement Hasher, should we rewrite this to use common hashing code, but switch the hasher depending on the method called?

In other words, something like:

func (p *Pipe) SHA256Sum() (string, error) {
	return p.hash(sha256.New())
}

bitfield avatar Jun 02 '22 11:06 bitfield

I think this is superseded by #130, isn't it?

bitfield avatar Aug 26 '22 14:08 bitfield