Skip to content

Conversation

@maqi
Copy link
Member

@maqi maqi commented Sep 2, 2025

  • Created an all-in-memory StreamingEncrypt without disk dependent, to be consistent with StreamingDecrypt
  • Created correspondent tests, include encryption with content being pushed in out-of-order.
  • Refactored streaming_encrypt_from_file helper function to utilise the new StreamingEncrypt
  • Reorganized StreamingDecrypt into stream_decrypt.rs, and put StreamingEncrypt into stream_decrypt.rs

Copy link
Member

@grumbach grumbach left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice one! Although this approach is quite hard to use. Why don't we simplify it to a single function that takes in a byte iterator and returns a chunk iterator?

/// # Ok(())
/// # }
/// ```
pub fn new_from_memory(file_size: usize, chunk_store: F) -> Result<Self> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe just new would be enough? And to be even more generic size instead of file_size would be great as we're not necessarily dealing with files.

Comment on lines +324 to +342
/// let storage = Rc::new(RefCell::new(HashMap::new()));
/// let storage_clone = Rc::clone(&storage);
/// let store_chunk = move |hash: XorName, content: Bytes| -> self_encryption::Result<()> {
/// let _ = storage_clone.borrow_mut().insert(hash, content.to_vec());
/// Ok(())
/// };
///
/// let file_size = 10_000;
/// let mut encryptor = StreamingEncrypt::new_from_memory(file_size, store_chunk)?;
///
/// // Process first chunk of data
/// let data1 = Bytes::from(vec![1u8; 5000]);
/// let result1 = encryptor.encrypt_part(0, data1)?;
/// assert!(result1.is_none()); // Not complete yet
///
/// // Process second chunk of data
/// let data2 = Bytes::from(vec![2u8; 5000]);
/// let result2 = encryptor.encrypt_part(5000, data2)?;
/// assert!(result2.is_some()); // Complete! Returns DataMap
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is kind of hard to use, I feel like this could be done in one function call without the whole indexing process which is very error prone.

@grumbach
Copy link
Member

grumbach commented Sep 3, 2025

Replaced by #422

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants