1
0
mirror of git://git.gnupg.org/gnupg.git synced 2024-05-28 21:50:02 +02:00

gpg: New option --mimemode.

* g10/gpg.c (oMimemode): New.
(opts): Add --mimemode.
(main): Use --mimemode only in rfc4880bis compliance mode.
* g10/options.h (struct opt): Add field "mimemode".
* g10/build-packet.c (do_plaintext): Allow for mode 'm'.
* g10/encrypt.c (encrypt_simple, encrypt_crypt): Use 'm' if requested.
* g10/plaintext.c (handle_plaintext): Handle 'm' mode.
* g10/sign.c (write_plaintext_packet): Handle 'm' mode.
(sign_file, sign_symencrypt_file): Use 'm' if requested.
--

Thsi patch prepares for a proposed change in RFC4880bis to support a
MIME flag.  A literal data packet with the mime flag set is handled
like a 't' or 'u' but CR are not removed.  The PLAINTEXT status line
will also indicate a MIME content.

If --mimemode is used without --rfc4880bis 't' will be used.

Signed-off-by: Werner Koch <wk@gnupg.org>
This commit is contained in:
Werner Koch 2016-07-13 13:31:12 +02:00
parent 95810929f7
commit e148c3caa9
No known key found for this signature in database
GPG Key ID: E3FDFF218E45B72B
6 changed files with 30 additions and 11 deletions

View File

@ -635,6 +635,7 @@ do_plaintext( IOBUF out, int ctb, PKT_plaintext *pt )
write_header(out, ctb, calc_plaintext( pt ) ); write_header(out, ctb, calc_plaintext( pt ) );
log_assert (pt->mode == 'b' || pt->mode == 't' || pt->mode == 'u' log_assert (pt->mode == 'b' || pt->mode == 't' || pt->mode == 'u'
|| pt->mode == 'm'
|| pt->mode == 'l' || pt->mode == '1'); || pt->mode == 'l' || pt->mode == '1');
iobuf_put(out, pt->mode ); iobuf_put(out, pt->mode );
iobuf_put(out, pt->namelen ); iobuf_put(out, pt->namelen );

View File

@ -335,7 +335,7 @@ encrypt_simple (const char *filename, int mode, int use_seskey)
{ {
/* Note that PT has been initialized above in !no_literal mode. */ /* Note that PT has been initialized above in !no_literal mode. */
pt->timestamp = make_timestamp(); pt->timestamp = make_timestamp();
pt->mode = opt.textmode? 't' : 'b'; pt->mode = opt.mimemode? 'm' : opt.textmode? 't' : 'b';
pt->len = filesize; pt->len = filesize;
pt->new_ctb = !pt->len; pt->new_ctb = !pt->len;
pt->buf = inp; pt->buf = inp;
@ -674,7 +674,7 @@ encrypt_crypt (ctrl_t ctrl, int filefd, const char *filename,
if (!opt.no_literal) if (!opt.no_literal)
{ {
pt->timestamp = make_timestamp(); pt->timestamp = make_timestamp();
pt->mode = opt.textmode ? 't' : 'b'; pt->mode = opt.mimemode? 'm' : opt.textmode ? 't' : 'b';
pt->len = filesize; pt->len = filesize;
pt->new_ctb = !pt->len; pt->new_ctb = !pt->len;
pt->buf = inp; pt->buf = inp;

View File

@ -169,6 +169,7 @@ enum cmd_and_opt_values
aServer, aServer,
aTOFUPolicy, aTOFUPolicy,
oMimemode,
oTextmode, oTextmode,
oNoTextmode, oNoTextmode,
oExpert, oExpert,
@ -532,7 +533,8 @@ static ARGPARSE_OPTS opts[] = {
ARGPARSE_s_i (oBZ2CompressLevel, "bzip2-compress-level", "@"), ARGPARSE_s_i (oBZ2CompressLevel, "bzip2-compress-level", "@"),
ARGPARSE_s_n (oBZ2DecompressLowmem, "bzip2-decompress-lowmem", "@"), ARGPARSE_s_n (oBZ2DecompressLowmem, "bzip2-decompress-lowmem", "@"),
ARGPARSE_s_n (oTextmodeShort, NULL, "@"), ARGPARSE_s_n (oMimemode, "mimemode", "@"),
ARGPARSE_s_n (oTextmode, "textmode", N_("use canonical text mode")),
ARGPARSE_s_n (oTextmode, "textmode", N_("use canonical text mode")), ARGPARSE_s_n (oTextmode, "textmode", N_("use canonical text mode")),
ARGPARSE_s_n (oNoTextmode, "no-textmode", "@"), ARGPARSE_s_n (oNoTextmode, "no-textmode", "@"),
@ -2887,9 +2889,11 @@ main (int argc, char **argv)
pargs.r.ret_str, utf8_strings); pargs.r.ret_str, utf8_strings);
break; break;
case oMimemode: opt.mimemode = opt.textmode = 1; break;
case oTextmodeShort: opt.textmode = 2; break; case oTextmodeShort: opt.textmode = 2; break;
case oTextmode: opt.textmode=1; break; case oTextmode: opt.textmode=1; break;
case oNoTextmode: opt.textmode=0; break; case oNoTextmode: opt.textmode=opt.mimemode=0; break;
case oExpert: opt.expert = 1; break; case oExpert: opt.expert = 1; break;
case oNoExpert: opt.expert = 0; break; case oNoExpert: opt.expert = 0; break;
case oDefSigExpire: case oDefSigExpire:
@ -3447,6 +3451,10 @@ main (int argc, char **argv)
if (opt.flags.rfc4880bis) if (opt.flags.rfc4880bis)
log_info ("WARNING: using experimental features from RFC4880bis!\n"); log_info ("WARNING: using experimental features from RFC4880bis!\n");
else
{
opt.mimemode = 0; /* This will use text mode instead. */
}
if (eyes_only) { if (eyes_only) {
if (opt.set_filename) if (opt.set_filename)

View File

@ -57,6 +57,7 @@ struct
int dry_run; int dry_run;
int autostart; int autostart;
int list_only; int list_only;
int mimemode;
int textmode; int textmode;
int expert; int expert;
const char *def_sig_expire; const char *def_sig_expire;

View File

@ -217,11 +217,16 @@ handle_plaintext (PKT_plaintext * pt, md_filter_context_t * mfx,
static off_t count = 0; static off_t count = 0;
int err = 0; int err = 0;
int c; int c;
int convert = (pt->mode == 't' || pt->mode == 'u'); int convert;
#ifdef __riscos__ #ifdef __riscos__
int filetype = 0xfff; int filetype = 0xfff;
#endif #endif
if (pt->mode == 't' || pt->mode == 'u' || pt->mode == 'm')
convert = pt->mode;
else
convert = 0;
/* Let people know what the plaintext info is. This allows the /* Let people know what the plaintext info is. This allows the
receiving program to try and do something different based on the receiving program to try and do something different based on the
format code (say, recode UTF-8 to local). */ format code (say, recode UTF-8 to local). */
@ -279,8 +284,10 @@ handle_plaintext (PKT_plaintext * pt, md_filter_context_t * mfx,
if (mfx->md) if (mfx->md)
gcry_md_putc (mfx->md, c); gcry_md_putc (mfx->md, c);
#ifndef HAVE_DOSISH_SYSTEM #ifndef HAVE_DOSISH_SYSTEM
if (c == '\r') /* convert to native line ending */ /* Convert to native line ending. */
continue; /* fixme: this hack might be too simple */ /* fixme: this hack might be too simple */
if (c == '\r' && convert != 'm')
continue;
#endif #endif
if (fp) if (fp)
{ {
@ -354,7 +361,7 @@ handle_plaintext (PKT_plaintext * pt, md_filter_context_t * mfx,
if (mfx->md) if (mfx->md)
gcry_md_putc (mfx->md, c); gcry_md_putc (mfx->md, c);
#ifndef HAVE_DOSISH_SYSTEM #ifndef HAVE_DOSISH_SYSTEM
if (convert && c == '\r') if (c == '\r' && convert != 'm')
continue; /* fixme: this hack might be too simple */ continue; /* fixme: this hack might be too simple */
#endif #endif
if (fp) if (fp)

View File

@ -605,7 +605,7 @@ write_plaintext_packet (IOBUF out, IOBUF inp, const char *fname, int ptmode)
* data, it is not possible to know the used length * data, it is not possible to know the used length
* without a double read of the file - to avoid that * without a double read of the file - to avoid that
* we simple use partial length packets. */ * we simple use partial length packets. */
if ( ptmode == 't' ) if ( ptmode == 't' || ptmode == 'u' || ptmode == 'm')
filesize = 0; filesize = 0;
} }
else else
@ -1033,7 +1033,8 @@ sign_file (ctrl_t ctrl, strlist_t filenames, int detached, strlist_t locusr,
} }
else { else {
rc = write_plaintext_packet (out, inp, fname, rc = write_plaintext_packet (out, inp, fname,
opt.textmode && !outfile ? 't':'b'); opt.textmode && !outfile ?
(opt.mimemode? 'm':'t'):'b');
} }
/* catch errors from above */ /* catch errors from above */
@ -1337,7 +1338,8 @@ sign_symencrypt_file (ctrl_t ctrl, const char *fname, strlist_t locusr)
/* Pipe data through all filters; i.e. write the signed stuff */ /* Pipe data through all filters; i.e. write the signed stuff */
/*(current filters: zip - encrypt - armor)*/ /*(current filters: zip - encrypt - armor)*/
rc = write_plaintext_packet (out, inp, fname, opt.textmode ? 't':'b'); rc = write_plaintext_packet (out, inp, fname,
opt.textmode ? (opt.mimemode?'m':'t'):'b');
if (rc) if (rc)
goto leave; goto leave;