feat(store): add createRwFile API and self-contained rw metadata management#445
Draft
kisielewski wants to merge 1 commit into
Draft
Conversation
…gement Introduce createRwFile() — a new public API method that creates an empty random-write file directly, without streaming chunks. The file is ready for read/write access via openFile immediately after creation. Refactor FileHandler to own its dynamic metadata entirely: replace the FileInfo/FileMeta/DecryptedEncKey/FileMetaEncryptor dependencies with a lightweight StaticMeta struct (fileId, resourceId, cipherType, chunkSize, key). FileHandler now computes and signs the rwMeta JSON on every flush using its own file key, and pulls the current server state via storeFileRwPull instead of receiving it as parameters. Simplify FileHandler::sync() to take no arguments — it fetches fresh rw state from the server autonomously. Simplify updateOnServer() to accept only newEncryptedFileSize; it builds and signs the full rwMeta internally. FileReadWriteHandle now calls storeFileRwPull on open to bootstrap the rw state, replacing the previous reliance on pre-fetched EncryptionParams. Server API: add storeFileRwPull, storeFileRwCreate, storeFileRwWrite methods with updated struct names (StoreFileRw* convention) and field names matching the bridge (rwVersion, rwMeta).
kisielewski
commented
Jun 10, 2026
| dmForSigning->set("serverSize", dmServerSize); | ||
| dmForSigning->set("size", dmSize); | ||
| dmForSigning->set("version", newVersion); | ||
| std::string rawSignature = privmx::crypto::Crypto::hmacSha256( |
Member
Author
There was a problem hiding this comment.
JSON serialization is not deterministic across libraries — key ordering, whitespace, and encoding of special values can differ between Poco (C++), and bindings in JS, Java, Swift, C#. Since this string is the HMAC input, any subtle difference breaks signature verification on the other end.
Worth considering a deterministic format, or simply signing a manually constructed string with fields in a fixed order (e.g. size || serverSize || version || hmac).
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.
Important
Depends on:
Summary
StoreApi::createRwFile()— creates an empty random-write file directly, without streaming chunks; ready for read/write access viaopenFileimmediately after creation.FileHandlerto own its dynamic metadata entirely — replaceFileInfo/FileMeta/DecryptedEncKey/FileMetaEncryptordependencies with a lightweightStaticMetastruct.FileHandlernow computes and signsrwMetaJSON on every flush using its own file key.FileHandler::sync()to take no arguments — fetches current rw state from the server autonomously viastoreFileRwPull.FileHandler::updateOnServer()— accepts onlynewEncryptedFileSize; builds and signs the fullrwMetainternally.FileReadWriteHandlenow callsstoreFileRwPullon open to bootstrap state, replacing reliance on pre-fetchedEncryptionParams.StoreRwFile*→StoreFileRw*, fieldsversion/meta→rwVersion/rwMetainStoreFileRandomWriteMeta,StoreFileRwPullResultextended with optionalstoreandfilefields,StoreFileReadModelextended with optionalrwVersion.