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

cipher: revert SeekNum::from_block_byte change #439

Merged
merged 1 commit into from Dec 30, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 2 additions & 11 deletions cipher/src/stream.rs
Expand Up @@ -114,17 +114,8 @@ macro_rules! impl_seek_num {
impl SeekNum for $t {
fn from_block_byte<T: TryInto<Self>>(block: T, byte: u8, bs: u8) -> Result<Self, OverflowError> {
debug_assert!(byte < bs);
let pos = block
.try_into()
.ok()
.and_then(|v| match byte == 0 {
true => Some(v),
// if `byte` is not zero, then block counter was incremented
false => v.checked_sub(1),
})
.and_then(|v| v.checked_mul(bs as Self))
.and_then(|v| v.checked_add(byte as Self))
.ok_or(OverflowError)?;
let block = block.try_into().map_err(|_| OverflowError)?;
let pos = block.checked_mul(bs as Self).ok_or(OverflowError)? + (byte as Self);
Ok(pos)
}

Expand Down