From 9438e82b3f2fee7a14e5c884316a69484f8d4413 Mon Sep 17 00:00:00 2001 From: Leigh McCulloch <351529+leighmcculloch@users.noreply.github.com> Date: Thu, 9 May 2024 15:13:24 +1000 Subject: [PATCH 1/2] Add support for decoding variable length arrays to cli --- src/cli/decode.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/cli/decode.rs b/src/cli/decode.rs index d60c989c..721050cd 100644 --- a/src/cli/decode.rs +++ b/src/cli/decode.rs @@ -52,6 +52,7 @@ pub enum InputFormat { Stream, StreamBase64, StreamFramed, + VarArray, } impl Default for InputFormat { @@ -107,6 +108,19 @@ macro_rules! run_x { self.out(&t?)?; } } + InputFormat::VarArray => { + use crate::$m::ReadXdr; + let len = u32::read_xdr(&mut f)?; + for _ in 0..len { + let t = crate::$m::Type::read_xdr(r#type, &mut f)?; + self.out(&t)?; + } + // Check that any further reads, such as this read of one byte, read no + // data, indicating EOF. If a byte is read the data is invalid. + if f.read(&mut [0u8; 1])? != 0 { + Err(crate::$m::Error::Invalid)?; + } + } }; } Ok(()) From d2f20e91f8b7a726335b7a01c220a6f5df5553b7 Mon Sep 17 00:00:00 2001 From: Leigh McCulloch <351529+leighmcculloch@users.noreply.github.com> Date: Thu, 9 May 2024 16:22:26 +1000 Subject: [PATCH 2/2] base64 --- src/cli/decode.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/cli/decode.rs b/src/cli/decode.rs index 721050cd..6db13627 100644 --- a/src/cli/decode.rs +++ b/src/cli/decode.rs @@ -53,6 +53,7 @@ pub enum InputFormat { StreamBase64, StreamFramed, VarArray, + VarArrayBase64, } impl Default for InputFormat { @@ -121,6 +122,23 @@ macro_rules! run_x { Err(crate::$m::Error::Invalid)?; } } + InputFormat::VarArrayBase64 => { + use crate::$m::ReadXdr; + let mut dec = crate::$m::Limited::new( + base64::read::DecoderReader::new(&mut f, base64::STANDARD), + crate::$m::Limits::none(), + ); + let len = u32::read_xdr(&mut dec)?; + for _ in 0..len { + let t = crate::$m::Type::read_xdr(r#type, &mut dec)?; + self.out(&t)?; + } + // Check that any further reads, such as this read of one byte, read no + // data, indicating EOF. If a byte is read the data is invalid. + if dec.read(&mut [0u8; 1])? != 0 { + Err(crate::$m::Error::Invalid)?; + } + } }; } Ok(())