Skip to content

Simplify digest.FromBytes calling convention - #1264

Merged
stevvooe merged 1 commit into
distribution:masterfrom
aaronlehmann:hash-errors
Dec 16, 2015
Merged

stevvooe merged 1 commit into
distribution:masterfrom
aaronlehmann:hash-errors

Conversation

@aaronlehmann

Copy link
Copy Markdown

The current implementation of digest.FromBytes returns an error. This
error can never be non-nil, but its presence in the function signature
means each call site needs error handling code for an error that is
always nil.

I verified that none of the hash.Hash implementations in the standard
library can return an error on Write. Nor can any of the hash.Hash
implementations vendored in distribution.

This commit changes digest.FromBytes not to return an error. If Write
returns an error, it will panic, but as discussed above, this should
never happen.

This commit also avoids using a bytes.Reader to feed data into the hash
function in FromBytes. This makes the hypothetical case that would panic
a bit more explicit, and should also be more performant.

The current implementation of digest.FromBytes returns an error. This
error can never be non-nil, but its presence in the function signature
means each call site needs error handling code for an error that is
always nil.

I verified that none of the hash.Hash implementations in the standard
library can return an error on Write. Nor can any of the hash.Hash
implementations vendored in distribution.

This commit changes digest.FromBytes not to return an error. If Write
returns an error, it will panic, but as discussed above, this should
never happen.

This commit also avoids using a bytes.Reader to feed data into the hash
function in FromBytes. This makes the hypothetical case that would panic
a bit more explicit, and should also be more performant.

Signed-off-by: Aaron Lehmann <[email protected]>
@RichardScothern

Copy link
Copy Markdown

LGTM

@dmcgowan

Copy link
Copy Markdown
Collaborator

LGTM

@stevvooe

Copy link
Copy Markdown
Collaborator

LGTM

This is a much need interface change. A little history here: tarsum was a hash that could fail. Not sure if that is still the case. We may be able to completely remove tarsum support at some point but this may break very old v2 clients.

stevvooe added a commit that referenced this pull request Dec 16, 2015
Simplify digest.FromBytes calling convention
@stevvooe
stevvooe merged commit 200cbe8 into distribution:master Dec 16, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants