Files
canalun f360de8050 Bug 1975760 - Part 12: Implement the EncryptedRandomAccessStream serialization. r=jari,dom-storage-reviewers,ipc-reviewers,nika
This wires EncryptedRandomAccessStream into the IPC serialization path. It adds
EncryptedRandomAccessStreamParams to the RandomAccessStreamParams union and adds
the corresponding serialization and deserialization handling.

Serialization is performed by an override of the instance Serialize() method,
so that the stream can be used as a drop-in replacement for the cleartext random
access stream. The method saves the current block, serializes the base stream and
the master key, and then closes itself. Serialization cannot fail, so a failure
to save the current block is expressed as parameters that the receiving side rejects.
Note that the logical position is not part of the parameters, so a deserialized
stream starts at zero.

Deserialization similarly goes through the static CreateFromParams() factory instead
of the usual instance Deserialize() method.
DeserializeRandomAccessStream normally default-constructs an empty stream and then
restores its members from the serialized parameters by calling Deserialize().
EncryptedRandomAccessStream does not fit that pattern.
The stream is intentionally constructed through Create() because construction validates
the backing data. In particular, it reads and validates the final block to determine
the logical size. As a result, a valid base stream and master key must already be
available when the object is constructed.
Default-constructing an empty object and restoring those members afterward would
violate these invariants and lead to an awkward design.
Instead, CreateFromParams() deserializes the base stream and master key, then passes
them to Create(). DeserializeRandomAccessStream calls this factory directly. The
instance Deserialize() method remains unreachable.

Differential Revision: https://phabricator.services.mozilla.com/D310747
2026-08-14 05:47:58 +00:00
..