-
-
Notifications
You must be signed in to change notification settings - Fork 14.3k
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
lib: add fromHexString #266705
Conversation
Signed-off-by: lucasew <lucas59356@gmail.com>
*/ | ||
fromHexString = value: | ||
let | ||
parsed = builtins.fromTOML "v=0x${value}"; |
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.
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.
testFromHexStringSecondExample = { | ||
expr = fromHexString (builtins.hashString "sha256" "test"); | ||
expected = 9223372036854775807; | ||
}; |
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.
This test will run into the length limit, needs some trimming :)
This PR can be closed since I cherry-picked the commit into #318712 |
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
nix.conf
? (See Nix manual)sandbox = relaxed
sandbox = true
nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD"
. Note: all changes have to be committed, also see nixpkgs-review usage./result/bin/
)