* Validate that V and R values are compatible.
(version: EncryptionVersion, revision: EncryptionRevision)
| 379 | * Validate that V and R values are compatible. |
| 380 | */ |
| 381 | function validateVersionRevision(version: EncryptionVersion, revision: EncryptionRevision): void { |
| 382 | // Valid combinations per PDF spec: |
| 383 | // V=1 → R=2 |
| 384 | // V=2 → R=3 |
| 385 | // V=3 → R=3 (unpublished, rare) |
| 386 | // V=4 → R=4 |
| 387 | // V=5 → R=5 or R=6 |
| 388 | |
| 389 | const valid = |
| 390 | (version === 1 && revision === 2) || |
| 391 | (version === 2 && revision === 3) || |
| 392 | (version === 3 && revision === 3) || |
| 393 | (version === 4 && revision === 4) || |
| 394 | (version === 5 && (revision === 5 || revision === 6)); |
| 395 | |
| 396 | if (!valid) { |
| 397 | // Be lenient - warn but allow (some PDFs have weird combinations) |
| 398 | // In strict mode, we'd throw here |
| 399 | console.warn(`Unusual V/R combination: V=${version}, R=${revision}`); |
| 400 | } |
| 401 | } |
| 402 | |
| 403 | /** |
| 404 | * Check if a dictionary represents an encrypted document. |
no test coverage detected