()
| 7 | |
| 8 | |
| 9 | def test_encryption(): |
| 10 | text = "some secret information" # keep this data secret |
| 11 | perm = int( |
| 12 | pymupdf.PDF_PERM_ACCESSIBILITY # always use this |
| 13 | | pymupdf.PDF_PERM_PRINT # permit printing |
| 14 | | pymupdf.PDF_PERM_COPY # permit copying |
| 15 | | pymupdf.PDF_PERM_ANNOTATE # permit annotations |
| 16 | ) |
| 17 | owner_pass = "owner" # owner password |
| 18 | user_pass = "user" # user password |
| 19 | encrypt_meth = pymupdf.PDF_ENCRYPT_AES_256 # strongest algorithm |
| 20 | doc = pymupdf.open() # empty pdf |
| 21 | page = doc.new_page() # empty page |
| 22 | page.insert_text((50, 72), text) # insert the data |
| 23 | tobytes = doc.tobytes( |
| 24 | encryption=encrypt_meth, # set the encryption method |
| 25 | owner_pw=owner_pass, # set the owner password |
| 26 | user_pw=user_pass, # set the user password |
| 27 | permissions=perm, # set permissions |
| 28 | ) |
| 29 | doc.close() |
| 30 | doc = pymupdf.open("pdf", tobytes) |
| 31 | assert doc.needs_pass |
| 32 | assert doc.is_encrypted |
| 33 | rc = doc.authenticate("owner") |
| 34 | assert rc == 4 |
| 35 | assert not doc.is_encrypted |
| 36 | doc.close() |
| 37 | doc = pymupdf.open("pdf", tobytes) |
| 38 | rc = doc.authenticate("user") |
| 39 | assert rc == 2 |
nothing calls this directly
no test coverage detected
searching dependent graphs…