mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 23:47:45 +00:00
LibPDF: Add implementation of the Standard security handler
Security handlers manage encryption and decription of PDF files. The standard security handler uses RC4/MD5 to perform its crypto (AES as well, but that is not yet implemented).
This commit is contained in:
parent
c98bda8ce6
commit
5b316462b2
9 changed files with 522 additions and 3 deletions
|
@ -41,9 +41,18 @@ PDFErrorOr<NonnullRefPtr<Document>> Document::create(ReadonlyBytes bytes)
|
|||
|
||||
TRY(parser->initialize());
|
||||
|
||||
document->m_trailer = parser->trailer();
|
||||
document->m_catalog = TRY(parser->trailer()->get_dict(document, CommonNames::Root));
|
||||
TRY(document->build_page_tree());
|
||||
TRY(document->build_outline());
|
||||
|
||||
if (document->m_trailer->contains(CommonNames::Encrypt)) {
|
||||
auto encryption_dict = TRY(document->m_trailer->get_dict(document, CommonNames::Encrypt));
|
||||
document->m_security_handler = TRY(SecurityHandler::create(document, encryption_dict));
|
||||
|
||||
// Automatically attempt to unencrypt the document with the empty string. The
|
||||
// result is not important; it is the caller's responsibility to ensure the
|
||||
// document is unencrypted before calling initialize().
|
||||
document->m_security_handler->try_provide_user_password("");
|
||||
}
|
||||
|
||||
return document;
|
||||
}
|
||||
|
@ -54,6 +63,17 @@ Document::Document(NonnullRefPtr<Parser> const& parser)
|
|||
m_parser->set_document(this);
|
||||
}
|
||||
|
||||
PDFErrorOr<void> Document::initialize()
|
||||
{
|
||||
if (m_security_handler)
|
||||
VERIFY(m_security_handler->has_user_password());
|
||||
|
||||
TRY(build_page_tree());
|
||||
TRY(build_outline());
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
PDFErrorOr<Value> Document::get_or_load_value(u32 index)
|
||||
{
|
||||
auto value = get_value(index);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue