Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cargo fmt project #54

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 5 additions & 10 deletions crates/cracker/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use std::{fs, io, cell::RefCell, sync::Arc};
use std::collections::hash_map::HashMap;
use std::{cell::RefCell, fs, io, sync::Arc};

use anyhow::anyhow;
use pdf::PdfError;
use pdf::any::AnySync;
use pdf::file::{Cache, Storage};
use pdf::object::{ParseOptions, PlainRef};
use pdf::PdfError;

#[derive(Clone)]
pub struct PDFCracker(Vec<u8>);
Expand All @@ -20,9 +20,7 @@ impl PDFCracker {
type ObjectCache = SimpleCache<Result<AnySync, Arc<PdfError>>>;
type StreamCache = SimpleCache<Result<Arc<[u8]>, Arc<PdfError>>>;

pub struct PDFCrackerState(
Storage<Vec<u8>, ObjectCache, StreamCache>
);
pub struct PDFCrackerState(Storage<Vec<u8>, ObjectCache, StreamCache>);

impl PDFCrackerState {
/// Init `pdf::file::Storage` so we can reuse it on each `attempt`.
Expand All @@ -42,15 +40,12 @@ impl PDFCrackerState {

/// Attempt to crack the cryptography using the password, return true on success.
pub fn attempt(&mut self, password: &[u8]) -> bool {
self.0.load_storage_and_trailer_password(password)
.is_ok()
self.0.load_storage_and_trailer_password(password).is_ok()
}
}

/// Single-threaded adapter to use `HashMap` as a `pdf::file::Cache`.
struct SimpleCache<T>(
RefCell<HashMap<PlainRef, T>>
);
struct SimpleCache<T>(RefCell<HashMap<PlainRef, T>>);

impl<T: Clone> SimpleCache<T> {
fn new() -> Self {
Expand Down
2 changes: 1 addition & 1 deletion crates/engine/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ pub fn crack_file(
let c2 = cracker_handle.clone();
let id: std::thread::JoinHandle<()> = std::thread::spawn(move || {
let Ok(mut cracker) = PDFCrackerState::from_cracker(&c2) else {
return
return;
};

while let Ok(passwd) = r2.recv() {
Expand Down
10 changes: 5 additions & 5 deletions crates/producer/src/default_query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ impl DefaultQuery {
let mut char_set: Vec<u8> = (b'0'..=b'9')
.chain(b'A'..=b'Z')
.chain(b'a'..=b'z')
.chain(b'!'..=b'/') // Adding special characters from ASCII range ! (33) to / (47)
.chain(b':'..=b'@') // Adding special characters from ASCII range : (58) to @ (64)
.chain(b'['..=b'`') // Adding special characters from ASCII range [ (91) to ` (96)
.chain(b'{'..=b'~') // Adding special characters from ASCII range { (123) to ~ (126)
.chain(b'!'..=b'/') // Adding special characters from ASCII range ! (33) to / (47)
.chain(b':'..=b'@') // Adding special characters from ASCII range : (58) to @ (64)
.chain(b'['..=b'`') // Adding special characters from ASCII range [ (91) to ` (96)
.chain(b'{'..=b'~') // Adding special characters from ASCII range { (123) to ~ (126)
.collect();

char_set.sort();

Self {
max_length,
min_length,
Expand Down
Loading