From 673a9715d559ff4e86f89f2d9e7201f81814991f Mon Sep 17 00:00:00 2001 From: DeFiDude <59237470+DeFiDude@users.noreply.github.com> Date: Thu, 14 May 2026 13:31:25 -0600 Subject: [PATCH] tools: align utilities with Reticulum 1.2.5 --- crates/rns-tools/src/commands/rncp.rs | 2 +- crates/rns-tools/src/commands/rnid/main.rs | 90 ++++++++++++++++++---- crates/rns-tools/src/commands/rnid/rsg.rs | 2 +- crates/rns-tools/src/commands/rnpath.rs | 2 +- crates/rns-tools/src/commands/rnprobe.rs | 2 +- crates/rns-tools/src/commands/rnsd.rs | 2 +- crates/rns-tools/src/commands/rnsh.rs | 4 +- crates/rns-tools/tests/rnid_cli.rs | 7 +- crates/rns-transport/src/actor/mod.rs | 2 +- 9 files changed, 87 insertions(+), 26 deletions(-) diff --git a/crates/rns-tools/src/commands/rncp.rs b/crates/rns-tools/src/commands/rncp.rs index 7d989c1..1f94009 100644 --- a/crates/rns-tools/src/commands/rncp.rs +++ b/crates/rns-tools/src/commands/rncp.rs @@ -42,7 +42,7 @@ use rns_runtime::rncp::{ }; const DEFAULT_TIMEOUT_SECS: f64 = 15.0; -const RETICULUM_COMPAT_VERSION: &str = "1.2.4"; +const RETICULUM_COMPAT_VERSION: &str = "1.2.5"; #[derive(Parser)] #[command( diff --git a/crates/rns-tools/src/commands/rnid/main.rs b/crates/rns-tools/src/commands/rnid/main.rs index 349c0d4..bbf9381 100644 --- a/crates/rns-tools/src/commands/rnid/main.rs +++ b/crates/rns-tools/src/commands/rnid/main.rs @@ -1,6 +1,6 @@ //! rnid-rs - identity create/inspect/sign/verify/encrypt/decrypt. //! -//! Python reference: `RNS/Utilities/rnid.py` from Reticulum 1.2.4. +//! Python reference: `RNS/Utilities/rnid.py` from Reticulum 1.2.5. mod rsg; @@ -26,7 +26,7 @@ use rns_transport::messages::{ #[cfg(feature = "hardware")] mod hw_commands; -const RETICULUM_COMPAT_VERSION: &str = "1.2.4"; +const RETICULUM_COMPAT_VERSION: &str = "1.2.5"; const DEFAULT_ASPECTS: &str = "rns.id"; const PUB_EXT: &str = "pub"; const SIG_EXT: &str = "rsg"; @@ -159,6 +159,10 @@ struct Args { #[arg(short = 'B', long)] base32: bool, + /// Use hex-encoded input and output. + #[arg(long)] + hex: bool, + /// Print version and exit. #[arg(long)] version: bool, @@ -271,8 +275,12 @@ async fn run(mut args: Args) -> ExitCode { eprintln!("The -i, -g, -m and -M args are mutually exclusive"); return ExitCode::from(1); } - if args.base64 && args.base32 { - eprintln!("The -b and -B args are mutually exclusive"); + let encoding_count = [args.base64, args.base32, args.hex] + .into_iter() + .filter(|flag| *flag) + .count(); + if encoding_count > 1 { + eprintln!("The -b, -B and --hex args are mutually exclusive"); return ExitCode::from(1); } @@ -858,19 +866,6 @@ fn sign_file(identity: &Identity, args: &Args) -> ExitCode { return ExitCode::from(6); } }; - let Some(output_path) = args - .write - .clone() - .or_else(|| Some(append_extension(input_path, SIG_EXT))) - else { - eprintln!("Signing requested, but no output specified"); - return ExitCode::from(253); - }; - if let Err(e) = ensure_output_allowed(&output_path, args.force) { - eprintln!("{e}"); - return ExitCode::from(11); - } - let signature = if args.raw { match rsg::create_raw_signature(identity, input) { Ok(signature) => signature.to_vec(), @@ -888,6 +883,37 @@ fn sign_file(identity: &Identity, args: &Args) -> ExitCode { } } }; + + if !args.raw && (args.base64 || args.base32 || args.hex) { + let encoded = if args.base64 { + URL_SAFE.encode(&signature) + } else if args.base32 { + encode_base32(&signature) + } else { + hex::encode(&signature) + }; + println!("\n{}\n", wrap_rsg(encoded.as_bytes())); + println!( + "Signed file {} with {}", + input_path.display(), + pretty_hash(&identity.hash) + ); + return ExitCode::SUCCESS; + } + + let Some(output_path) = args + .write + .clone() + .or_else(|| Some(append_extension(input_path, SIG_EXT))) + else { + eprintln!("Signing requested, but no output specified"); + return ExitCode::from(253); + }; + if let Err(e) = ensure_output_allowed(&output_path, args.force) { + eprintln!("{e}"); + return ExitCode::from(11); + } + if let Err(e) = write_output(&output_path, &signature, args.stdout) { eprintln!("{e}"); return ExitCode::from(253); @@ -1301,6 +1327,36 @@ fn encode_key_text(bytes: &[u8], args: &Args) -> String { } } +fn wrap_rsg(rsg: &[u8]) -> String { + const HEADER: &[u8] = b"#### Start of rsg data "; + const FOOTER: &[u8] = b" End of rsg data ####"; + const ROW_WIDTH: usize = 64; + + let mut header = String::from_utf8_lossy(HEADER).into_owned(); + while header.len() < ROW_WIDTH { + header.push('#'); + } + + let mut footer = String::new(); + while footer.len() + FOOTER.len() < ROW_WIDTH { + footer.push('#'); + } + footer.push_str(&String::from_utf8_lossy(FOOTER)); + + let mut wrapped = String::new(); + wrapped.push_str(&header); + wrapped.push('\n'); + for chunk in rsg.chunks(ROW_WIDTH) { + wrapped.push_str(&String::from_utf8_lossy(chunk)); + for _ in chunk.len()..ROW_WIDTH { + wrapped.push('='); + } + wrapped.push('\n'); + } + wrapped.push_str(&footer); + wrapped +} + fn encode_base32(bytes: &[u8]) -> String { const ALPHABET: &[u8; 32] = b"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567"; let mut out = String::new(); diff --git a/crates/rns-tools/src/commands/rnid/rsg.rs b/crates/rns-tools/src/commands/rnid/rsg.rs index 0522401..0579f87 100644 --- a/crates/rns-tools/src/commands/rnid/rsg.rs +++ b/crates/rns-tools/src/commands/rnid/rsg.rs @@ -291,7 +291,7 @@ mod tests { use super::*; fn message() -> &'static [u8] { - b"Reticulum 1.2.4 rsg test payload" + b"Reticulum 1.2.5 rsg test payload" } fn pack_value(value: Value) -> Vec { diff --git a/crates/rns-tools/src/commands/rnpath.rs b/crates/rns-tools/src/commands/rnpath.rs index 9fa154d..3fdcd79 100644 --- a/crates/rns-tools/src/commands/rnpath.rs +++ b/crates/rns-tools/src/commands/rnpath.rs @@ -27,7 +27,7 @@ const REMOTE_TIMEOUT_SECS: u64 = 30; const REMOTE_HOPS: u8 = 8; const MGMT_APP: &str = "rnstransport.remote.management"; const BLACKHOLE_APP: &str = "rnstransport.info.blackhole"; -const RETICULUM_COMPAT_VERSION: &str = "1.2.4"; +const RETICULUM_COMPAT_VERSION: &str = "1.2.5"; #[derive(Parser)] #[command( diff --git a/crates/rns-tools/src/commands/rnprobe.rs b/crates/rns-tools/src/commands/rnprobe.rs index 86458bb..c1abb29 100644 --- a/crates/rns-tools/src/commands/rnprobe.rs +++ b/crates/rns-tools/src/commands/rnprobe.rs @@ -13,7 +13,7 @@ use rns_runtime::probe::{ const DEFAULT_PROBE_SIZE: usize = 16; const DEFAULT_TIMEOUT_SECS: f64 = 12.0; -const RETICULUM_COMPAT_VERSION: &str = "1.2.4"; +const RETICULUM_COMPAT_VERSION: &str = "1.2.5"; #[derive(Parser)] #[command( diff --git a/crates/rns-tools/src/commands/rnsd.rs b/crates/rns-tools/src/commands/rnsd.rs index 91b42e9..3592062 100644 --- a/crates/rns-tools/src/commands/rnsd.rs +++ b/crates/rns-tools/src/commands/rnsd.rs @@ -7,7 +7,7 @@ use std::path::{Path, PathBuf}; use clap::Parser; use tracing_subscriber::fmt::MakeWriter; -const RETICULUM_COMPAT_VERSION: &str = "1.2.4"; +const RETICULUM_COMPAT_VERSION: &str = "1.2.5"; const LOG_ROTATE_BYTES: u64 = 5 * 1024 * 1024; const RNSD_EXAMPLE_CONFIG: &str = r#"# This is an example Reticulum config file. diff --git a/crates/rns-tools/src/commands/rnsh.rs b/crates/rns-tools/src/commands/rnsh.rs index 3e36a1a..c85212a 100644 --- a/crates/rns-tools/src/commands/rnsh.rs +++ b/crates/rns-tools/src/commands/rnsh.rs @@ -23,7 +23,7 @@ use rns_runtime::rnsh::{ }; use tokio::sync::mpsc; -const RNS_VERSION: &str = "1.2.4"; +const RNS_VERSION: &str = "1.2.5"; const RNSH_PROTOCOL_VERSION: &str = "0.2.0"; const APP_NAME: &str = "rnsh"; const DEFAULT_SERVICE_NAME: &str = "default"; @@ -872,7 +872,7 @@ mod tests { fn version_string_uses_rust_command_name() { assert_eq!( format!("rnsh-rs {RNS_VERSION} (protocol {RNSH_PROTOCOL_VERSION})"), - "rnsh-rs 1.2.4 (protocol 0.2.0)" + "rnsh-rs 1.2.5 (protocol 0.2.0)" ); } diff --git a/crates/rns-tools/tests/rnid_cli.rs b/crates/rns-tools/tests/rnid_cli.rs index a0472b8..a2a56e8 100644 --- a/crates/rns-tools/tests/rnid_cli.rs +++ b/crates/rns-tools/tests/rnid_cli.rs @@ -135,7 +135,12 @@ fn rnid_flag_conflicts_are_rejected() { let tmp = TempDir::new("rnid-flag-conflicts"); let output = rnid(&tmp, ["-b", "-B"]); - assert_failure(&output, Some(1), "-b and -B", "base64/base32 conflict"); + assert_failure( + &output, + Some(1), + "-b, -B and --hex", + "base64/base32 conflict", + ); let generated = tmp.join("identity"); let output = rnid( diff --git a/crates/rns-transport/src/actor/mod.rs b/crates/rns-transport/src/actor/mod.rs index 40c52c3..c2f58ef 100644 --- a/crates/rns-transport/src/actor/mod.rs +++ b/crates/rns-transport/src/actor/mod.rs @@ -777,7 +777,7 @@ impl TransportActor { } /// Pin all cached announces made by `identity_hash`. Exposed via - /// `RetainIdentity` for Python 1.2.4 rnid parity. + /// `RetainIdentity` for Python 1.2.5 rnid parity. pub(super) fn retain_identity(&mut self, identity_hash: &[u8; 16]) -> bool { let mut retained = false; for entry in self.recent_announces.values_mut() {