aboutsummaryrefslogtreecommitdiffstats
path: root/g10/decrypt.c
diff options
context:
space:
mode:
authorRepo Admin <[email protected]>2003-06-05 07:14:21 +0000
committerRepo Admin <[email protected]>2003-06-05 07:14:21 +0000
commit7250331472efe70fac928fa06e51c7c80f2b715c (patch)
treed6ec62958ba3971115da3b81c8e1ad0f6d822fe0 /g10/decrypt.c
parentMake use of libgpg-error (diff)
downloadgnupg-7250331472efe70fac928fa06e51c7c80f2b715c.tar.gz
gnupg-7250331472efe70fac928fa06e51c7c80f2b715c.zip
This commit was manufactured by cvs2svn to create branch
'GNUPG-1-9-BRANCH'.
Diffstat (limited to 'g10/decrypt.c')
-rw-r--r--g10/decrypt.c141
1 files changed, 141 insertions, 0 deletions
diff --git a/g10/decrypt.c b/g10/decrypt.c
new file mode 100644
index 000000000..df778d1ad
--- /dev/null
+++ b/g10/decrypt.c
@@ -0,0 +1,141 @@
+/* decrypt.c - verify signed data
+ * Copyright (C) 1998,1999,2000,2001,2002,2003 Free Software Foundation, Inc.
+ *
+ * This file is part of GnuPG.
+ *
+ * GnuPG is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * GnuPG is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+ */
+
+#include <config.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+#include <assert.h>
+
+#include "options.h"
+#include "packet.h"
+#include "errors.h"
+#include "iobuf.h"
+#include "keydb.h"
+#include "memory.h"
+#include "util.h"
+#include "main.h"
+#include "status.h"
+#include "i18n.h"
+
+
+
+/****************
+ * Assume that the input is an encrypted message and decrypt
+ * (and if signed, verify the signature on) it.
+ * This command differs from the default operation, as it never
+ * writes to the filename which is included in the file and it
+ * rejects files which don't begin with an encrypted message.
+ */
+
+int
+decrypt_message( const char *filename )
+{
+ IOBUF fp;
+ armor_filter_context_t afx;
+ progress_filter_context_t pfx;
+ int rc;
+ int no_out=0;
+
+ /* open the message file */
+ fp = iobuf_open(filename);
+ if( !fp ) {
+ log_error(_("can't open `%s'\n"), print_fname_stdin(filename));
+ return G10ERR_OPEN_FILE;
+ }
+
+ handle_progress (&pfx, fp, filename);
+
+ if( !opt.no_armor ) {
+ if( use_armor_filter( fp ) ) {
+ memset( &afx, 0, sizeof afx);
+ iobuf_push_filter( fp, armor_filter, &afx );
+ }
+ }
+
+ if( !opt.outfile ) {
+ no_out = 1;
+ opt.outfile = "-";
+ }
+ rc = proc_encryption_packets( NULL, fp );
+ if( no_out )
+ opt.outfile = NULL;
+ iobuf_close(fp);
+ return rc;
+}
+
+void
+decrypt_messages(int nfiles, char **files)
+{
+ IOBUF fp;
+ armor_filter_context_t afx;
+ progress_filter_context_t pfx;
+ char *p, *output = NULL;
+ int rc = 0;
+
+ if (opt.outfile)
+ {
+ log_error(_("--output doesn't work for this command\n"));
+ return;
+
+ }
+
+ while (nfiles--)
+ {
+ print_file_status(STATUS_FILE_START, *files, 3);
+ output = make_outfile_name(*files);
+ if (!output)
+ goto next_file;
+ fp = iobuf_open(*files);
+ if (!fp)
+ {
+ log_error(_("can't open `%s'\n"), print_fname_stdin(*files));
+ goto next_file;
+ }
+
+ handle_progress (&pfx, fp, *files);
+
+ if (!opt.no_armor)
+ {
+ if (use_armor_filter(fp))
+ {
+ memset(&afx, 0, sizeof afx);
+ iobuf_push_filter(fp, armor_filter, &afx);
+ }
+ }
+ rc = proc_packets(NULL, fp);
+ iobuf_close(fp);
+ if (rc)
+ log_error("%s: decryption failed: %s\n", print_fname_stdin(*files),
+ g10_errstr(rc));
+ p = get_last_passphrase();
+ set_next_passphrase(p);
+ m_free (p);
+
+ next_file:
+ /* Note that we emit file_done even after an error. */
+ write_status( STATUS_FILE_DONE );
+ m_free(output);
+ files++;
+ }
+ set_next_passphrase(NULL);
+}
+