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

libutils/hash: remove default encoding #3655

Merged
merged 1 commit into from Jun 10, 2020

Conversation

zimbatm
Copy link
Member

@zimbatm zimbatm commented Jun 3, 2020

This is the first step in a series of patches.

The idea, in the end, is that it will be possible to display the hash using the original encoding. This is to solve the issue where "expect got " is printed in a different encoding than what is in the source code. This makes it harder to scan the source to replace the hash.

  1. Remove all the defaults (this PR). This is done separately so that it can be merged in the flakes branch and all the merge conflicts resolved there.
  2. Rename Base to HashEncoding. "Base" doesn't make sense anymore since SRI. Maybe introduce "PrefixedBase16" and "PrefixedBase32" to remove the (encoding, includeType) tuple since it doesn't make sense with SRI either?
  3. Change the parser to store the original encoding. Restore the hash.to_string() function but that prints using the original encoding. Remove the encoding from places where we want to show the original hash.

/cc @Ericson2314 @matthewbauer who have conflicting PRs open

This will make it easier to reason about the hash encoding and switch to
SRI everywhere where possible.
Copy link
Member

@Ericson2314 Ericson2314 left a comment

Choose a reason for hiding this comment

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

This PR looks good to me

@Ericson2314
Copy link
Member

Ericson2314 commented Jun 3, 2020

For step 2, I would rather have #3453 merged first, as I think that opens the door to more renaming choices, but I still like the idea (and am fine about breakage with any other PR @matthewbauer and I have open, we can fix those).

For step 3...part of me just doesn't like storing extra information that is only used for diagnostics, but I certainly am sympathetic to the use case. Maybe we could have separate a Hash and HashWithEncoding to just hit the points where it matters. (e.g. drv files all use the same encoding for outputs, etc.)

@zimbatm
Copy link
Member Author

zimbatm commented Jun 3, 2020

I like your idea of splitting Hash and HashWithEncoding. Then only HashWithEncoding would have an argument-less to_string()

@gilligan
Copy link
Contributor

gilligan commented Jun 5, 2020

to_string(Base32, false);
to_string(SRI, true);

I lack the insight to make any comments on broader design choices here but I think it would be great if if to_string could be changed to avoid the boolean blindness and instead use something like:

to_string(Base32, HashFormat::Plain);
to_string(SRI, HashFormat::TypePrefix);

@zimbatm
Copy link
Member Author

zimbatm commented Jun 5, 2020

With the introduction of SRI, (SRI, false) doesn't make any sense. That's why I am proposing to change the API to be to_string(HashEncoding) and give each variant a name. (this is point 2 of the plan)

@gilligan
Copy link
Contributor

gilligan commented Jun 5, 2020

@zimbatm okay cool. I don’t know what SRI stands for by the way 😅

@zimbatm
Copy link
Member Author

zimbatm commented Jun 6, 2020

It stands for Subresource Integrity and is a standard from the w3c: https://www.w3.org/TR/SRI/
The idea was to re-use an existing standard instead of inventing our own.

@edolstra edolstra merged commit b9ae1bd into NixOS:master Jun 10, 2020
@zimbatm zimbatm deleted the hash-encoding-prepare branch June 10, 2020 10:21
zimbatm added a commit to zimbatm/nix that referenced this pull request Jun 10, 2020
Compress the (Base, usePrefix) tuple to a single field that represents
the hash encoding. This makes more sense because SRI always has a
prefix.

This is a continuation of the work started at NixOS#3655
zimbatm added a commit to zimbatm/nix that referenced this pull request Jun 10, 2020
Compress the (Base, usePrefix) tuple to a single field that represents
the hash encoding. This makes more sense because SRI always has a
prefix.

This is a continuation of the work started at NixOS#3655
zimbatm added a commit to zimbatm/nix that referenced this pull request Jun 10, 2020
Compress the (Base, usePrefix) tuple to a single field that represents
the hash encoding. This makes more sense because SRI always has a
prefix.

This is a continuation of the work started at NixOS#3655
zimbatm added a commit to zimbatm/nix that referenced this pull request Jun 17, 2020
Compress the (Base, usePrefix) tuple to a single field that represents
the hash encoding. This makes more sense because SRI always has a
prefix.

This is a continuation of the work started at NixOS#3655
zimbatm added a commit to zimbatm/nix that referenced this pull request Jun 17, 2020
Compress the (Base, usePrefix) tuple to a single field that represents
the hash encoding. This makes more sense because SRI always has a
prefix.

This is a continuation of the work started at NixOS#3655
zimbatm added a commit to zimbatm/nix that referenced this pull request Jun 17, 2020
Compress the (Base, usePrefix) tuple to a single field that represents
the hash encoding. This makes more sense because SRI always has a
prefix.

This is a continuation of the work started at NixOS#3655
zimbatm added a commit to zimbatm/nix that referenced this pull request Jun 18, 2020
Compress the (Base, usePrefix) tuple to a single field that represents
the hash encoding. This makes more sense because SRI always has a
prefix.

This is a continuation of the work started at NixOS#3655
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.

None yet

4 participants