Skip to content

Commit

Permalink
Merge 02a131b into d9275d9
Browse files Browse the repository at this point in the history
  • Loading branch information
kanav99 committed Apr 5, 2021
2 parents d9275d9 + 02a131b commit 3e7a319
Show file tree
Hide file tree
Showing 9 changed files with 381 additions and 501 deletions.
8 changes: 4 additions & 4 deletions benches/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,12 @@ fn custom_criterion() -> Criterion {
Criterion::default().sample_size(SAMPLE_SIZE)
}

fn write(b: &mut Bencher<'_>, bytes_len: u64) {
fn write(b: &mut Bencher<'_>, bytes_len: usize) {
b.iter_batched(
// the setup
|| {
let mut rng = new_test_rng().unwrap();
let bytes = random_bytes(&mut rng, bytes_len as usize);
let bytes = random_bytes(&mut rng, bytes_len);
let storage = Some(SimpleStorage::new());

(bytes, storage)
Expand All @@ -87,12 +87,12 @@ fn write(b: &mut Bencher<'_>, bytes_len: u64) {
);
}

fn read(b: &mut Bencher, bytes_len: u64) {
fn read(b: &mut Bencher, bytes_len: usize) {
b.iter_batched(
// the setup
|| {
let mut rng = new_test_rng().unwrap();
let bytes = random_bytes(&mut rng, bytes_len as usize);
let bytes = random_bytes(&mut rng, bytes_len);
let storage = SimpleStorage::new();
let self_encryptor = SelfEncryptor::new(storage, DataMap::None).unwrap();

Expand Down
10 changes: 5 additions & 5 deletions src/data_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ use std::fmt::{Debug, Error, Formatter, Write};
#[derive(Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord, Clone, Default)]
pub struct ChunkDetails {
/// Index number (starts at 0)
pub chunk_num: u32,
pub chunk_num: usize,
/// Post-encryption hash of chunk
pub hash: Vec<u8>,
/// Pre-encryption hash of chunk
pub pre_hash: Vec<u8>,
/// Size before encryption (compression alters this as well as any possible padding depending
/// on cipher used)
pub source_size: u64,
pub source_size: usize,
}

fn debug_bytes<V: AsRef<[u8]>>(input: V) -> String {
Expand Down Expand Up @@ -91,10 +91,10 @@ pub enum DataMap {
#[allow(clippy::len_without_is_empty)]
impl DataMap {
/// Original (pre-encryption) size of file in DataMap.
pub fn len(&self) -> u64 {
pub fn len(&self) -> usize {
match *self {
DataMap::Chunks(ref chunks) => DataMap::chunks_size(chunks),
DataMap::Content(ref content) => content.len() as u64,
DataMap::Content(ref content) => content.len(),
DataMap::None => 0,
}
}
Expand Down Expand Up @@ -134,7 +134,7 @@ impl DataMap {
}

/// Iterates through the chunks to figure out the total size, i.e. the file size
fn chunks_size(chunks: &[ChunkDetails]) -> u64 {
fn chunks_size(chunks: &[ChunkDetails]) -> usize {
chunks.iter().fold(0, |acc, chunk| acc + chunk.source_size)
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,9 +191,9 @@ pub use crate::{
/// The maximum size of file which can be self_encrypted, defined as 1GB.
pub const MAX_FILE_SIZE: usize = 1024 * 1024 * 1024;
/// The maximum size (before compression) of an individual chunk of the file, defined as 1MB.
pub const MAX_CHUNK_SIZE: u32 = 1024 * 1024;
pub const MAX_CHUNK_SIZE: usize = 1024 * 1024;
/// The minimum size (before compression) of an individual chunk of the file, defined as 1kB.
pub const MIN_CHUNK_SIZE: u32 = 1024;
pub const MIN_CHUNK_SIZE: usize = 1024;
/// Controls the compression-speed vs compression-density tradeoffs. The higher the quality, the
/// slower the compression. Range is 0 to 11.
pub const COMPRESSION_QUALITY: i32 = 6;

0 comments on commit 3e7a319

Please sign in to comment.