feat: decrypt password-protected OOXML when a password is supplied (#102)
Fixes #102
Summary
Password-protected .docx/.xlsx/.pptx convert when the caller supplies a password, instead of always ending in Encrypted. Plaintext files are untouched; without a password nothing changes.
What changed
to_markdown_with_password(path, password)andto_markdown_bytes_with_password(bytes, format, password): an encrypted OOXML package (OLE container withEncryptionInfo/EncryptedPackage, detected by the same shapeprobe_olealready classifies) is decrypted viaoffice-crypto0.3 and converted as its plaintext zip, so all existing resource limits apply unchanged. No password / empty password / wrong password →Encrypted, exactly as today. Legacy RC4 binary formats (.doc/.ppt/.xls) stay out of scope.- Wrong-password detection: office-crypto does not check the EncryptionInfo password verifier (a wrong key decrypts to noise with an
Okstatus), so the decrypted payload's zip signature (PK) gates success. Documented insrc/package/crypto.rs. - CLI:
-p/--password, withANYDOC_PASSWORDenv fallback since argv leaks into shell history andps. - Node, Python, wasm bindings gain an optional trailing
passwordargument (toMarkdownBytes(bytes, format?, password?),to_markdown_bytes(data, format=None, password=None)); existing signatures keep working.
Fixture provenance
tests/fixtures/encrypted/agile-sha512-docx--errors.docx is an agile SHA-512 encrypted .docx taken from office-crypto's MIT-licensed test suite (password testPassword). It carries the corpus sweep's --errors annotation for the no-password path; tests/fixtures/docx/ detection invariants are unaffected.
Verification
- New integration tests (
tests/encrypted.rs, 5 cases): convert-with-password returns the expected body; no/wrong/empty password →Encrypted; plaintext file with a stray password converts identically. - Unit tests for the crypto wrapper incl. the non-zip-payload gate.
- Full suite green (288 lib + snapshot corpus + encrypted), clippy clean, fmt clean.
- CLI end-to-end: with
ANYDOC_PASSWORD=testPasswordthe fixture converts; without it,error: document is encrypted.
This change was prepared with AI assistance under human direction and review.
Summary by cubic
Decrypts password-protected OOXML when a password is supplied and fixes DOCX list numbering to continue across instances that share an abstract, only restarting overridden levels. Previously encrypted OOXML always returned Encrypted; wrong/empty passwords still do, while plaintext files are unchanged.
- New APIs
to_markdown_with_password(path, password)andto_markdown_bytes_with_password(bytes, format, password)decrypt then convert; exportsis_encrypted_ooxmlanddecrypt_ooxml. Validates the decrypted payload as a zip, rejects wrong passwords before size limits, enforces a 512 MB decrypted-package budget, then applies the usual package limits unchanged. - CLI:
-p/--passwordwithANYDOC_PASSWORDfallback; a missing--passwordvalue is a usage error. Password-bearing path conversions route through byte-level conversion after decryption, using content detection with the path extension as fallback; assets come from the same decrypted bytes. - Bindings: optional trailing
passwordin Node (toMarkdownBytes(bytes, format?, password?)), Python (to_markdown_bytes(data, format=None, password=None)), and wasm; existing call sites continue to work. - DOCX numbering: counters key by the resolved abstract so instances sharing one abstract continue a single sequence; only
lvlOverride/startOverridelevels restart, triggered on first use under the overriding instance. - Merged upstream
main, which added the PDF Parse mode; the Node wrappers keep password routing andparseModeworking together.