Skip to content
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

Improve checksum package and increase its test coverage #593

Merged
merged 8 commits into from
Jul 9, 2024

Conversation

cthulhu-rider
Copy link
Contributor

No description provided.

Copy link

codecov bot commented Jul 5, 2024

Codecov Report

Attention: Patch coverage is 95.55556% with 2 lines in your changes missing coverage. Please review.

Project coverage is 39.56%. Comparing base (d5a5fbc) to head (4a5fd58).
Report is 1 commits behind head on master.

Files Patch % Lines
checksum/test/generate.go 71.42% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #593      +/-   ##
==========================================
+ Coverage   39.47%   39.56%   +0.08%     
==========================================
  Files         147      147              
  Lines       17494    17496       +2     
==========================================
+ Hits         6906     6922      +16     
+ Misses      10213    10198      -15     
- Partials      375      376       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@carpawell carpawell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Conflicts.

@@ -123,6 +119,7 @@ func Calculate(c *Checksum, t Type, v []byte) {
case TZ:
c.SetTillichZemor(tz.Sum(v))
default:
panic(fmt.Errorf("unsupported checksum type %v", t))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i am not sure it is good. we have discussed panics in SDK and i thought we do not use them anymore. if a wrong scheme must be (really?) noticed, i would prefer an error

Copy link
Contributor Author

@cthulhu-rider cthulhu-rider Jul 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

panics are better than hidden bugs. We discussed this for functions which return an error. I'll make NewFromData to return an error

done

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, i reopened this issue with some my thoughts: #390 (comment)

checksum/checksum.go Show resolved Hide resolved
Copy link
Member

@carpawell carpawell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should go further (but conflicts).

It teaches what a regular user should be freed from.

Signed-off-by: Leonard Lyubich <[email protected]>
`Checksum` type instances are very lightweight, so setters do not
provide much benefit while forcing user to explicitly declare a new var.
It was also no convenient way to create an instance from stdlib `hash.Hash`.

From now `Checksum` can be instantiated with less code using set of new
constructors. Old functions are marked as deprecated.

Refs #483.

Signed-off-by: Leonard Lyubich <[email protected]>
Vary not only the value but also the type.

Signed-off-by: Leonard Lyubich <[email protected]>
Previously, `Checksum.Type` method returned any unsupported value as
zero. This led to a kind of value loss and the impossibility of forward
compatibility - although at the type level it is possible.

From now method returns underlying numeric value for unknown enum values.
The stringer now also does not fallback. `Unknown` constant is no longer
needed and deprecated.

Signed-off-by: Leonard Lyubich <[email protected]>
Previously, protocol conversion method `Checksum.ReadFromV2` failed on
any unsupported enum value. This didn't make much sense since type
getter is provided, so callers can decide for themselves.

From now method ignores checksum type.

Signed-off-by: Leonard Lyubich <[email protected]>
Signed-off-by: Leonard Lyubich <[email protected]>
Unlike SHA-256, this hash function is not so widely known.

Signed-off-by: Leonard Lyubich <[email protected]>
@cthulhu-rider
Copy link
Contributor Author

We should go further (but conflicts).

resolved

@cthulhu-rider cthulhu-rider merged commit 606acea into master Jul 9, 2024
12 checks passed
@cthulhu-rider cthulhu-rider deleted the checksum branch July 9, 2024 20:03
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.

2 participants