New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Generic HashSum and HashSums #130
base: master
Are you sure you want to change the base?
Conversation
Thanks, @wishdev! This is certainly more flexible than what we have at the moment. I'm not sure if specifying the desired hash algorithm as a string is the right way to go. It would make sense to define these as constants: script.Echo("hello").HashSum(script.SHA-256).Stdout() However, this isn't valid Go, because identifiers can only contain letters. This is presumably why the constants defined in It also sets up a potentially irksome maintainer chore of keeping the list up to date with Go's script.Echo("secret password").Hash(crypto.SHA256).Stdout() |
As opposed to SHA256Sum/SHA512Sum and such - add HashSum(algo) function. This allows for the use of any standard go hasher interface algorithms.
Sounds perfectly reasonable. Updated... |
Nice! Shall we now think about an example that demonstrates the need for |
'HashSums' isn't new functionality. It replaces SHA256Sums which is used for hashng files. You pass it a slice of file names and it will return the hash of each file. There is a test already setup for SHA256Sums within the test file. |
Well, that's exactly the point of my question: why replace it? |
I guess I'm just confused - it "replaces" the function in the same way HashSum replaces SHA256Sum - it allows one to select a different hash algorithm for the task at hand. Both SHA256Sum and SHA256Sums still exist - they are just single line functions to HashSum(crypto.SHA256) or HashSums(crypto.SHA256). I did move SHA256Sums down in the code base to get all the hashing functionality a little closer together - maybe that's leading to the confusion? |
And in what kind of non-trivial |
I also want to point out what an API concern with using |
This would replace #113/#114 and "depreciate" SHA256Sum and SHA256Sums by adding more generic functions called HashSum and HashSums.
One could call p.HashSum("SHA-256") or p.HashSums("SHA3-512") as opposed to adding specific functions for each hash algorithm desired.
This uses the crypto package and the official blessed algorithms within.
There are probably some extra tests (specifically passing an invalid hash name) and some docs to add - but I wanted to make sure I was on the right path here.....
SHA256Sum and SHA256Sums are replaced internally with calls to HashSum("SHA-256") and HashSums("SHA-256").
Finally, the internals are condensed and HashSum and HashSums use a common hash function to which they pass their io.Reader