-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
argon2: move
Memory
to its own module (#158)
Also makes `Instance` accept `Memory` as a parameter. This is in preparation for moving slice handling to `Memory`.
- Loading branch information
Showing
3 changed files
with
43 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
//! Memory blocks | ||
|
||
use crate::Block; | ||
|
||
/// Structure containing references to the memory blocks | ||
pub(crate) struct Memory<'a> { | ||
/// Memory blocks | ||
data: &'a mut [Block], | ||
|
||
/// Size of the memory in blocks | ||
size: usize, | ||
} | ||
|
||
impl<'a> Memory<'a> { | ||
/// Instantiate a new memory struct | ||
pub(crate) fn new(data: &'a mut [Block]) -> Self { | ||
let size = data.len(); | ||
|
||
Self { data, size } | ||
} | ||
|
||
/// Get a copy of the block | ||
pub(crate) fn get_block(&self, idx: usize) -> Block { | ||
self.data[idx] | ||
} | ||
|
||
/// Get a mutable reference to the block | ||
pub(crate) fn get_block_mut(&mut self, idx: usize) -> &mut Block { | ||
&mut self.data[idx] | ||
} | ||
|
||
/// Size of the memory | ||
pub(crate) fn len(&self) -> usize { | ||
self.size | ||
} | ||
} |