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

Replace md5 with md-5 #272

Merged
merged 1 commit into from
Mar 31, 2024
Merged
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
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ image = { version = "^0.24", optional = true }
itoa = "^1.0"
linked-hash-map = "^0.5"
log = "^0.4"
md5 = "0.7.0"
md-5 = "0.10"
nom = { version = "^7.1", optional = true }
pom = { version = "^3.2", optional = true }
rayon = { version = "^1.6", optional = true }
Expand Down
13 changes: 7 additions & 6 deletions src/encryption.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::rc4::Rc4;
use crate::{Document, Object, ObjectId};
use md5::{Digest as _, Md5};
use std::fmt;

#[derive(Debug)]
Expand Down Expand Up @@ -146,7 +147,7 @@ where
// Hash the contents of key and take the first key_len bytes
let n_hashes = if revision < 3 { 1 } else { 51 };
for _ in 0..n_hashes {
let digest = md5::compute(&key);
let digest = Md5::digest(&key);
key.truncate(key_len); // only keep the first key_len bytes
key.copy_from_slice(&digest[..key_len]);
}
Expand Down Expand Up @@ -179,12 +180,12 @@ where
} else {
// Algorithm 3.5
// 3.5.2
let mut ctx = md5::Context::new();
ctx.consume(PAD_BYTES);
let mut ctx = Md5::new();
ctx.update(PAD_BYTES);

// 3.5.3
ctx.consume(file_id_0);
let hash = ctx.compute();
ctx.update(file_id_0);
let hash = ctx.finalize();

// 3.5.4
let mut encrypted_hash = encryptor.encrypt(&hash[..]);
Expand Down Expand Up @@ -222,7 +223,7 @@ where

// Now construct the rc4 key
let key_len = std::cmp::min(key.len() + 5, 16);
let rc4_key = &md5::compute(builder)[..key_len];
let rc4_key = &Md5::digest(builder)[..key_len];

let encrypted = match obj {
Object::String(content, _) => content,
Expand Down