From 9725522fbea660d75c1f43b3bae8da3d729c779a Mon Sep 17 00:00:00 2001 From: neevek Date: Wed, 22 May 2024 08:48:21 +0800 Subject: [PATCH] support base64 decode and encode cmdline args --- Cargo.lock | 2 +- src/bin/omnip.rs | 18 ++++++++++++++---- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 71e764d..ecc21f9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1433,7 +1433,7 @@ dependencies = [ [[package]] name = "rstun" version = "0.4.12" -source = "git+https://github.com/neevek/rstun#9a4e8253813206ab4859dce0ba8047779321f5d9" +source = "git+https://github.com/neevek/rstun#15009d86d45895d1a2c4935011c6ecb906402082" dependencies = [ "android_logger", "anyhow", diff --git a/src/bin/omnip.rs b/src/bin/omnip.rs index c89f089..97e9ae4 100644 --- a/src/bin/omnip.rs +++ b/src/bin/omnip.rs @@ -58,6 +58,12 @@ fn parse_args() -> Result { .decode(base64_args) .context("invalid base64")?, )?; + if args.decode_base64 { + println!("{space_sep_args}"); + // simply print the args and quit + bail!(""); + } + let parts: Vec = space_sep_args .split_whitespace() .map(String::from) @@ -76,10 +82,10 @@ fn parse_args() -> Result { } fn print_args_as_base64(args: &OmnipArgs) -> bool { - if args.print_base64 { + if args.encode_base64 { let space_sep_args = env::args_os() .skip(1) - .filter(|arg| arg != "-P" && arg != "--print-base64") + .filter(|arg| arg != "-E" && arg != "--encode-base64") .map(|arg| { arg.into_string() .unwrap_or_else(|os_str| os_str.to_string_lossy().into_owned()) @@ -179,6 +185,10 @@ struct OmnipArgs { /// Print the args as base64 string to be used in opp:// address, will be ignored if passing in /// as an opp:// address, which can combine all args as a single base64 string - #[arg(short = 'P', long, action)] - print_base64: bool, + #[arg(short = 'E', long, action)] + encode_base64: bool, + + /// Decode and print the base64 encoded opp:// address + #[arg(short = 'D', long, action)] + decode_base64: bool, }