From e0a6dd778d2cc05a3a2ce85afaf2123b4bce90c0 Mon Sep 17 00:00:00 2001 From: Magnetar Date: Thu, 24 Mar 2022 18:48:06 -0400 Subject: [PATCH] fix: remove update and make size and step public --- Cargo.lock | 2 +- Cargo.toml | 2 +- src/lib.rs | 16 ++-------------- src/util.rs | 4 ++-- 4 files changed, 6 insertions(+), 18 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index f56c63c..a3b691a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4,4 +4,4 @@ version = 3 [[package]] name = "md5-rs" -version = "0.1.3" +version = "0.1.4" diff --git a/Cargo.toml b/Cargo.toml index 785f568..6adadea 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "md5-rs" -version = "0.1.3" +version = "0.1.4" edition = "2021" license = "MIT" readme = "README.md" diff --git a/src/lib.rs b/src/lib.rs index 63a7cd4..23b92c0 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -8,7 +8,7 @@ pub use consts::{DIGEST_LEN, INPUT_BUFFER_LEN}; #[derive(Debug)] pub struct Context { /// The total size of the recieved input - size: u64, + pub size: u64, /// The input buffer /// /// Note: only access directly if you're writing to it, (e.g. if you want to write to it via Wasm memory) @@ -29,18 +29,6 @@ impl Context { } } - /// Process the bytes in the input buffer - /// - /// Note: this should only be used if you're writing to the `Context.input` array directly (e.g. if you're writing to it via Wasm memory). - /// Otherwise, use `Context::read`, but do note that it copies the data. - pub fn update(&mut self, bytes_written: usize) { - self.size += bytes_written as u64; - if self.size % (BLOCK_SIZE as u64) != 0 { - return; - } - self.step(); - } - /// Process the bytes in `buf` /// /// Usage: @@ -61,7 +49,7 @@ impl Context { } /// Process a 512-bit chunk - fn step(&mut self) { + pub fn step(&mut self) { let [mut a, mut b, mut c, mut d] = self.buffer; let mut e: u32; let mut g: usize; diff --git a/src/util.rs b/src/util.rs index f00cbf8..4e4252c 100644 --- a/src/util.rs +++ b/src/util.rs @@ -1,5 +1,6 @@ use core::ops::{BitAnd, BitOr, BitXor, Not}; +#[inline] pub fn rotate_u32_left(x: u32, n: u32) -> u32 { (x << n) | (x >> (32 - n)) } @@ -7,8 +8,7 @@ pub fn rotate_u32_left(x: u32, n: u32) -> u32 { #[inline] pub fn f(x: T, y: T, z: T) -> T where - T: Copy + BitAnd + Not + BitOr, - T: Not + BitAnd + BitOr, + T: Copy + Not + BitAnd + BitOr, { (x & y) | (!x & z) }