mirror of
https://github.com/storytold/pdfcraft.git
synced 2026-10-30 13:08:48 -06:00
Undo can restore a snapshot from before the last save. Save normally reopens the last saved file and appends the snapshot's objects as an incremental update. When the snapshot's encryption differs from the saved file's (undoing a saved protect, remove protection, password change or rekey, or a compaction that renumbered /Encrypt), that update was read with the wrong key: pages reopened blank, and after undoing a removal the plaintext revision stayed inside the encrypted file. Document::has_same_output_security compares the actual output security: the /Encrypt object number, security dictionary, file key and first file identifier, not passwords or authentication level. Session::save_bytes writes such a snapshot in full, and overlay_changes_from refuses an incompatible overlay before changing anything. Tests cover each transition for every algorithm, inline and indirect /Encrypt, user and owner openings, restricted rights after unlock, the compatible incremental path, redo and byte-stable resaves.