1
0
mirror of git://git.gnupg.org/gnupg.git synced 2024-06-05 23:07:49 +02:00

* gpg.c (print_mds), armor.c (armor_filter, parse_hash_header): Add

SHA-224.

* sign.c (write_plaintext_packet), encode.c (encode_simple): Factor
common literal packet setup code from here, to...

* main.h, plaintext.c (setup_plaintext_name): Here. New. Make sure the
literal packet filename field is UTF-8 encoded.

* options.h, gpg.c (main): Make sure --set-filename is UTF-8 encoded
and note when filenames are already UTF-8.
This commit is contained in:
David Shaw 2006-04-20 02:36:05 +00:00
parent ebdd458f82
commit 99b1f3e1da
8 changed files with 98 additions and 50 deletions

View File

@ -1,3 +1,17 @@
2006-04-19 David Shaw <dshaw@jabberwocky.com>
* gpg.c (print_mds), armor.c (armor_filter, parse_hash_header):
Add SHA-224.
* sign.c (write_plaintext_packet), encode.c (encode_simple):
Factor common literal packet setup code from here, to...
* main.h, plaintext.c (setup_plaintext_name): Here. New. Make sure
the literal packet filename field is UTF-8 encoded.
* options.h, gpg.c (main): Make sure --set-filename is UTF-8
encoded and note when filenames are already UTF-8.
2006-04-18 David Shaw <dshaw@jabberwocky.com>
* keyedit.c (menu_backsign): Give some more verbose errors when we

View File

@ -1,6 +1,6 @@
/* armor.c - Armor flter
* Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004,
* 2005 Free Software Foundation, Inc.
* Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
* 2006 Free Software Foundation, Inc.
*
* This file is part of GnuPG.
*
@ -242,12 +242,14 @@ parse_hash_header( const char *line )
found |= 2;
else if( !strncmp( s, "MD5", s2-s ) )
found |= 4;
else if( !strncmp( s, "SHA256", s2-s ) )
else if( !strncmp( s, "SHA224", s2-s ) )
found |= 8;
else if( !strncmp( s, "SHA384", s2-s ) )
else if( !strncmp( s, "SHA256", s2-s ) )
found |= 16;
else if( !strncmp( s, "SHA512", s2-s ) )
else if( !strncmp( s, "SHA384", s2-s ) )
found |= 32;
else if( !strncmp( s, "SHA512", s2-s ) )
found |= 64;
else
return 0;
for(; *s2 && (*s2==' ' || *s2 == '\t'); s2++ )
@ -953,10 +955,12 @@ armor_filter( void *opaque, int control,
if( hashes & 4 )
buf[n++] = DIGEST_ALGO_MD5;
if( hashes & 8 )
buf[n++] = DIGEST_ALGO_SHA256;
buf[n++] = DIGEST_ALGO_SHA224;
if( hashes & 16 )
buf[n++] = DIGEST_ALGO_SHA384;
buf[n++] = DIGEST_ALGO_SHA256;
if( hashes & 32 )
buf[n++] = DIGEST_ALGO_SHA384;
if( hashes & 64 )
buf[n++] = DIGEST_ALGO_SHA512;
buf[1] = n - 2;

View File

@ -1,6 +1,6 @@
/* encode.c - encode data
* Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004,
* 2005 Free Software Foundation, Inc.
* Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
* 2006 Free Software Foundation, Inc.
*
* This file is part of GnuPG.
*
@ -268,22 +268,8 @@ encode_simple( const char *filename, int mode, int use_seskey )
xfree(enc);
}
if (!opt.no_literal) {
/* setup the inner packet */
if( filename || opt.set_filename ) {
char *s = make_basename( opt.set_filename ? opt.set_filename
: filename,
iobuf_get_real_fname( inp ) );
pt = xmalloc( sizeof *pt + strlen(s) - 1 );
pt->namelen = strlen(s);
memcpy(pt->name, s, pt->namelen );
xfree(s);
}
else { /* no filename */
pt = xmalloc( sizeof *pt - 1 );
pt->namelen = 0;
}
}
if (!opt.no_literal)
pt=setup_plaintext_name(filename,inp);
/* Note that PGP 5 has problems decrypting symmetrically encrypted
data if the file length is in the inner packet. It works when

View File

@ -2186,7 +2186,12 @@ main (int argc, char **argv )
riscos_not_implemented("run-as-shm-coprocess");
#endif /* __riscos__ */
break;
case oSetFilename: opt.set_filename = pargs.r.ret_str; break;
case oSetFilename:
if(utf8_strings)
opt.set_filename = pargs.r.ret_str;
else
opt.set_filename = native_to_utf8(pargs.r.ret_str);
break;
case oForYourEyesOnly: eyes_only = 1; break;
case oNoForYourEyesOnly: eyes_only = 0; break;
case oSetPolicyURL:
@ -2212,8 +2217,12 @@ main (int argc, char **argv )
opt.verify_options&=~VERIFY_SHOW_POLICY_URLS;
break;
case oSigKeyserverURL: add_keyserver_url(pargs.r.ret_str,0); break;
case oUseEmbeddedFilename: opt.use_embedded_filename = 1; break;
case oNoUseEmbeddedFilename: opt.use_embedded_filename = 0; break;
case oUseEmbeddedFilename:
opt.flags.use_embedded_filename=1;
break;
case oNoUseEmbeddedFilename:
opt.flags.use_embedded_filename=0;
break;
case oComment:
if(pargs.r.ret_str[0])
append_to_strlist(&opt.comments,pargs.r.ret_str);
@ -3095,6 +3104,9 @@ main (int argc, char **argv )
fname = argc? *argv : NULL;
if(fname && utf8_strings)
opt.flags.utf8_filename=1;
switch( cmd ) {
case aPrimegen:
case aPrintMD:
@ -3919,6 +3931,7 @@ print_mds( const char *fname, int algo )
md_enable( md, DIGEST_ALGO_SHA1 );
md_enable( md, DIGEST_ALGO_RMD160 );
#ifdef USE_SHA256
md_enable( md, DIGEST_ALGO_SHA224 );
md_enable( md, DIGEST_ALGO_SHA256 );
#endif
#ifdef USE_SHA512
@ -3941,6 +3954,7 @@ print_mds( const char *fname, int algo )
print_hashline( md, DIGEST_ALGO_SHA1, fname );
print_hashline( md, DIGEST_ALGO_RMD160, fname );
#ifdef USE_SHA256
print_hashline( md, DIGEST_ALGO_SHA224, fname );
print_hashline( md, DIGEST_ALGO_SHA256, fname );
#endif
#ifdef USE_SHA512
@ -3957,6 +3971,7 @@ print_mds( const char *fname, int algo )
print_hex( md, DIGEST_ALGO_SHA1, fname );
print_hex( md, DIGEST_ALGO_RMD160, fname );
#ifdef USE_SHA256
print_hex( md, DIGEST_ALGO_SHA224, fname );
print_hex( md, DIGEST_ALGO_SHA256, fname );
#endif
#ifdef USE_SHA512

View File

@ -274,6 +274,7 @@ void decrypt_messages(int nfiles, char *files[]);
/*-- plaintext.c --*/
int hash_datafiles( MD_HANDLE md, MD_HANDLE md2,
STRLIST files, const char *sigfilename, int textmode );
PKT_plaintext *setup_plaintext_name(const char *filename,IOBUF iobuf);
/*-- pipemode.c --*/
void run_in_pipemode (void);

View File

@ -170,7 +170,6 @@ struct
STRLIST sig_keyserver_url;
STRLIST cert_subpackets;
STRLIST sig_subpackets;
int use_embedded_filename;
int allow_non_selfsigned_uid;
int allow_freeform_uid;
int no_literal;
@ -221,6 +220,8 @@ struct
made by signing subkeys. If not set, a missing backsig is not
an error (but an invalid backsig still is). */
unsigned int require_cross_cert:1;
unsigned int use_embedded_filename:1;
unsigned int utf8_filename:1;
} flags;
/* Linked list of ways to find a key if the key isn't on the local

View File

@ -1,6 +1,6 @@
/* plaintext.c - process plaintext packets
* Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004,
* 2005, 2006 Free Software Foundation, Inc.
* Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
* 2006 Free Software Foundation, Inc.
*
* This file is part of GnuPG.
*
@ -91,7 +91,7 @@ handle_plaintext( PKT_plaintext *pt, md_filter_context_t *mfx,
log_info(_("data not saved; use option \"--output\" to save it\n"));
nooutput = 1;
}
else if( !opt.use_embedded_filename ) {
else if( !opt.flags.use_embedded_filename ) {
fname = make_outfile_name( iobuf_get_real_fname(pt->buf) );
if( !fname )
fname = ask_outfile_name( pt->name, pt->namelen );
@ -100,9 +100,8 @@ handle_plaintext( PKT_plaintext *pt, md_filter_context_t *mfx,
goto leave;
}
}
else {
fname = make_printable_string( pt->name, pt->namelen, 0 );
}
else
fname=utf8_to_native(pt->name,pt->namelen,0);
if( nooutput )
;
@ -547,3 +546,44 @@ hash_datafiles( MD_HANDLE md, MD_HANDLE md2, STRLIST files,
return 0;
}
/* Set up a plaintext packet with the appropriate filename. If there
is a --set-filename, use it (it's already UTF8). If there is a
regular filename, UTF8-ize it if necessary. If there is no
filenames at all, set the field empty. */
PKT_plaintext *
setup_plaintext_name(const char *filename,IOBUF iobuf)
{
PKT_plaintext *pt;
if(filename || opt.set_filename)
{
char *s;
if(opt.set_filename)
s=make_basename(opt.set_filename,iobuf_get_real_fname(iobuf));
else if(filename && !opt.flags.utf8_filename)
{
char *tmp=native_to_utf8(filename);
s=make_basename(tmp,iobuf_get_real_fname(iobuf));
xfree(tmp);
}
else
s=make_basename(filename,iobuf_get_real_fname(iobuf));
pt = xmalloc (sizeof *pt + strlen(s) - 1);
pt->namelen = strlen (s);
memcpy (pt->name, s, pt->namelen);
xfree (s);
}
else
{
/* no filename */
pt = xmalloc (sizeof *pt - 1);
pt->namelen = 0;
}
return pt;
}

View File

@ -537,21 +537,8 @@ write_plaintext_packet (IOBUF out, IOBUF inp, const char *fname, int ptmode)
u32 filesize;
int rc = 0;
if (!opt.no_literal) {
if (fname || opt.set_filename) {
char *s = make_basename (opt.set_filename? opt.set_filename
: fname,
iobuf_get_real_fname(inp));
pt = xmalloc (sizeof *pt + strlen(s) - 1);
pt->namelen = strlen (s);
memcpy (pt->name, s, pt->namelen);
xfree (s);
}
else { /* no filename */
pt = xmalloc (sizeof *pt - 1);
pt->namelen = 0;
}
}
if (!opt.no_literal)
pt=setup_plaintext_name(fname,inp);
/* try to calculate the length of the data */
if ( !iobuf_is_pipe_filename (fname) && *fname )