diff --git a/src/lib.rs b/src/lib.rs index b670e05..d43e42f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -97,11 +97,9 @@ impl Fingerprunk { }; for num in 0..self.config.workers.get() { - let sender = sender.clone(); - thread::Builder::new() .name(format!("worker-{num:03}")) - .spawn_scoped(scope, move || ref_self.worker_thread(sender))?; + .spawn_scoped(scope, || ref_self.worker_thread(&sender))?; } let mut stdout = io::stdout().lock(); @@ -111,7 +109,7 @@ impl Fingerprunk { match message { Message::Key(key) => { let cert = self.key_to_cert(key)?; - self.serialize_cert(cert, &mut stdout)?; + self.serialize_cert(&cert, &mut stdout)?; // Increase "found" counter and stop if enough matches have been found let prev = self.counter_found.fetch_add(1, Ordering::Relaxed); @@ -135,7 +133,7 @@ impl Fingerprunk { }) } - fn worker_thread(&self, sender: mpsc::SyncSender) { + fn worker_thread(&self, sender: &mpsc::SyncSender) { let mut fingerprint_hex = String::with_capacity(20 * 2); while !self.stop.load(Ordering::Relaxed) { @@ -161,7 +159,7 @@ impl Fingerprunk { .expect("should check regex without error") } - fn key_to_cert(&self, key: SecretKey) -> anyhow::Result { + fn key_to_cert(&self, mut key: SecretKey) -> anyhow::Result { let creation_time = SystemTime::now(); let mut signer = key @@ -175,7 +173,6 @@ impl Fingerprunk { // Create certificate let mut cert = Cert::try_from(Packet::SecretKey({ - let mut key = key.clone(); if let Some(ref password) = self.config.password { let (k, mut secret) = key.take_secret(); secret.encrypt_in_place(&k, password)?; @@ -205,7 +202,7 @@ impl Fingerprunk { Ok(cert) } - fn serialize_cert(&self, cert: Cert, to: impl io::Write) -> anyhow::Result<()> { + fn serialize_cert(&self, cert: &Cert, to: impl io::Write) -> anyhow::Result<()> { let mut comments = cert.armor_headers(); comments.push(format!( "Generated with Fingerprunk. Regex: {}", diff --git a/src/main.rs b/src/main.rs index 14d9e27..389e9a2 100644 --- a/src/main.rs +++ b/src/main.rs @@ -93,7 +93,7 @@ fn main() -> anyhow::Result<()> { "WARNING: No user ID was provided.\n\ You may experience problems importing generated keys into GnuPG.\n\ Use `--userid ` to add a user ID.\n" - ) + ); } let password = if args.password { @@ -125,7 +125,5 @@ fn main() -> anyhow::Result<()> { workers, }; - Fingerprunk::new_from_config(config).run()?; - - Ok(()) + Fingerprunk::new_from_config(config).run() }