diff --git a/g10/ChangeLog b/g10/ChangeLog index 187763ddd..8889fa743 100644 --- a/g10/ChangeLog +++ b/g10/ChangeLog @@ -1,3 +1,20 @@ +2002-05-09 David Shaw + + * getkey.c (merge_selfsigs_main): Make sure the revocation key + list starts clean as this function may be called more than once + (e.g. from functions in --edit). + + * g10.c, encode.c (encode_crypt), sign.c (sign_file, + sign_symencrypt_file): Make --compress-algo work like the + documentation says. It should be like --cipher-algo and + --digest-algo in that it can override the preferences calculation + and impose the setting the user wants. No --compress-algo setting + allows the usual preferences calculation to take place. + + * main.h, compress.c (compress_filter): use new + DEFAULT_COMPRESS_ALGO define, and add a sanity check for compress + algo value. + 2002-05-08 David Shaw * pkclist.c (select_algo_from_prefs): There is an assumed diff --git a/g10/compress.c b/g10/compress.c index 2aecfe9ab..6d85e0181 100644 --- a/g10/compress.c +++ b/g10/compress.c @@ -31,6 +31,7 @@ #include "memory.h" #include "packet.h" #include "filter.h" +#include "main.h" #include "options.h" @@ -224,7 +225,9 @@ compress_filter( void *opaque, int control, PKT_compressed cd; if( !zfx->algo ) - zfx->algo = opt.def_compress_algo; + zfx->algo = DEFAULT_COMPRESS_ALGO; + if( zfx->algo != 1 && zfx->algo != 2 ) + BUG(); memset( &cd, 0, sizeof cd ); cd.len = 0; cd.algorithm = zfx->algo; diff --git a/g10/encode.c b/g10/encode.c index 8cd4a4732..bcafe16bf 100644 --- a/g10/encode.c +++ b/g10/encode.c @@ -407,18 +407,20 @@ encode_crypt( const char *filename, STRLIST remusr ) /* register the compress filter */ if( do_compress ) { - int compr_algo = select_algo_from_prefs( pk_list, PREFTYPE_ZIP ); - if( !compr_algo ) - ; /* don't use compression */ - else { - if( compr_algo == 1 ) - zfx.algo = 1; - if( compr_algo == 2 ) - zfx.algo = 2; - /* Any other compr_algo will fall back to - opt.def_compress_algo in the compress_filter. */ + int compr_algo = opt.def_compress_algo; + + if(compr_algo==-1) + { + if((compr_algo=select_algo_from_prefs( pk_list, PREFTYPE_ZIP))==-1) + compr_algo=DEFAULT_COMPRESS_ALGO; + } + + /* algo 0 means no compression */ + if( compr_algo ) + { + zfx.algo = compr_algo; iobuf_push_filter( out, compress_filter, &zfx ); - } + } } /* do the work */ diff --git a/g10/g10.c b/g10/g10.c index f70348986..f00970fd7 100644 --- a/g10/g10.c +++ b/g10/g10.c @@ -808,7 +808,7 @@ main( int argc, char **argv ) /* note: if you change these lines, look at oOpenPGP */ opt.def_cipher_algo = 0; opt.def_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; @@ -1510,7 +1510,7 @@ main( int argc, char **argv ) if( check_digest_algo(opt.s2k_digest_algo) ) log_error(_("selected digest algorithm is invalid\n")); } - if( opt.def_compress_algo < 0 || opt.def_compress_algo > 2 ) + if( opt.def_compress_algo < -1 || opt.def_compress_algo > 2 ) log_error(_("compress algorithm must be in range %d..%d\n"), 0, 2); if( opt.completes_needed < 1 ) log_error(_("completes-needed must be greater than 0\n")); diff --git a/g10/getkey.c b/g10/getkey.c index fd8eb5b89..c902fbf36 100644 --- a/g10/getkey.c +++ b/g10/getkey.c @@ -1192,6 +1192,12 @@ merge_selfsigs_main( KBNODE keyblock, int *r_revoked ) /* first pass: find the latest direct key self-signature. * We assume that the newest one overrides all others */ + + /* In case this key was already merged */ + m_free(pk->revkey); + pk->revkey=NULL; + pk->numrevkeys=0; + signode = NULL; sigdate = 0; /* helper to find the latest signature */ for(k=keyblock; k && k->pkt->pkttype != PKT_PUBLIC_SUBKEY; k = k->next ) { diff --git a/g10/main.h b/g10/main.h index 6f29e6fed..cba4d4d73 100644 --- a/g10/main.h +++ b/g10/main.h @@ -25,10 +25,10 @@ #include "cipher.h" #include "keydb.h" -#define DEFAULT_CIPHER_ALGO CIPHER_ALGO_CAST5 -#define DEFAULT_PUBKEY_ALGO PUBKEY_ALGO_ELGAMAL -#define DEFAULT_DIGEST_ALGO DIGEST_ALGO_SHA1 - +#define DEFAULT_CIPHER_ALGO CIPHER_ALGO_CAST5 +#define DEFAULT_PUBKEY_ALGO PUBKEY_ALGO_ELGAMAL +#define DEFAULT_DIGEST_ALGO DIGEST_ALGO_SHA1 +#define DEFAULT_COMPRESS_ALGO 1 typedef struct { int header_okay; diff --git a/g10/sign.c b/g10/sign.c index f7ddfd847..25cee51a9 100644 --- a/g10/sign.c +++ b/g10/sign.c @@ -596,7 +596,6 @@ sign_file( STRLIST filenames, int detached, STRLIST locusr, SK_LIST sk_rover = NULL; int multifile = 0; int old_style = opt.rfc1991; - int compr_algo = -1; /* unknown */ u32 timestamp=0,duration=0; memset( &afx, 0, sizeof afx); @@ -633,12 +632,8 @@ sign_file( STRLIST filenames, int detached, STRLIST locusr, opt.pgp2=0; } - if( encryptflag ) { - if( (rc=build_pk_list( remusr, &pk_list, PUBKEY_USAGE_ENC )) ) - goto leave; - if( !old_style ) - compr_algo = select_algo_from_prefs( pk_list, PREFTYPE_ZIP ); - } + if(encryptflag && (rc=build_pk_list( remusr, &pk_list, PUBKEY_USAGE_ENC ))) + goto leave; /* prepare iobufs */ if( multifile ) /* have list of filenames */ @@ -687,17 +682,31 @@ sign_file( STRLIST filenames, int detached, STRLIST locusr, iobuf_push_filter( out, encrypt_filter, &efx ); } - if( opt.compress && !outfile && ( !detached || opt.compress_sigs) ) { - if( !compr_algo ) - ; /* don't use compression */ - else { - if( old_style - || compr_algo == 1 - || (compr_algo == -1 && !encryptflag) ) - zfx.algo = 1; /* use the non optional algorithm */ + if( opt.compress && !outfile && ( !detached || opt.compress_sigs) ) + { + int compr_algo=opt.def_compress_algo; + + /* If not forced by user */ + if(compr_algo==-1) + { + /* If we're not encrypting, then select_algo_from_prefs + will fail and we'll end up with the default. If we are + encrypting, select_algo_from_prefs cannot fail since + there is an assumed preference for uncompressed data. + Still, if it did fail, we'll also end up with the + default. */ + + if((compr_algo=select_algo_from_prefs( pk_list, PREFTYPE_ZIP))==-1) + compr_algo=DEFAULT_COMPRESS_ALGO; + } + + /* algo 0 means no compression */ + if( compr_algo ) + { + zfx.algo = compr_algo; iobuf_push_filter( out, compress_filter, &zfx ); - } - } + } + } /* Write the one-pass signature packets if needed */ if (!detached && !opt.rfc1991) { @@ -925,7 +934,6 @@ sign_symencrypt_file (const char *fname, STRLIST locusr) SK_LIST sk_list = NULL; SK_LIST sk_rover = NULL; int old_style = opt.rfc1991; - int compr_algo = -1; /* unknown */ int algo; u32 timestamp=0,duration=0; @@ -1011,15 +1019,20 @@ sign_symencrypt_file (const char *fname, STRLIST locusr) iobuf_push_filter( out, cipher_filter, &cfx ); /* Push the Zip filter */ - if (opt.compress) { - if (!compr_algo) - ; /* don't use compression */ - else { - if( old_style || compr_algo == 1 ) - zfx.algo = 1; /* use the non optional algorithm */ + if (opt.compress) + { + 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 ); - } - } + } + } /* Write the one-pass signature packets */ /*(current filters: zip - encrypt - armor)*/