From 75b6425fe9ce8136dbc852415471708d365b4d25 Mon Sep 17 00:00:00 2001 From: Tor Andersson Date: Thu, 19 Jan 2012 00:58:09 +0100 Subject: Remove confusing optional 'password' argument to pdf_open_xref. Require that clients call pdf_needs_password/pdf_authenticate_password instead. For dumb clients, we still allow for decrypting a file with a blank password without calling those functions. --- apps/pdfshow.c | 35 ++++++++++++++++++++++------------- 1 file changed, 22 insertions(+), 13 deletions(-) (limited to 'apps/pdfshow.c') diff --git a/apps/pdfshow.c b/apps/pdfshow.c index a84e962b..2fbfdc2f 100644 --- a/apps/pdfshow.c +++ b/apps/pdfshow.c @@ -205,26 +205,35 @@ int main(int argc, char **argv) exit(1); } - xref = pdf_open_xref(ctx, filename, password); + fz_var(xref); + fz_try(ctx) + { + xref = pdf_open_xref(ctx, filename); + if (pdf_needs_password(xref)) + if (!pdf_authenticate_password(xref, password)) + fz_throw(ctx, "cannot authenticate password: %s", filename); - if (fz_optind == argc) - showtrailer(); + if (fz_optind == argc) + showtrailer(); - while (fz_optind < argc) - { - switch (argv[fz_optind][0]) + while (fz_optind < argc) { - case 't': showtrailer(); break; - case 'x': showxref(); break; - case 'p': showpagetree(); break; - case 'g': showgrep(filename); break; - default: showobject(atoi(argv[fz_optind]), 0); break; + switch (argv[fz_optind][0]) + { + case 't': showtrailer(); break; + case 'x': showxref(); break; + case 'p': showpagetree(); break; + case 'g': showgrep(filename); break; + default: showobject(atoi(argv[fz_optind]), 0); break; + } + fz_optind++; } - fz_optind++; + } + fz_catch(ctx) + { } pdf_free_xref(xref); - fz_flush_warnings(ctx); fz_free_context(ctx); return 0; } -- cgit v1.2.3