mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 01:17:35 +00:00
pdf: Add a --password option for encrypted PDFs
This commit is contained in:
parent
63670f27de
commit
c781686198
1 changed files with 11 additions and 3 deletions
|
@ -45,6 +45,9 @@ static PDF::PDFErrorOr<int> pdf_main(Main::Arguments arguments)
|
||||||
{
|
{
|
||||||
Core::ArgsParser args_parser;
|
Core::ArgsParser args_parser;
|
||||||
|
|
||||||
|
StringView password;
|
||||||
|
args_parser.add_option(password, "Password for decrypting PDF, if needed", "password", {}, "PASS");
|
||||||
|
|
||||||
StringView in_path;
|
StringView in_path;
|
||||||
args_parser.add_positional_argument(in_path, "Path to input image file", "FILE");
|
args_parser.add_positional_argument(in_path, "Path to input image file", "FILE");
|
||||||
|
|
||||||
|
@ -55,9 +58,14 @@ static PDF::PDFErrorOr<int> pdf_main(Main::Arguments arguments)
|
||||||
auto document = TRY(PDF::Document::create(file->bytes()));
|
auto document = TRY(PDF::Document::create(file->bytes()));
|
||||||
|
|
||||||
if (auto handler = document->security_handler(); handler && !handler->has_user_password()) {
|
if (auto handler = document->security_handler(); handler && !handler->has_user_password()) {
|
||||||
// FIXME: Add a flag for passing in a password and suggest it in this diag.
|
if (password.is_empty()) {
|
||||||
warnln("PDF requires password");
|
warnln("PDF requires password, pass in using --password");
|
||||||
return 1;
|
return 1;
|
||||||
|
}
|
||||||
|
if (!document->security_handler()->try_provide_user_password(password)) {
|
||||||
|
warnln("invalid password '{}'", password);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
TRY(document->initialize());
|
TRY(document->initialize());
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue