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

lib: add fromHexString #266705

Closed
wants to merge 1 commit into from
Closed

Conversation

lucasew
Copy link
Contributor

@lucasew lucasew commented Nov 10, 2023

Description of changes

Add a function that convert an hexadecimal string to it's int representation

Simplification of #258834

How to test:

  • nix-instantiate --eval lib/tests/misc.nix

Things done

  • Built on platform(s)
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • For non-Linux: Is sandboxing enabled in nix.conf? (See Nix manual)
    • sandbox = relaxed
    • sandbox = true
  • Tested, as applicable:
  • Tested compilation of all packages that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD". Note: all changes have to be committed, also see nixpkgs-review usage
  • Tested basic functionality of all binary files (usually in ./result/bin/)
  • 23.11 Release Notes (or backporting 23.05 Release notes)
    • (Package updates) Added a release notes entry if the change is major or breaking
    • (Module updates) Added a release notes entry if the change is significant
    • (Module addition) Added a release notes entry if adding a new NixOS module
  • Fits CONTRIBUTING.md.

Signed-off-by: lucasew <lucas59356@gmail.com>
@github-actions github-actions bot added the 6.topic: lib The Nixpkgs function library label Nov 10, 2023
@lucasew lucasew marked this pull request as ready for review November 10, 2023 17:44
@ofborg ofborg bot added 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin 10.rebuild-linux: 1-10 labels Nov 10, 2023
*/
fromHexString = value:
let
parsed = builtins.fromTOML "v=0x${value}";
Copy link
Member

Choose a reason for hiding this comment

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

We should make sure to check for the limits of this approach. I recommend a single builtins.match "^[0-9a-fA-F]{,<maximum>}$" value to validate there's no invalid characters and not too many (fill in ). The current length limit should also be documented as a warning in the docs (see here), with a note that it could get increased in the future.

Comment on lines +167 to +170
testFromHexStringSecondExample = {
expr = fromHexString (builtins.hashString "sha256" "test");
expected = 9223372036854775807;
};
Copy link
Member

Choose a reason for hiding this comment

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

This test will run into the length limit, needs some trimming :)

@wegank wegank added the 2.status: merge conflict This PR has merge conflicts with the target branch label Mar 20, 2024
@woojiq woojiq mentioned this pull request Jun 10, 2024
3 tasks
@wegank wegank added the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Jul 4, 2024
@woojiq
Copy link
Contributor

woojiq commented Jul 13, 2024

This PR can be closed since I cherry-picked the commit into #318712

@stale stale bot removed the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Jul 13, 2024
@lucasew lucasew closed this Jul 13, 2024
@lucasew lucasew deleted the lib/fromHexString branch July 13, 2024 09:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2.status: merge conflict This PR has merge conflicts with the target branch 6.topic: lib The Nixpkgs function library 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin 10.rebuild-linux: 1-10
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants