Description:
Currently, running the "Lock PDF" tool on an already-encrypted file, or the "Unlock PDF" tool on a standard (unencrypted) file, results in irreversible file corruption. We need to implement a validation layer that checks the document's encryption state before triggering any cryptographic operations.
Expected Behavior:
- Lock PDF: Should block execution and show an error toast if the uploaded PDF is already encrypted.
- Unlock PDF: Should block execution and show an error toast if the uploaded PDF is NOT encrypted.
Proposed Solution:
- Implement a
checkEncryptionStatus utility in pdf.service.js using pdfjs-dist to lightly read the file buffer and catch PasswordException (which indicates encryption).
- Add guard clauses to the submit handlers in
LockPdf.jsx and UnlockPdf.jsx to validate the file state via this utility before allowing the user to proceed.
Description:
Currently, running the "Lock PDF" tool on an already-encrypted file, or the "Unlock PDF" tool on a standard (unencrypted) file, results in irreversible file corruption. We need to implement a validation layer that checks the document's encryption state before triggering any cryptographic operations.
Expected Behavior:
Proposed Solution:
checkEncryptionStatusutility inpdf.service.jsusingpdfjs-distto lightly read the file buffer and catchPasswordException(which indicates encryption).LockPdf.jsxandUnlockPdf.jsxto validate the file state via this utility before allowing the user to proceed.