Changeset View
Changeset View
Standalone View
Standalone View
tests/run-decrypt.c
Show First 20 Lines • Show All 82 Lines • ▼ Show 20 Lines | fputs ("usage: " PGM " [options] FILE\n\n" | ||||
" --openpgp use the OpenPGP protocol (default)\n" | " --openpgp use the OpenPGP protocol (default)\n" | ||||
" --cms use the CMS protocol\n" | " --cms use the CMS protocol\n" | ||||
" --export-session-key show the session key\n" | " --export-session-key show the session key\n" | ||||
" --override-session-key STRING use STRING as session key\n" | " --override-session-key STRING use STRING as session key\n" | ||||
" --request-origin STRING use STRING as request origin\n" | " --request-origin STRING use STRING as request origin\n" | ||||
" --no-symkey-cache disable the use of that cache\n" | " --no-symkey-cache disable the use of that cache\n" | ||||
" --ignore-mdc-error allow decryption of legacy data\n" | " --ignore-mdc-error allow decryption of legacy data\n" | ||||
" --unwrap remove only the encryption layer\n" | " --unwrap remove only the encryption layer\n" | ||||
" --diagnostics print diagnostics\n" | |||||
, stderr); | , stderr); | ||||
exit (ex); | exit (ex); | ||||
} | } | ||||
int | int | ||||
main (int argc, char **argv) | main (int argc, char **argv) | ||||
{ | { | ||||
int last_argc = -1; | int last_argc = -1; | ||||
gpgme_error_t err; | gpgme_error_t err; | ||||
gpgme_ctx_t ctx; | gpgme_ctx_t ctx; | ||||
gpgme_protocol_t protocol = GPGME_PROTOCOL_OpenPGP; | gpgme_protocol_t protocol = GPGME_PROTOCOL_OpenPGP; | ||||
gpgme_decrypt_flags_t flags = 0; | gpgme_decrypt_flags_t flags = 0; | ||||
FILE *fp_in = NULL; | FILE *fp_in = NULL; | ||||
gpgme_data_t in = NULL; | gpgme_data_t in = NULL; | ||||
gpgme_data_t out = NULL; | gpgme_data_t out = NULL; | ||||
gpgme_decrypt_result_t result; | gpgme_decrypt_result_t result; | ||||
int print_status = 0; | int print_status = 0; | ||||
int export_session_key = 0; | int export_session_key = 0; | ||||
const char *override_session_key = NULL; | const char *override_session_key = NULL; | ||||
const char *request_origin = NULL; | const char *request_origin = NULL; | ||||
int no_symkey_cache = 0; | int no_symkey_cache = 0; | ||||
int ignore_mdc_error = 0; | int ignore_mdc_error = 0; | ||||
int raw_output = 0; | int raw_output = 0; | ||||
int diagnostics = 0; | |||||
if (argc) | if (argc) | ||||
{ argc--; argv++; } | { argc--; argv++; } | ||||
while (argc && last_argc != argc ) | while (argc && last_argc != argc ) | ||||
{ | { | ||||
last_argc = argc; | last_argc = argc; | ||||
if (!strcmp (*argv, "--")) | if (!strcmp (*argv, "--")) | ||||
▲ Show 20 Lines • Show All 49 Lines • ▼ Show 20 Lines | while (argc && last_argc != argc ) | ||||
no_symkey_cache = 1; | no_symkey_cache = 1; | ||||
argc--; argv++; | argc--; argv++; | ||||
} | } | ||||
else if (!strcmp (*argv, "--ignore-mdc-error")) | else if (!strcmp (*argv, "--ignore-mdc-error")) | ||||
{ | { | ||||
ignore_mdc_error = 1; | ignore_mdc_error = 1; | ||||
argc--; argv++; | argc--; argv++; | ||||
} | } | ||||
else if (!strcmp (*argv, "--diagnostics")) | |||||
{ | |||||
diagnostics = 1; | |||||
argc--; argv++; | |||||
} | |||||
else if (!strcmp (*argv, "--unwrap")) | else if (!strcmp (*argv, "--unwrap")) | ||||
{ | { | ||||
flags |= GPGME_DECRYPT_UNWRAP; | flags |= GPGME_DECRYPT_UNWRAP; | ||||
raw_output = 1; | raw_output = 1; | ||||
argc--; argv++; | argc--; argv++; | ||||
} | } | ||||
else if (!strncmp (*argv, "--", 2)) | else if (!strncmp (*argv, "--", 2)) | ||||
show_usage (1); | show_usage (1); | ||||
▲ Show 20 Lines • Show All 90 Lines • ▼ Show 20 Lines | if (err) | ||||
{ | { | ||||
fprintf (stderr, PGM ": error allocating data object: %s\n", | fprintf (stderr, PGM ": error allocating data object: %s\n", | ||||
gpgme_strerror (err)); | gpgme_strerror (err)); | ||||
exit (1); | exit (1); | ||||
} | } | ||||
err = gpgme_op_decrypt_ext (ctx, flags, in, out); | err = gpgme_op_decrypt_ext (ctx, flags, in, out); | ||||
result = gpgme_op_decrypt_result (ctx); | result = gpgme_op_decrypt_result (ctx); | ||||
if (diagnostics) | |||||
{ | |||||
gpgme_data_t diag; | |||||
gpgme_error_t diag_err; | |||||
gpgme_data_new (&diag); | |||||
diag_err = gpgme_op_getauditlog (ctx, diag, GPGME_AUDITLOG_DIAG); | |||||
if (diag_err) | |||||
{ | |||||
fprintf (stderr, PGM ": getting diagnostics failed: %s\n", | |||||
gpgme_strerror (diag_err)); | |||||
} | |||||
fputs ("Begin Diagnostics:\n", stdout); | |||||
print_data (diag); | |||||
fputs ("End Diagnostics.\n", stdout); | |||||
gpgme_data_release (diag); | |||||
} | |||||
if (err) | if (err) | ||||
{ | { | ||||
fprintf (stderr, PGM ": decrypt failed: %s\n", gpgme_strerror (err)); | fprintf (stderr, PGM ": decrypt failed: %s\n", gpgme_strerror (err)); | ||||
if (result) | if (result) | ||||
print_result (result); | print_result (result); | ||||
exit (1); | exit (1); | ||||
} | } | ||||
if (result) | if (result) | ||||
Show All 16 Lines |