From 7ad731cc56d0cf7d9d97e4d7309713670bf48b20 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ant=C3=B3nio=20Conselheiro?= Date: Sun, 3 Nov 2024 13:04:01 -0300 Subject: [PATCH] include error when simple regex include non bench32 chars --- Cargo.lock | 2 +- Cargo.toml | 2 +- README.md | 10 +++++----- src/main.rs | 18 ++++++++++++++---- 4 files changed, 21 insertions(+), 11 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index f638863..b1c363a 100755 --- a/Cargo.lock +++ b/Cargo.lock @@ -510,7 +510,7 @@ dependencies = [ [[package]] name = "eschanostr" -version = "0.1.0" +version = "1.0.1" dependencies = [ "chrono", "clap", diff --git a/Cargo.toml b/Cargo.toml index bd19781..3213e37 100755 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "eschanostr" -version = "0.1.0" +version = "1.0.1" edition = "2021" [dependencies] diff --git a/README.md b/README.md index d4ddd1e..1608c67 100755 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ Convert electricity into read friendly nostr npub. ## Install ```sh -sudo wget -O /usr/bin/eschanostr https://github.com/antonioconselheiro/eschanostr/releases/download/1.0.0/eschanostr; +sudo wget -O /usr/bin/eschanostr https://github.com/antonioconselheiro/eschanostr/releases/download/1.0.1/eschanostr; sudo chmod +x /usr/bin/eschanostr ``` @@ -22,15 +22,15 @@ Or just download the last version in releases page. **Basic run:** -`eschanostr --nregex "horses" --npassword "jesusteama"` +`eschanostr --nregex "deep" --npassword "jesusteama"` or -`eschanostr -r "libs" -p "reijesus"` +`eschanostr -r "h0ney" -p "reijesus"` **Complex regexes:** -`eschanostr --nregex ".*h[o0]rs[e3]s?" --npassword "jesusteama"` +`eschanostr --nregex ".*pl[a4]c[e3]" --npassword "jesusteama"` You can compose your regex using [this tool](https://jex.im/regulex/#!flags=&re=.*h%5Bo0%5Drs%5Be3%5Ds%3F). @@ -38,7 +38,7 @@ The algorithm use brute-force search, so if you should fill the regex with all y **Dev run** -`cargo run -- --nregex "shop" --npassword "jesuslindo"` +`cargo run -- --nregex "sh0p" --npassword "jesuslindo"` See more in [CONTRIBUTE.md](./CONTRIBUTE.md). diff --git a/src/main.rs b/src/main.rs index 6182411..7afb6f4 100755 --- a/src/main.rs +++ b/src/main.rs @@ -18,7 +18,7 @@ use std::io::{stdout, Write}; use ctrlc; #[derive(Parser)] -#[clap(name = "eschanostr", version = "1.0", about = "convert electricity into read friendly nostr npub")] +#[clap(name = "eschanostr", version = "1.0.1", about = "convert electricity into read friendly nostr npub")] struct Cli { #[arg(short = 'r', long, help = "mandatory regular expression with the desired pattern in your npub")] @@ -122,7 +122,7 @@ fn main() -> Result<(), Box> { let npassword = args.npassword.unwrap_or("".to_string()); let ndancing = args.ndancing.unwrap_or(true); - let full_regex_pattern = format!(r"^npub1({})", args.nregex); + // set offset let spacing; if ndancing { spacing = "\r "; @@ -130,8 +130,18 @@ fn main() -> Result<(), Box> { spacing = ""; } - println!("{}:: STARTING", spacing); + // validate and build regex + let nregex = args.nregex.clone(); + let is_alpha_numerical = Regex::new("^[a-zA-Z\\d]+$")?; + let is_bench32_compatible = Regex::new("^[023456789acdefghjklmnpqrstuvwxyz]+$")?; + + if is_alpha_numerical.is_match(&nregex) && !is_bench32_compatible.is_match(&nregex) { + println!("{}:: Chars that occurs in npub1: 023456789acdefghjklmnpqrstuvwxyz", spacing); + panic!("{}:: Error: some characteres in \"{}\" will never occur in npub1 string", spacing, nregex); + } + let full_regex_pattern = format!(r"^npub1({})", nregex); + // subscribe ctrlc listener let mut ctrlc_calls = 0; let ctrlc_can_be_not_instantly = [ "user triggered close command", @@ -159,7 +169,6 @@ fn main() -> Result<(), Box> { "yeah I known", ]; - // listen user close command let running: Arc = Arc::new(AtomicBool::new(true)); let running_clone = running.clone(); ctrlc::set_handler(move || { @@ -176,6 +185,7 @@ fn main() -> Result<(), Box> { running_clone.store(false, Ordering::SeqCst); })?; + println!("{}:: STARTING", spacing); if ndancing { println!(""); println!("{}▓█████ ██████ ▄████▄ ██░ ██ ▄▄▄ ███▄ █ ▒█████ ██████ ▄▄▄█████▓ ██▀███ ", spacing);