Skip to content

Commit

Permalink
Merge 3661fb0 into d9275d9
Browse files Browse the repository at this point in the history
  • Loading branch information
kanav99 committed Apr 7, 2021
2 parents d9275d9 + 3661fb0 commit a7104c7
Show file tree
Hide file tree
Showing 10 changed files with 729 additions and 503 deletions.
28 changes: 27 additions & 1 deletion .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ jobs:
steps:
- uses: actions/checkout@v2
with:
fetch-depth: '0'
fetch-depth: "0"
- uses: maidsafe/pr_size_checker@v2
with:
max_lines_changed: 200
Expand Down Expand Up @@ -151,6 +151,32 @@ jobs:
- name: Cargo test
run: cargo test --release

tests32:
name: Test 32bit
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
# Install Rust
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: i686-unknown-linux-gnu
override: true

# Cache.
- name: Cargo cache registry, index and build
uses: actions/cache@v2.1.4
with:
path: |
~/.cargo/registry
~/.cargo/git
target
key: ${{ runner.os }}-cargo-cache-${{ hashFiles('**/Cargo.lock') }}

# Run tests.
- name: Cargo test
run: cargo test --release

# Test publish using --dry-run.
test-publish:
name: Test Publish
Expand Down
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 a7104c7

Please sign in to comment.