Skip to content

Add streaming encrypt decrypt and hash pipeline#48

Merged
Adel-Ayoub merged 14 commits into
devfrom
streaming
Feb 27, 2026
Merged

Add streaming encrypt decrypt and hash pipeline#48
Adel-Ayoub merged 14 commits into
devfrom
streaming

Conversation

@Adel-Ayoub

Copy link
Copy Markdown
Collaborator

Summary

  • Low-level streaming primitives: StreamHeader (16B), ChunkAad (9B), ChunkReader/Writer (zero-alloc), last-chunk
    padding with zero-byte validation — 22 unit tests
  • High-level encrypt/decrypt API: TempFileGuard atomic writes, header algorithm cross-check, u64 progress
    arithmetic — 16 API tests
  • Streaming hash: 64KB chunk reads, raw bytes to BLAKE3/SHA-3, digest matches one-shot hash — 5 tests
  • FRB bindings: StreamSink progress callbacks, feed+finalize split for hash, NoopEncryption #[frb(ignore)] fix
  • Dart StreamingService wrapper: encryptFile, decryptFile, hashFile with progress streams
  • 8 integration tests: roundtrip, hash match, progress, wrong key, empty file, small-file padding strip, uniform
    chunk sizes, tampered padding detection

Security hardening

  • Small files padded on disk but decrypted to exact original bytes
  • All encrypted chunks uniform size (no file-size leakage)
  • Truncated files rejected
  • Tampered padding detected end-to-end from Dart

Adel-Ayoub and others added 14 commits February 26, 2026 13:46
…6B): magic/version/algorithm/reserved

  - ChunkAad (9B): index(u64 LE) + is_final(u8) for truncation protection                                          - ChunkReader: fill-in-place zero-alloc read_chunk(&mut chunk)
  - ChunkWriter: internal buffer for single-syscall writes
  - Last-chunk padding with zero-byte validation
  - EncryptedChunk pre-allocation + Default
  - StreamAlgorithm <-> Algorithm conversion bridge
  - Generic finish() + finish_file() for fsync
  - 22 unit tests covering all acceptance criteria
feat(streaming): add low-level streaming primitives                  …
  - encrypt_file_impl / decrypt_file_impl: 64KB AEAD chunk streaming
  - Per-chunk AAD (index + is_final) prevents reorder/truncation/append
  - Last-chunk padding to uniform ENCRYPTED_CHUNK_SIZE
  - Atomic temp-file-then-rename: failed ops leave no partial output
  - Algorithm cross-check between header and CipherHandle
  - Progress callbacks (0.0..1.0) via closure, FRB StreamSink wrappers
  - CipherHandle: add pub(crate) encrypt_raw/decrypt_raw/algorithm_id
  - 16 tests: roundtrip, tamper detection, progress, cleanup guarantees
  - Remove needless borrows in fs::write test calls
  - Replace unwrap_err() with expect_err() to satisfy deny(clippy::unwrap_used)
…pt-decrypt

feat(streaming): add high-level streaming encrypt/decrypt API
…noop.dart referenced core/traits.dart which is not generated (#[frb(ignore)] on Encryption trait).NoopEncryption itself does not need FRB scanning only create_noop_encryption() returning CipherHandle is the public API.
  - hash_file_impl reads file in 64KB chunks, feeds raw bytes to hasher
  - No encryption padding digest matches one-shot blake3_hash/sha3_hash
  - stream_hash_file FRB wrapper with StreamSink<f64> progress
  - pub(crate) update_raw/finalize_raw/reset_raw on HasherHandle
  - New tests: BLAKE3, SHA-3, empty file, 1MB+ file, exact boundary
…noop.dart referenced core/traits.dart which is not generated (#[frb(ignore)] on Encryption trait).NoopEncryption itself does not need FRB scanning only create_noop_encryption() returning CipherHandle is the public API.
feat(streaming): add streaming file hash with BLAKE3/SHA-3
…ity FRB drops the Vec<u8> return when a function also has StreamSink. Stream_hash_file now only feeds data Dart calls hasherFinalize() to obtain the digest.
- Add StreamingService with encryptFile, decryptFile, hashFile
- Add 8 integration tests (6/8 pass)
- Export StreamingService from lib/m_security.dart
… unawaited(executeNormal) for stream functions, so Rust errors arrive as zone errors after the progress stream closes. _guardedStream uses runZonedGuarded + deferred close to forward these to the stream.

  All 8 integration tests pass on macOS, Android, and iOS.
feat(streaming): add Dart StreamingService wrapper and integration tests
@Adel-Ayoub Adel-Ayoub merged commit c35d7ff into dev Feb 27, 2026
5 checks passed
@Adel-Ayoub Adel-Ayoub deleted the streaming branch February 27, 2026 16:30
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