Skip to content

Commit

Permalink
fix: remove update and make size and step public
Browse files Browse the repository at this point in the history
  • Loading branch information
magnetardev committed Mar 24, 2022
1 parent a109932 commit e0a6dd7
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 18 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "md5-rs"
version = "0.1.3"
version = "0.1.4"
edition = "2021"
license = "MIT"
readme = "README.md"
Expand Down
16 changes: 2 additions & 14 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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:
Expand All @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/util.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
use core::ops::{BitAnd, BitOr, BitXor, Not};

#[inline]
pub fn rotate_u32_left(x: u32, n: u32) -> u32 {
(x << n) | (x >> (32 - n))
}

#[inline]
pub fn f<T>(x: T, y: T, z: T) -> T
where
T: Copy + BitAnd + Not + BitOr,
T: Not<Output = T> + BitAnd<Output = T> + BitOr<Output = T>,
T: Copy + Not<Output = T> + BitAnd<Output = T> + BitOr<Output = T>,
{
(x & y) | (!x & z)
}
Expand Down

0 comments on commit e0a6dd7

Please sign in to comment.