tools: align utilities with Reticulum 1.2.5

This commit is contained in:
DeFiDude committed 2026-05-14 13:31:25 -06:00
1 parent 81672542ce
commit 673a9715d5
9 files changed
+87 -26

No files matched your search

+1 -1
View File
@@ -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(
+73 -17
View File
@@ -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();
+1 -1
View File
@@ -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<u8> {
+1 -1
View File
@@ -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(
+1 -1
View File
@@ -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(
+1 -1
View File
@@ -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.
+2 -2
View File
@@ -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)"
);
}
+6 -1
View File
@@ -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(
+1 -1
View File
@@ -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() {