Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 57 additions & 4 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ subtle = "2.6.1"
bon = "3.3.0"
shush-rs = "0.1.10"
criterion = { version = "0.5.1", features = ["html_reports"] }
reed-solomon-erasure = "5"

[target.'cfg(target_os = "linux")'.dependencies]
fuse3 = { version = "0.8.1", features = ["tokio-runtime", "unprivileged"] }
Expand Down
1 change: 1 addition & 0 deletions examples/encryptedfs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ async fn main() -> Result<()> {
data_dir.clone(),
Box::new(PasswordProviderImpl {}),
cipher,
None,
false,
)
.await?;
Expand Down
1 change: 1 addition & 0 deletions examples/file_handling.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ async fn main() -> Result<()> {
data_dir.clone(),
Box::new(PasswordProviderImpl),
cipher,
None,
false,
)
.await?;
Expand Down
23 changes: 23 additions & 0 deletions examples/rs_example.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
use rencfs::crypto::rs::RsEncoder;

fn main() {
let encoder = RsEncoder::new(3, 2);
let data = b"hello, this is my message";

println!("Original: {}", String::from_utf8_lossy(data));

let shards = encoder.encode(data).expect("encode failed");
println!("Created {} shards", shards.len());

let mut shards_opt: Vec<Option<Vec<u8>>> = shards.into_iter().map(Some).collect();
shards_opt[0] = None; // drop one data shard
shards_opt[4] = None; // drop one parity shard

println!("Simulated missing shards at indexes 0 and 4");

let recovered = encoder
.reconstruct(&mut shards_opt)
.expect("reconstruct failed");

println!("Recovered: {}", String::from_utf8_lossy(&recovered));
}
3 changes: 2 additions & 1 deletion src/crypto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use serde::{Deserialize, Serialize};
use shush_rs::{ExposeSecret, SecretString, SecretVec};
use strum_macros::{Display, EnumIter, EnumString};
use thiserror::Error;
use tracing::{debug, error, instrument};
use tracing::{debug, instrument};
use write::CryptoInnerWriter;

use crate::crypto::read::{CryptoRead, CryptoReadSeek, RingCryptoRead};
Expand All @@ -29,6 +29,7 @@ use crate::{fs_util, stream_util};

pub mod buf_mut;
pub mod read;
pub mod rs;
pub mod write;

pub static BASE64: GeneralPurpose = GeneralPurpose::new(&STANDARD, NO_PAD);
Expand Down
6 changes: 2 additions & 4 deletions src/crypto/read.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,6 @@ macro_rules! decrypt_block {
}};
}

pub(crate) use decrypt_block;

#[allow(clippy::module_name_repetitions)]
pub struct RingCryptoRead<R: Read> {
input: Option<R>,
Expand Down Expand Up @@ -201,7 +199,7 @@ impl<R: Read + Seek> Seek for RingCryptoRead<R> {
let block_index = self.pos() / self.plaintext_block_size as u64;
let new_block_index = new_pos / self.plaintext_block_size as u64;
if block_index == new_block_index {
let at_full_block_end = self.pos() % self.plaintext_block_size as u64 == 0
let at_full_block_end = self.pos().is_multiple_of(self.plaintext_block_size as u64)
&& self.buf.available_read() == 0;
if self.buf.available() > 0
// this make sure we are not at the end of the current block, which is the start boundary of next block
Expand All @@ -224,7 +222,7 @@ impl<R: Read + Seek> Seek for RingCryptoRead<R> {
))?;
self.buf.clear();
self.block_index = new_block_index;
if new_pos % self.plaintext_block_size as u64 == 0 {
if new_pos.is_multiple_of(self.plaintext_block_size as u64) {
// in case we need to seek at the start of the new block, we need to decrypt here, because we altered
// the block_index but the seek seek_forward from below will not decrypt anything
// as the offset in new block is 0. In that case the po()
Expand Down
Loading
Loading