diff options
author | Werner Koch <wk@gnupg.org> | 2009-10-02 16:57:55 +0200 |
---|---|---|
committer | Werner Koch <wk@gnupg.org> | 2009-10-02 16:57:55 +0200 |
commit | 71625f56fd98ab37bc05f1806b4b49a2e418ac37 (patch) | |
tree | 24d54f73a41c21241f7b99c3eee15374b1185df6 /g10/decrypt.c | |
parent | Fixed EOF detection for encrypted packets. (diff) | |
download | gnupg2-71625f56fd98ab37bc05f1806b4b49a2e418ac37.tar.xz gnupg2-71625f56fd98ab37bc05f1806b4b49a2e418ac37.zip |
Implement the server comamnd DECRYPT.
Use int instead of gnupg_fd_t in the server.
Comment fixes.
Rename encr-data.c -> decrypt-data.c
Diffstat (limited to 'g10/decrypt.c')
-rw-r--r-- | g10/decrypt.c | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/g10/decrypt.c b/g10/decrypt.c index c76c295c8..68b668864 100644 --- a/g10/decrypt.c +++ b/g10/decrypt.c @@ -97,6 +97,73 @@ decrypt_message (const char *filename) } +/* Same as decrypt_message but takes a file descriptor for input and + output. */ +gpg_error_t +decrypt_message_fd (int input_fd, int output_fd) +{ + gpg_error_t err; + IOBUF fp; + armor_filter_context_t *afx = NULL; + progress_filter_context_t *pfx; + + if (opt.outfp) + return gpg_error (GPG_ERR_BUG); + + pfx = new_progress_context (); + + /* Open the message file. */ + fp = iobuf_open_fd_or_name (input_fd, NULL, "rb"); + if (fp && is_secured_file (iobuf_get_fd (fp))) + { + iobuf_close (fp); + fp = NULL; + errno = EPERM; + } + if (!fp) + { + char xname[64]; + + err = gpg_error_from_syserror (); + snprintf (xname, sizeof xname, "[fd %d]", input_fd); + log_error (_("can't open `%s': %s\n"), xname, gpg_strerror (err)); + release_progress_context (pfx); + return err; + } + + opt.outfp = fdopen (dup (output_fd), "wb"); + if (!opt.outfp) + { + char xname[64]; + + err = gpg_error_from_syserror (); + snprintf (xname, sizeof xname, "[fd %d]", output_fd); + log_error (_("can't open `%s': %s\n"), xname, gpg_strerror (err)); + iobuf_close (fp); + release_progress_context (pfx); + return err; + } + + if (!opt.no_armor) + { + if (use_armor_filter (fp)) + { + afx = new_armor_context (); + push_armor_filter ( afx, fp ); + } + } + + err = proc_encryption_packets ( NULL, fp ); + + iobuf_close (fp); + fclose (opt.outfp); + opt.outfp = NULL; + release_armor_context (afx); + release_progress_context (pfx); + return err; +} + + void decrypt_messages (int nfiles, char *files[]) { |