From 3c0e42167fccc1d54d47bc143b85e2aef05c4d1d Mon Sep 17 00:00:00 2001 From: edef Date: Fri, 27 Oct 2023 07:50:38 +0000 Subject: feat(tvix/nix-compat): use AsRef<[u8]> for base32 decode input Change-Id: If2275dda62b852aedb64b4f9915f7dc4173cabd2 Reviewed-on: https://cl.tvl.fyi/c/depot/+/9851 Tested-by: BuildkiteCI Reviewed-by: flokli --- tvix/nix-compat/src/nixbase32.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'tvix/nix-compat/src') 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, Nixbase32DecodeError> { +pub fn decode(input: impl AsRef<[u8]>) -> Result, Nixbase32DecodeError> { + let input = input.as_ref(); + let output_len = decode_len(input.len()); let mut output: Vec = 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()); } } } -- cgit 1.4.1