aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTimo Schulz <[email protected]>2002-01-15 16:52:36 +0000
committerTimo Schulz <[email protected]>2002-01-15 16:52:36 +0000
commite17cd91abe3c64dfc086003d8f8711d23f2c84db (patch)
tree1b7a6fd7bd963c562b78e195bc5ce1f028e9818f
parentFixed some typos. (diff)
downloadgnupg-e17cd91abe3c64dfc086003d8f8711d23f2c84db.tar.gz
gnupg-e17cd91abe3c64dfc086003d8f8711d23f2c84db.zip
New command --decrypt-files.
Some fixes.
-rw-r--r--doc/DETAILS3
-rw-r--r--g10/ChangeLog8
-rw-r--r--g10/decrypt.c55
-rw-r--r--g10/encode.c77
-rw-r--r--g10/g10.c8
-rw-r--r--g10/main.h1
6 files changed, 111 insertions, 41 deletions
diff --git a/doc/DETAILS b/doc/DETAILS
index dc75b9384..3581304a6 100644
--- a/doc/DETAILS
+++ b/doc/DETAILS
@@ -221,7 +221,8 @@ more arguments in future versions.
Start processing a file <filename>. <what> indicates the performed
operation:
1 - verify
- 2 - encrypt
+ 2 - encrypt
+ 3 - decrypt
FILE_DONE
Marks the end of a file processing which has been started
diff --git a/g10/ChangeLog b/g10/ChangeLog
index 61acb9ba1..8bae70472 100644
--- a/g10/ChangeLog
+++ b/g10/ChangeLog
@@ -1,3 +1,11 @@
+2002-01-15 Timo Schulz <[email protected]>
+
+ * encode.c (encode_crypt_files): Fail if --output is used.
+
+ * g10.c: New command --decrypt-files.
+
+ * decrypt.c (decrypt_messages): New.
+
2002-01-09 David Shaw <[email protected]>
* g10.c, misc.c, gpgv.c: move idea_cipher_warn to misc.c so gpgv.c
diff --git a/g10/decrypt.c b/g10/decrypt.c
index f444fda05..6e43295ba 100644
--- a/g10/decrypt.c
+++ b/g10/decrypt.c
@@ -33,6 +33,7 @@
#include "memory.h"
#include "util.h"
#include "main.h"
+#include "status.h"
#include "i18n.h"
@@ -78,5 +79,59 @@ decrypt_message( const char *filename )
return rc;
}
+void
+decrypt_messages(int nfiles, char **files)
+{
+ IOBUF fp;
+ armor_filter_context_t afx;
+ 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)
+ continue;
+ fp = iobuf_open(*files);
+ if (!fp)
+ {
+ log_error(_("can't open `%s'\n"), print_fname_stdin(*files));
+ continue;
+ }
+ 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);
+ files++;
+ m_free(output);
+ write_status( STATUS_FILE_DONE );
+ }
+ set_next_passphrase(NULL);
+}
+
+
+
+
+
+
diff --git a/g10/encode.c b/g10/encode.c
index 38c672433..cd3d29a0d 100644
--- a/g10/encode.c
+++ b/g10/encode.c
@@ -568,47 +568,46 @@ write_pubkey_enc_from_list( PK_LIST pk_list, DEK *dek, IOBUF out )
void
encode_crypt_files(int nfiles, char **files, STRLIST remusr)
{
- int rc = 0;
+ int rc = 0;
- if (opt.outfile)
- {
- if (opt.verbose)
- log_info(_("ignore --output for multiple files"));
- opt.outfile = NULL;
- }
+ if (opt.outfile)
+ {
+ log_error(_("--output doesn't work for this command\n"));
+ return;
+ }
- if (!nfiles)
- {
- char line[2048];
- unsigned int lno = 0;
- while ( fgets(line, DIM(line), stdin) )
- {
- lno++;
- if (!*line || line[strlen(line)-1] != '\n')
- {
- log_error("input line %u too long or missing LF\n", lno);
- return;
- }
- line[strlen(line)-1] = '\0';
- print_file_status(STATUS_FILE_START, line, 2);
- if ( (rc = encode_crypt(line, remusr)) )
- log_error("%s: encryption failed: %s\n",
- print_fname_stdin(line), g10_errstr(rc) );
- write_status( STATUS_FILE_DONE );
- }
- }
- else
- {
- while (nfiles--)
- {
- print_file_status(STATUS_FILE_START, *files, 2);
- if ( (rc = encode_crypt(*files, remusr)) )
- log_error("%s: encryption failed: %s\n",
- print_fname_stdin(*files), g10_errstr(rc) );
- write_status( STATUS_FILE_DONE );
- files++;
- }
- }
+ if (!nfiles)
+ {
+ char line[2048];
+ unsigned int lno = 0;
+ while ( fgets(line, DIM(line), stdin) )
+ {
+ lno++;
+ if (!*line || line[strlen(line)-1] != '\n')
+ {
+ log_error("input line %u too long or missing LF\n", lno);
+ return;
+ }
+ line[strlen(line)-1] = '\0';
+ print_file_status(STATUS_FILE_START, line, 2);
+ if ( (rc = encode_crypt(line, remusr)) )
+ log_error("%s: encryption failed: %s\n",
+ print_fname_stdin(line), g10_errstr(rc) );
+ write_status( STATUS_FILE_DONE );
+ }
+ }
+ else
+ {
+ while (nfiles--)
+ {
+ print_file_status(STATUS_FILE_START, *files, 2);
+ if ( (rc = encode_crypt(*files, remusr)) )
+ log_error("%s: encryption failed: %s\n",
+ print_fname_stdin(*files), g10_errstr(rc) );
+ write_status( STATUS_FILE_DONE );
+ files++;
+ }
+ }
}
diff --git a/g10/g10.c b/g10/g10.c
index 66f72f867..60997f38b 100644
--- a/g10/g10.c
+++ b/g10/g10.c
@@ -72,6 +72,7 @@ enum cmd_and_opt_values { aNull = 0,
oShowNotation,
oNoShowNotation,
oBatch = 500,
+ aDecryptFiles,
aClearsign,
aStore,
aKeygen,
@@ -273,6 +274,7 @@ static ARGPARSE_OPTS opts[] = {
{ aSym, "symmetric", 256, N_("encryption only with symmetric cipher")},
{ aStore, "store", 256, N_("store only")},
{ aDecrypt, "decrypt", 256, N_("decrypt data (default)")},
+ { aDecryptFiles, "decrypt-files", 256, N_("|[files]|decrypt files")},
{ aVerify, "verify" , 256, N_("verify a signature")},
{ aVerifyFiles, "verify-files" , 256, "@" },
{ aListKeys, "list-keys", 256, N_("list keys")},
@@ -900,6 +902,7 @@ main( int argc, char **argv )
case aSym: set_cmd( &cmd, aSym); break;
case aDecrypt: set_cmd( &cmd, aDecrypt); break;
+ case aDecryptFiles: set_cmd( &cmd, aDecryptFiles); break;
case aEncr: set_cmd( &cmd, aEncr); break;
case aEncrFiles: set_cmd( &cmd, aEncrFiles ); break;
@@ -1611,7 +1614,10 @@ main( int argc, char **argv )
log_error("decrypt_message failed: %s\n", g10_errstr(rc) );
break;
-
+ case aDecryptFiles:
+ decrypt_messages(argc, argv);
+ break;
+
case aSignKey: /* sign the key given as argument */
if( argc != 1 )
wrong_args(_("--sign-key user-id"));
diff --git a/g10/main.h b/g10/main.h
index c1cb2fbee..85ba3b00a 100644
--- a/g10/main.h
+++ b/g10/main.h
@@ -169,6 +169,7 @@ int verify_files( int nfiles, char **files );
/*-- decrypt.c --*/
int decrypt_message( const char *filename );
+void decrypt_messages(int nfiles, char **files);
/*-- plaintext.c --*/
int hash_datafiles( MD_HANDLE md, MD_HANDLE md2,