From f0b541b507bd6101eef6d46ae32f2b6518b07cf8 Mon Sep 17 00:00:00 2001 From: Padraic Fanning Date: Thu, 2 Sep 2021 22:13:47 -0400 Subject: [PATCH] Add uuencoding functions to binascii rust module Currently, they don't work as advertised. --- vm/src/stdlib/binascii.rs | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/vm/src/stdlib/binascii.rs b/vm/src/stdlib/binascii.rs index ef61b1086..8eb128d65 100644 --- a/vm/src/stdlib/binascii.rs +++ b/vm/src/stdlib/binascii.rs @@ -143,4 +143,32 @@ mod decl { } encoded } + + #[pyfunction] + fn a2b_uu(s: SerializedData, vm: &VirtualMachine) -> PyResult> { + s.with_ref(|b| { + let mut buf; + let b = if memchr::memchr(b'\n', b).is_some() { + buf = b.to_vec(); + buf.retain(|c| *c != b'\n'); + &buf + } else { + b + }; + // TODO: RUSTPYTHON, implement actual uuencoding code + base64::decode(b) + }) + .map_err(|err| vm.new_value_error(format!("error decoding uuencode: {}", err))) + } + + #[pyfunction] + fn b2a_uu(data: ArgBytesLike, NewlineArg { newline }: NewlineArg) -> Vec { + #[allow(clippy::redundant_closure)] // https://stackoverflow.com/questions/63916821 + // TODO: RUSTPYTHON, implement actual uuencoding code + let mut encoded = data.with_ref(|b| base64::encode(b)).into_bytes(); + if newline { + encoded.push(b'\n'); + } + encoded + } }