-
Notifications
You must be signed in to change notification settings - Fork 60
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
[SUPERCEDED] Standardize and disambiguate the return from digest.Parse
#76
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -80,7 +80,10 @@ var ( | |
// be returned if the format is invalid. | ||
func Parse(s string) (Digest, error) { | ||
d := Digest(s) | ||
return d, d.Validate() | ||
if err := d.Validate(); err != nil { | ||
return "", err | ||
} | ||
return d, nil | ||
} | ||
|
||
// FromReader consumes the content of rd until io.EOF, returning canonical digest. | ||
|
@@ -137,11 +140,21 @@ func (d Digest) Encoded() string { | |
return string(d[d.sepIndex()+1:]) | ||
} | ||
|
||
// Hex is deprecated. Please use Digest.Encoded. | ||
// IsIdenticalTo compares this digest to any other, inclusive of the hashing algorithm used | ||
func (d Digest) IsIdenticalTo(o Digest) bool { | ||
return string(d) == string(o) | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should be probably a separate PR |
||
|
||
// Deprecated: Hex has been deprecated in favor of Digest.Encoded | ||
func (d Digest) Hex() string { | ||
return d.Encoded() | ||
} | ||
|
||
// IsEmpty does what it says (an empty digest is an empty string) | ||
func (d Digest) IsEmpty() bool { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This one too |
||
return len(d.String()) == 0 | ||
} | ||
|
||
func (d Digest) String() string { | ||
return string(d) | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤔 the existing code looks a bit odd indeed (always returning the digest, even if it didn't validate).
However, it looks like there's some code that uses the returned value even if there's an error;
go-digest/digestset/set.go
Lines 95 to 103 in bde1400
(i.e., it only considers the error if it's a
digest.ErrDigestInvalidFormat
). Not sure if that's a bug, or if that's intentional (in either case, the documentation of this function should be updated to explain, and the code I linked to could use some comments as well)@dmcgowan I see you wrote that code in 77570c9 (#55) perhaps you recall?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've made a change that I think should address this (valid) issue that you've picked up with the change I made. Let me know if you think it seems reasonable to you.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not keep the previous code?