Add ByteSource abstraction for content protection - #22
Open
itsthisjustin wants to merge 9 commits into
Open
Conversation
Introduces a random-access byte source interface and miniz configuration for streaming inflate in the content protection module. ByteSource mirrors FreeInkBook's BookSource shape to enable easy adaptation of various file sources (SD, stdio) without direct filesystem access. Includes dual-mode miniz configuration to either bind to host application's existing miniz or compile a standalone prefixed copy to avoid symbol conflicts.
Make ContentProtection library storage-agnostic by removing SD card file handling implementation. The integrating firmware now provides the ByteSource binding to device storage, keeping the portable library decoupled from specific storage backends.
Remove verbose implementation details from header comments, replacing them with concise descriptions. The comments now focus on what each component does rather than explaining the overall content protection architecture.
Refactors content decryption to use a callback-based sink pattern instead of loading entire files into memory. Adds decryptedSize() method and decryptToSink() interface. Implements chunked reading and decryption with fixed-size buffers (2KB cipher, 4KB output) to reduce memory footprint for large encrypted entries.
Allows embedding applications to classify a plain EPUB before initializing crypto, then transfer ownership of the already-scanned ZIP index instead of scanning the central directory twice. Refactors common opening logic into finishOpen method.
Request 2KB TLS record size limit (RFC 6066) to reduce memory pressure. wolfSSL allocates receive buffers per record, so default 16KB records can cause MEMORY_E failures when heap is constrained (~20KB free). The 2KB limit keeps allocations small while remaining compatible with servers that ignore the extension.
Replace in-memory decryption with streamed chunk processing and parse encryption.xml incrementally instead of loading it whole. Store entry paths as FNV-1a 64-bit hashes instead of strings to reduce per-entry overhead from heap strings to 8 bytes. This prevents OOM aborts on small-heap devices when opening containers with hundreds of encrypted files (~60KB manifests).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Introduces a random-access byte source interface and miniz configuration for streaming inflate in the content protection module. ByteSource mirrors FreeInkBook's BookSource shape to enable easy adaptation of various file sources (SD, stdio) without direct filesystem access. Includes dual-mode miniz configuration to either bind to host application's existing miniz or compile a standalone prefixed copy to avoid symbol conflicts.