diff options
author | edef <edef@edef.eu> | 2023-10-27T07·50+0000 |
---|---|---|
committer | edef <edef@edef.eu> | 2023-10-27T12·18+0000 |
commit | 3c0e42167fccc1d54d47bc143b85e2aef05c4d1d (patch) | |
tree | 5d85d80821671a43511e923e6b1694afc25f663c /tvix | |
parent | 6a0a75c8e11aaf8dc8c3114eee354be34b7be16d (diff) |
feat(tvix/nix-compat): use AsRef<[u8]> for base32 decode input r/6884
Change-Id: If2275dda62b852aedb64b4f9915f7dc4173cabd2 Reviewed-on: https://cl.tvl.fyi/c/depot/+/9851 Tested-by: BuildkiteCI Reviewed-by: flokli <flokli@flokli.de>
Diffstat (limited to 'tvix')
-rw-r--r-- | tvix/nix-compat/src/nixbase32.rs | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/tvix/nix-compat/src/nixbase32.rs b/tvix/nix-compat/src/nixbase32.rs index 39b6b8cfe97d..fae80cd4a042 100644 --- a/tvix/nix-compat/src/nixbase32.rs +++ b/tvix/nix-compat/src/nixbase32.rs @@ -68,7 +68,9 @@ const BASE32_ORD: [u8; 256] = { }; /// Returns decoded input -pub fn decode(input: &[u8]) -> Result<Vec<u8>, Nixbase32DecodeError> { +pub fn decode(input: impl AsRef<[u8]>) -> Result<Vec<u8>, Nixbase32DecodeError> { + let input = input.as_ref(); + let output_len = decode_len(input.len()); let mut output: Vec<u8> = vec![0x00; output_len]; @@ -149,11 +151,11 @@ mod tests { match dec { Some(dec) => { // The decode needs to match what's passed in dec - assert_eq!(dec, super::decode(enc.as_bytes()).unwrap()); + assert_eq!(dec, super::decode(enc).unwrap()); } None => { // the decode needs to be an error - assert!(super::decode(enc.as_bytes()).is_err()); + assert!(super::decode(enc).is_err()); } } } |