Repository navigation
chore(sdk): calculate encrypted segment size instead of measuring it (DSPX-4496) - #1061
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configuration
📒 Files selected for processing (5)
Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review. 📝 WalkthroughWalkthroughThe cipher API now reports encrypted payload sizes. TDF stream writing uses this calculation to choose its default encrypted segment size and rejects encrypted segments whose actual size does not match the reported size. ChangesCipher Payload Sizing
Priority: ⬇️ Low Estimated code review effort: 3 (Moderate) | ~20 minutes Change: Refactor Sequence Diagram(s)sequenceDiagram
participant TDF
participant Cipher
participant CryptoService
TDF->>Cipher: Get encryptedPayloadSize for the default plaintext size
TDF->>CryptoService: Encrypt each plaintext segment
CryptoService-->>TDF: Return encrypted segment bytes
TDF->>Cipher: Get expected size for the plaintext segment
TDF->>TDF: Compare actual and expected encrypted sizes
Suggested reviewers: Merge Risk: ⚪ Minimal · up to No actionable merge-blocking risk was identified; the change is ready for normal test checks. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. A rabbit checks each cipher’s size, Comment |
32d08b0 to
5281f17
Compare
…it (DSPX-4496) writeStream learned `encryptedSegmentSizeDefault` by encrypting a throwaway full-size segment under the payload key and measuring the result. That spent an AES-GCM invocation, and an extra encryption under the caller's key, to learn a constant. Add `SymmetricCipher.encryptedPayloadSize`, implement it exactly for AesGcmCipher (IV + plaintext + 16-byte tag), and derive the default from it. The base implementation throws a named ConfigurationError, so a duck-typed cipher from an older release fails legibly rather than with a TypeError. Every written segment is checked against the arithmetic. A mismatch, such as an injected CryptoService returning a short tag, now fails the write instead of being absorbed by the per-segment `encryptedSegmentSize`. Signed-off-by: Dave Mihalcik <dmihalcik@virtru.com>
5281f17 to
e6951e2
Compare
|



What
writeStreamnow calculatesencryptedSegmentSizeDefaultinstead of measuring it. Before, it encrypted a throwaway full-size segment under the payload key and measured the output.SymmetricCipher.encryptedPayloadSize(plaintextSize):AesGcmCipherimplements it exactly: 12-byte IV + plaintext + 16-byte tag.ConfigurationError, so a duck-typed cipher from an older release fails clearly instead of with aTypeError.CryptoServicereturning a short tag, now fails the write instead of being absorbed by the per-segmentencryptedSegmentSize.Why
encryptedSegmentSizeDefaultover the per-segment sizes.How to test
cd lib && npm test. New tests:AesGcmCipherpredicts the exact ciphertext length for several sizes, from 0 to 1 MiB.CryptoServicetruncates the tag fails mid-stream withConfigurationError.Risk
Low to moderate. This touches the write path. The manifest values are unchanged for
AesGcmCipher, which is the only cipher the SDK ships.DSPX-4496 series
mainmainmainmainAesGcmEncryptorSPIDSPX-4496-encrypted-segment-sizeDSPX-4496-aes-gcm-encryptor#1059, #1060 and #1062 stand alone. #1061 ← #1063 ← #1018 is a stack.
Summary by CodeRabbit