Skip to content

Commit

Permalink
Create separate Cracker crate
Browse files Browse the repository at this point in the history
  • Loading branch information
timmy committed Feb 10, 2024
1 parent cfcd653 commit 95fc457
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 2 deletions.
5 changes: 3 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[workspace]
members = ["crates/producer"]
members = [ "crates/cracker","crates/producer"]

[workspace.package]
version = "2.0.1"
Expand All @@ -9,6 +9,7 @@ authors = ["Mufeed VH <[email protected]>", "Pommaq"]
[workspace.dependencies]
bytecount = "0.6.7"
log = "0.4.19"
pdf = "0.8.1"


[package]
Expand All @@ -25,9 +26,9 @@ anyhow = "1.0.72"
crossbeam = "0.8.2"
pretty_env_logger = "0.5.0"
colored = "2.0.4"
pdf = "0.8.1"
bytecount.workspace = true
clap = { version = "4.4.13", features = ["derive"] }
pdf.workspace = true

[profile.release]
lto = 'thin'
Expand Down
11 changes: 11 additions & 0 deletions crates/cracker/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[package]
name = "cracker"
version.workspace = true
edition.workspace = true
authors.workspace = true

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
log.workspace = true
pdf.workspace = true
23 changes: 23 additions & 0 deletions crates/cracker/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
use std::{fs, io};

use pdf::file::FileOptions;

#[derive(Clone)]
pub struct PDFCracker(Vec<u8>);

impl PDFCracker {
pub fn from_file(path: &str) -> Result<Self, io::Error> {
let pdf_file: Vec<u8> = fs::read(path)?;
Ok(Self(pdf_file))
}
}

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())
.is_ok()
}
}

0 comments on commit 95fc457

Please sign in to comment.