messense / mupdf-rs

Rust binding to mupdf
GNU Affero General Public License v3.0
96 stars 21 forks source link

Authentication does not work as intended #82

Open LukasPieger1 opened 3 months ago

LukasPieger1 commented 3 months ago

Hello, I am very new to this crate and rust in general, so sorry in advance if this is a stupid question :smile:

I want to extract links from an encrypted pdf, but cannot seam to figure out how the authenticate-method works. Here is my test function:

    #[test]
    fn extract_lots_of_links_from_encrypted_pdf() {
        let mut doc = Document::from_bytes(BIG_PDF_ENCRYPTED, "").unwrap();
        println!("{}", doc.needs_password().unwrap());          // true
        println!("{}", doc.authenticate("asdfasdf").unwrap()); // true
        println!("{}", doc.needs_password().unwrap());          // true
        let links = extract_links_from_doc(doc).unwrap();
        assert_eq!(38, links.len())
    }

In my understanding the authenticate method should decrypt my file and return true or false depending on if it was successful. The true value here indicates, that decryption was successful, but the doc itself seems unaltered, and extraction of the links shows, that is indeed the case.

Using a wrong password also correctly makes the authenticate method return false.

I'm really stuck here, and would be very grateful, if someone knows what the issue with my code is. I'd be happy to provide any additional information :)