aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--g10/ChangeLog12
-rw-r--r--g10/encode.c13
-rw-r--r--g10/g10.c2
-rw-r--r--g10/main.h2
-rw-r--r--g10/misc.c25
-rw-r--r--g10/sign.c19
6 files changed, 50 insertions, 23 deletions
diff --git a/g10/ChangeLog b/g10/ChangeLog
index 55f386e63..13ef4224b 100644
--- a/g10/ChangeLog
+++ b/g10/ChangeLog
@@ -1,5 +1,17 @@
2002-11-24 David Shaw <[email protected]>
+ * main.h, misc.c (default_cipher_algo, default_compress_algo):
+ New. Return the default algorithm by trying
+ --cipher-algo/--compress-algo, then the first item in the pref
+ list, then s2k-cipher-algo or ZIP.
+
+ * sign.c (sign_file, sign_symencrypt_file), encode.c
+ (encode_simple, encode_crypt): Call default_cipher_algo and
+ default_compress_algo to get algorithms.
+
+ * g10.c (main): Allow pref selection for compress algo with
+ --openpgp.
+
* mainproc.c (proc_encrypted): Use --s2k-digest-algo for
passphrase mangling rather than --digest-algo.
diff --git a/g10/encode.c b/g10/encode.c
index a2ca43fb1..5550af4a7 100644
--- a/g10/encode.c
+++ b/g10/encode.c
@@ -194,8 +194,7 @@ encode_simple( const char *filename, int mode, int compat )
s2k->mode = opt.rfc1991? 0:opt.s2k_mode;
s2k->hash_algo = opt.s2k_digest_algo;
cfx.dek = passphrase_to_dek( NULL, 0,
- opt.def_cipher_algo ? opt.def_cipher_algo
- : opt.s2k_cipher_algo , s2k, 2, NULL );
+ default_cipher_algo(), s2k, 2, NULL );
if( !cfx.dek || !cfx.dek->keylen ) {
rc = G10ERR_PASSPHRASE;
m_free(cfx.dek);
@@ -211,9 +210,7 @@ encode_simple( const char *filename, int mode, int compat )
}
if ( !compat ) {
- seskeylen = cipher_get_keylen( opt.def_cipher_algo ?
- opt.def_cipher_algo:
- opt.s2k_cipher_algo ) / 8;
+ seskeylen = cipher_get_keylen( default_cipher_algo() ) / 8;
encode_sesskey( cfx.dek, &dek, enckey );
m_free( cfx.dek ); cfx.dek = dek;
}
@@ -332,9 +329,7 @@ encode_simple( const char *filename, int mode, int compat )
{
if (cfx.dek && cfx.dek->use_mdc)
zfx.new_ctb = 1;
- zfx.algo=opt.def_compress_algo;
- if(zfx.algo==-1)
- zfx.algo=DEFAULT_COMPRESS_ALGO;
+ zfx.algo=default_compress_algo();
iobuf_push_filter( out, compress_filter, &zfx );
}
@@ -564,6 +559,8 @@ encode_crypt( const char *filename, STRLIST remusr )
if((compr_algo=
select_algo_from_prefs(pk_list,PREFTYPE_ZIP,-1,NULL))==-1)
compr_algo=DEFAULT_COMPRESS_ALGO;
+ /* Theoretically impossible to get here since uncompressed
+ is implicit. */
}
else if(!opt.expert &&
select_algo_from_prefs(pk_list,PREFTYPE_ZIP,
diff --git a/g10/g10.c b/g10/g10.c
index 2795cc9b7..e7173f48f 100644
--- a/g10/g10.c
+++ b/g10/g10.c
@@ -1515,7 +1515,7 @@ main( int argc, char **argv )
opt.def_cipher_algo = 0;
opt.def_digest_algo = 0;
opt.cert_digest_algo = 0;
- opt.def_compress_algo = 1;
+ opt.def_compress_algo = -1;
opt.s2k_mode = 3; /* iterated+salted */
opt.s2k_digest_algo = DIGEST_ALGO_SHA1;
opt.s2k_cipher_algo = CIPHER_ALGO_CAST5;
diff --git a/g10/main.h b/g10/main.h
index a1aff3afb..91b7182e2 100644
--- a/g10/main.h
+++ b/g10/main.h
@@ -88,6 +88,8 @@ void deprecated_warning(const char *configname,unsigned int configlineno,
const char *compress_algo_to_string(int algo);
int string_to_compress_algo(const char *string);
int check_compress_algo(int algo);
+int default_cipher_algo(void);
+int default_compress_algo(void);
/*-- helptext.c --*/
void display_online_help( const char *keyword );
diff --git a/g10/misc.c b/g10/misc.c
index fee040f86..c5506948a 100644
--- a/g10/misc.c
+++ b/g10/misc.c
@@ -565,3 +565,28 @@ check_compress_algo(int algo)
return G10ERR_COMPR_ALGO;
}
+
+int
+default_cipher_algo(void)
+{
+ if(opt.def_cipher_algo)
+ return opt.def_cipher_algo;
+ else if(opt.personal_cipher_prefs)
+ return opt.personal_cipher_prefs[0].value;
+ else
+ return opt.s2k_cipher_algo;
+}
+
+/* There is no default_digest_algo function, but see
+ sign.c:hash_for */
+
+int
+default_compress_algo(void)
+{
+ if(opt.def_compress_algo!=-1)
+ return opt.def_compress_algo;
+ else if(opt.personal_compress_prefs)
+ return opt.personal_compress_prefs[0].value;
+ else
+ return DEFAULT_COMPRESS_ALGO;
+}
diff --git a/g10/sign.c b/g10/sign.c
index 8e444ddda..524205228 100644
--- a/g10/sign.c
+++ b/g10/sign.c
@@ -775,7 +775,7 @@ sign_file( STRLIST filenames, int detached, STRLIST locusr,
if((compr_algo=
select_algo_from_prefs(pk_list,PREFTYPE_ZIP,-1,NULL))==-1)
- compr_algo=DEFAULT_COMPRESS_ALGO;
+ compr_algo=default_compress_algo();
}
else if(!opt.expert &&
select_algo_from_prefs(pk_list,PREFTYPE_ZIP,
@@ -1048,7 +1048,7 @@ sign_symencrypt_file (const char *fname, STRLIST locusr)
s2k->mode = opt.rfc1991? 0:opt.s2k_mode;
s2k->hash_algo = opt.s2k_digest_algo;
- algo = opt.def_cipher_algo ? opt.def_cipher_algo : opt.s2k_cipher_algo;
+ algo = default_cipher_algo();
if (!opt.quiet || !opt.batch)
log_info (_("%s encryption will be used\n"),
cipher_algo_to_string(algo) );
@@ -1099,19 +1099,10 @@ sign_symencrypt_file (const char *fname, STRLIST locusr)
iobuf_push_filter( out, cipher_filter, &cfx );
/* Push the Zip filter */
- if (opt.compress)
+ if (opt.compress && default_compress_algo())
{
- int compr_algo=opt.def_compress_algo;
-
- /* Default */
- if(compr_algo==-1)
- compr_algo=DEFAULT_COMPRESS_ALGO;
-
- if (compr_algo)
- {
- zfx.algo = compr_algo;
- iobuf_push_filter( out, compress_filter, &zfx );
- }
+ zfx.algo = default_compress_algo();
+ iobuf_push_filter( out, compress_filter, &zfx );
}
/* Write the one-pass signature packets */