feat(tvix/store): add nixbase32 mod

This implements the nix-specific base32 encoding and decoding, exposing
a subset of the API that the data-encoding crate provides.

Nix uses a custom alphabet, no padding, and encodes bytes in reverse
order. The latter one is the reason we can't just use the data-encoding
crate directly.

Three odd corner case tests ported over from go-nix failed. We opened
b/235 to further investigate.

Change-Id: I73fab6ddd67177d882e4c3f2b48761c95853d558
Reviewed-on: https://cl.tvl.fyi/c/depot/+/7683
Reviewed-by: tazjin <tazjin@tvl.su>
Autosubmit: flokli <flokli@flokli.de>
Tested-by: BuildkiteCI
This commit is contained in:
Florian Klink 2022-12-29 22:47:02 +01:00 committed by flokli
parent 5ba47a2bc3
commit 357c4d4836
5 changed files with 247 additions and 33 deletions

30
tvix/Cargo.lock generated
View file

@ -473,6 +473,12 @@ dependencies = [
"syn 1.0.103",
]
[[package]]
name = "data-encoding"
version = "2.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "23d8666cb01533c39dde32bcbab8e227b4ed6679b2c925eba05feabea39508fb"
[[package]]
name = "derivation"
version = "0.1.0"
@ -1785,6 +1791,28 @@ dependencies = [
"winapi-util",
]
[[package]]
name = "test-case"
version = "2.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "21d6cf5a7dffb3f9dceec8e6b8ca528d9bd71d36c9f074defb548ce161f598c0"
dependencies = [
"test-case-macros",
]
[[package]]
name = "test-case-macros"
version = "2.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e45b7bf6e19353ddd832745c8fcf77a17a93171df7151187f26623f2b75b5b26"
dependencies = [
"cfg-if",
"proc-macro-error",
"proc-macro2 1.0.47",
"quote 1.0.21",
"syn 1.0.103",
]
[[package]]
name = "test-generator"
version = "0.3.0"
@ -2116,9 +2144,11 @@ version = "0.1.0"
dependencies = [
"anyhow",
"blake3",
"data-encoding",
"lazy_static",
"prost",
"prost-build",
"test-case",
"thiserror",
"tonic",
"tonic-build",