From 5c3065b43a61a5fa019cbbb157984fc5eb81d439 Mon Sep 17 00:00:00 2001 From: Padraic-O-Mhuiris Date: Wed, 21 Feb 2024 16:49:07 +0000 Subject: feat(tvix/eval): implement `builtins.hashString` Implements md5, sha1, sha256 and sha512 using the related crates from the RustCrypto hashes project (https://github.com/RustCrypto/hashes) Change-Id: I00730dea44ec9ef85309edc27addab0ae88814b8 Reviewed-on: https://cl.tvl.fyi/c/depot/+/11005 Tested-by: BuildkiteCI Reviewed-by: aspen --- tvix/eval/src/tests/nix_tests/eval-okay-groupBy.exp | 1 + tvix/eval/src/tests/nix_tests/eval-okay-groupBy.nix | 5 +++++ tvix/eval/src/tests/nix_tests/eval-okay-hashstring.exp | 1 + tvix/eval/src/tests/nix_tests/eval-okay-hashstring.nix | 4 ++++ tvix/eval/src/tests/nix_tests/notyetpassing/eval-okay-groupBy.exp | 1 - tvix/eval/src/tests/nix_tests/notyetpassing/eval-okay-groupBy.nix | 5 ----- .../eval/src/tests/nix_tests/notyetpassing/eval-okay-hashstring.exp | 1 - .../eval/src/tests/nix_tests/notyetpassing/eval-okay-hashstring.nix | 4 ---- tvix/eval/src/tests/tvix_tests/eval-okay-builtins-hashString.exp | 1 + tvix/eval/src/tests/tvix_tests/eval-okay-builtins-hashString.nix | 6 ++++++ 10 files changed, 18 insertions(+), 11 deletions(-) create mode 100644 tvix/eval/src/tests/nix_tests/eval-okay-groupBy.exp create mode 100644 tvix/eval/src/tests/nix_tests/eval-okay-groupBy.nix create mode 100644 tvix/eval/src/tests/nix_tests/eval-okay-hashstring.exp create mode 100644 tvix/eval/src/tests/nix_tests/eval-okay-hashstring.nix delete mode 100644 tvix/eval/src/tests/nix_tests/notyetpassing/eval-okay-groupBy.exp delete mode 100644 tvix/eval/src/tests/nix_tests/notyetpassing/eval-okay-groupBy.nix delete mode 100644 tvix/eval/src/tests/nix_tests/notyetpassing/eval-okay-hashstring.exp delete mode 100644 tvix/eval/src/tests/nix_tests/notyetpassing/eval-okay-hashstring.nix create mode 100644 tvix/eval/src/tests/tvix_tests/eval-okay-builtins-hashString.exp create mode 100644 tvix/eval/src/tests/tvix_tests/eval-okay-builtins-hashString.nix (limited to 'tvix/eval/src/tests') diff --git a/tvix/eval/src/tests/nix_tests/eval-okay-groupBy.exp b/tvix/eval/src/tests/nix_tests/eval-okay-groupBy.exp new file mode 100644 index 000000000000..bfca5652a59b --- /dev/null +++ b/tvix/eval/src/tests/nix_tests/eval-okay-groupBy.exp @@ -0,0 +1 @@ +{ "1" = [ 9 ]; "2" = [ 8 ]; "3" = [ 13 29 ]; "4" = [ 3 4 10 11 17 18 ]; "5" = [ 0 23 26 28 ]; "6" = [ 1 12 21 27 30 ]; "7" = [ 7 22 ]; "8" = [ 14 ]; "9" = [ 19 ]; b = [ 16 25 ]; c = [ 24 ]; d = [ 2 ]; e = [ 5 6 15 31 ]; f = [ 20 ]; } diff --git a/tvix/eval/src/tests/nix_tests/eval-okay-groupBy.nix b/tvix/eval/src/tests/nix_tests/eval-okay-groupBy.nix new file mode 100644 index 000000000000..862d89dbd670 --- /dev/null +++ b/tvix/eval/src/tests/nix_tests/eval-okay-groupBy.nix @@ -0,0 +1,5 @@ +with import ./lib.nix; + +builtins.groupBy (n: + builtins.substring 0 1 (builtins.hashString "sha256" (toString n)) +) (range 0 31) diff --git a/tvix/eval/src/tests/nix_tests/eval-okay-hashstring.exp b/tvix/eval/src/tests/nix_tests/eval-okay-hashstring.exp new file mode 100644 index 000000000000..d720a082ddb3 --- /dev/null +++ b/tvix/eval/src/tests/nix_tests/eval-okay-hashstring.exp @@ -0,0 +1 @@ +[ "d41d8cd98f00b204e9800998ecf8427e" "6c69ee7f211c640419d5366cc076ae46" "bb3438fbabd460ea6dbd27d153e2233b" "da39a3ee5e6b4b0d3255bfef95601890afd80709" "cd54e8568c1b37cf1e5badb0779bcbf382212189" "6d12e10b1d331dad210e47fd25d4f260802b7e77" "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855" "900a4469df00ccbfd0c145c6d1e4b7953dd0afafadd7534e3a4019e8d38fc663" "ad0387b3bd8652f730ca46d25f9c170af0fd589f42e7f23f5a9e6412d97d7e56" "cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e" "9d0886f8c6b389398a16257bc79780fab9831c7fc11c8ab07fa732cb7b348feade382f92617c9c5305fefba0af02ab5fd39a587d330997ff5bd0db19f7666653" "21644b72aa259e5a588cd3afbafb1d4310f4889680f6c83b9d531596a5a284f34dbebff409d23bcc86aee6bad10c891606f075c6f4755cb536da27db5693f3a7" ] diff --git a/tvix/eval/src/tests/nix_tests/eval-okay-hashstring.nix b/tvix/eval/src/tests/nix_tests/eval-okay-hashstring.nix new file mode 100644 index 000000000000..b0f62b245ca8 --- /dev/null +++ b/tvix/eval/src/tests/nix_tests/eval-okay-hashstring.nix @@ -0,0 +1,4 @@ +let + strings = [ "" "text 1" "text 2" ]; +in + builtins.concatLists (map (hash: map (builtins.hashString hash) strings) ["md5" "sha1" "sha256" "sha512"]) diff --git a/tvix/eval/src/tests/nix_tests/notyetpassing/eval-okay-groupBy.exp b/tvix/eval/src/tests/nix_tests/notyetpassing/eval-okay-groupBy.exp deleted file mode 100644 index bfca5652a59b..000000000000 --- a/tvix/eval/src/tests/nix_tests/notyetpassing/eval-okay-groupBy.exp +++ /dev/null @@ -1 +0,0 @@ -{ "1" = [ 9 ]; "2" = [ 8 ]; "3" = [ 13 29 ]; "4" = [ 3 4 10 11 17 18 ]; "5" = [ 0 23 26 28 ]; "6" = [ 1 12 21 27 30 ]; "7" = [ 7 22 ]; "8" = [ 14 ]; "9" = [ 19 ]; b = [ 16 25 ]; c = [ 24 ]; d = [ 2 ]; e = [ 5 6 15 31 ]; f = [ 20 ]; } diff --git a/tvix/eval/src/tests/nix_tests/notyetpassing/eval-okay-groupBy.nix b/tvix/eval/src/tests/nix_tests/notyetpassing/eval-okay-groupBy.nix deleted file mode 100644 index 7e0eab28b036..000000000000 --- a/tvix/eval/src/tests/nix_tests/notyetpassing/eval-okay-groupBy.nix +++ /dev/null @@ -1,5 +0,0 @@ -with import ./../lib.nix; - -builtins.groupBy (n: - builtins.substring 0 1 (builtins.hashString "sha256" (toString n)) -) (range 0 31) diff --git a/tvix/eval/src/tests/nix_tests/notyetpassing/eval-okay-hashstring.exp b/tvix/eval/src/tests/nix_tests/notyetpassing/eval-okay-hashstring.exp deleted file mode 100644 index d720a082ddb3..000000000000 --- a/tvix/eval/src/tests/nix_tests/notyetpassing/eval-okay-hashstring.exp +++ /dev/null @@ -1 +0,0 @@ -[ "d41d8cd98f00b204e9800998ecf8427e" "6c69ee7f211c640419d5366cc076ae46" "bb3438fbabd460ea6dbd27d153e2233b" "da39a3ee5e6b4b0d3255bfef95601890afd80709" "cd54e8568c1b37cf1e5badb0779bcbf382212189" "6d12e10b1d331dad210e47fd25d4f260802b7e77" "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855" "900a4469df00ccbfd0c145c6d1e4b7953dd0afafadd7534e3a4019e8d38fc663" "ad0387b3bd8652f730ca46d25f9c170af0fd589f42e7f23f5a9e6412d97d7e56" "cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e" "9d0886f8c6b389398a16257bc79780fab9831c7fc11c8ab07fa732cb7b348feade382f92617c9c5305fefba0af02ab5fd39a587d330997ff5bd0db19f7666653" "21644b72aa259e5a588cd3afbafb1d4310f4889680f6c83b9d531596a5a284f34dbebff409d23bcc86aee6bad10c891606f075c6f4755cb536da27db5693f3a7" ] diff --git a/tvix/eval/src/tests/nix_tests/notyetpassing/eval-okay-hashstring.nix b/tvix/eval/src/tests/nix_tests/notyetpassing/eval-okay-hashstring.nix deleted file mode 100644 index b0f62b245ca8..000000000000 --- a/tvix/eval/src/tests/nix_tests/notyetpassing/eval-okay-hashstring.nix +++ /dev/null @@ -1,4 +0,0 @@ -let - strings = [ "" "text 1" "text 2" ]; -in - builtins.concatLists (map (hash: map (builtins.hashString hash) strings) ["md5" "sha1" "sha256" "sha512"]) diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-hashString.exp b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-hashString.exp new file mode 100644 index 000000000000..e00b80e561fb --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-hashString.exp @@ -0,0 +1 @@ +[ "8a0614b4eaa4cffb7515ec101847e198" "8bd218cf61321d8aa05b3602b99f90d2d8cef3d6" "80ac06d74cb6c5d14af718ce8c3c1255969a1a595b76a3cf92354a95331a879a" "0edac513b6b0454705b553deda4c9b055da0939d26d2f73548862817ebeac5378cf64ff7a752ce1a0590a736735d3bbd9e8a7f04d93617cdf514313f5ab5baa4" ] diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-hashString.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-hashString.nix new file mode 100644 index 000000000000..aed723d3670a --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-hashString.nix @@ -0,0 +1,6 @@ +[ + (builtins.hashString "md5" "tvix") + (builtins.hashString "sha1" "tvix") + (builtins.hashString "sha256" "tvix") + (builtins.hashString "sha512" "tvix") +] -- cgit 1.4.1