Skip to content

Commit

Permalink
code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Timothy Hjort committed Dec 3, 2023
1 parent f88ac69 commit 5384d3d
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 13 deletions.
12 changes: 3 additions & 9 deletions src/core/cracker.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,8 @@
/// We require cracker implementations to support being sent between threads.
pub trait Cracker: Sync + Send{
/// Attempt to crack the cryptography using the password, return true on success.
fn attempt(&self, password: &[u8]) -> bool;
}

pub mod pdf {
use std::{fs, io};

use pdf::file::FileOptions;

use super::Cracker;
#[derive(Clone)]
pub struct PDFCracker(Vec<u8>);

Expand All @@ -20,8 +13,9 @@ pub mod pdf {
}
}

impl Cracker for PDFCracker {
fn attempt(&self, password: &[u8]) -> bool {
impl PDFCracker {
/// Attempt to crack the cryptography using the password, return true on success.
pub fn attempt(&self, password: &[u8]) -> bool {
FileOptions::cached()
.password(password)
.load(self.0.as_ref())
Expand Down
2 changes: 1 addition & 1 deletion src/core/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use indicatif::ProgressBar;

use crate::core::production::Producer;

use super::cracker::{pdf::PDFCracker, Cracker};
use super::cracker::pdf::PDFCracker;

pub fn crack_file(
no_workers: usize,
Expand Down
5 changes: 2 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ pub fn main() -> anyhow::Result<()> {
// print a banner to look cool!
interface::banner();
let cli = interface::args();
let cracker =
PDFCracker::from_file(&cli.filename).context(format!("path: {}", cli.filename))?;

let producer: Box<dyn Producer> = match cli.subcommand {
interface::Method::Wordlist(args) => {
Expand Down Expand Up @@ -61,7 +59,8 @@ pub fn main() -> anyhow::Result<()> {
}
};

engine::crack_file(cli.number_of_threads, cracker, producer)?;
engine::crack_file(cli.number_of_threads,
PDFCracker::from_file(&cli.filename).context(format!("path: {}", cli.filename))?, producer)?;

Ok(())
}

0 comments on commit 5384d3d

Please sign in to comment.