diff options
author | Jürgen Hahn <mail.jhahn@gmail.com> | 2023-01-02T15·09+0100 |
---|---|---|
committer | jrhahn <mail.jhahn@gmail.com> | 2023-01-04T12·24+0000 |
commit | 6f993b8bde8201213fe2953ea663ac387de916e3 (patch) | |
tree | f82cd8094172c18a5eb0601f278fa4205e48344c /tvix/derivation/src/nix_hash.rs | |
parent | 79c05f38109d2eac07b9ba893b9b6f67fd34c29c (diff) |
feat(tvix/derivation): add nix drv path generation to Derivation r/5580
This adds a function to generate the derivation path. The computation is based on the Go implementation. Change-Id: Iae89db4976f5fd9208f0453f73688689a245cd66 Reviewed-on: https://cl.tvl.fyi/c/depot/+/7729 Tested-by: BuildkiteCI Reviewed-by: flokli <flokli@flokli.de>
Diffstat (limited to 'tvix/derivation/src/nix_hash.rs')
-rw-r--r-- | tvix/derivation/src/nix_hash.rs | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/tvix/derivation/src/nix_hash.rs b/tvix/derivation/src/nix_hash.rs new file mode 100644 index 000000000000..a49d444faa53 --- /dev/null +++ b/tvix/derivation/src/nix_hash.rs @@ -0,0 +1,15 @@ +/// CompressHash takes an arbitrary long sequence of bytes (usually a hash +/// digest), and returns a sequence of bytes of length output_size. +/// It's calculated by rotating through the bytes in the output buffer (zero- +/// initialized), and XOR'ing with each byte of the passed input. +/// It consumes 1 byte at a time, and XOR's it with the current value in the +/// output buffer. +pub fn compress_hash(input: &[u8], output_size: usize) -> Vec<u8> { + let mut output: Vec<u8> = vec![0; output_size]; + + for (ii, ch) in input.iter().enumerate() { + output[ii % output_size] ^= ch; + } + + output +} |