From 9d501133366a4abac6607c33f6fd865dd6dd2996 Mon Sep 17 00:00:00 2001 From: Paolo Barbolini Date: Sat, 30 Mar 2024 07:49:12 +0100 Subject: [PATCH] Replace md5 with md-5 --- Cargo.toml | 2 +- src/encryption.rs | 13 +++++++------ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index c179064..7ac800a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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 } diff --git a/src/encryption.rs b/src/encryption.rs index 76b3b29..91f0a3c 100644 --- a/src/encryption.rs +++ b/src/encryption.rs @@ -1,5 +1,6 @@ use crate::rc4::Rc4; use crate::{Document, Object, ObjectId}; +use md5::{Digest as _, Md5}; use std::fmt; #[derive(Debug)] @@ -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]); } @@ -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[..]); @@ -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,