* exec.c (set_exec_path): Add debugging line.

* g10.c (print_hex, print_mds): Print long hash strings a lot neater.
This assumes at least an 80-character display, as there are a few other
similar assumptions here and there.  Users who need unformatted hashes can
still use with-colons.  Check that SHA384 and 512 are available before
using them as they are no longer always available.
This commit is contained in:
David Shaw 2003-02-12 05:18:26 +00:00
parent 257956b490
commit 48ac1127ae
3 changed files with 110 additions and 61 deletions

View File

@ -1,5 +1,14 @@
2003-02-11 David Shaw <dshaw@jabberwocky.com> 2003-02-11 David Shaw <dshaw@jabberwocky.com>
* exec.c (set_exec_path): Add debugging line.
* g10.c (print_hex, print_mds): Print long hash strings a lot
neater. This assumes at least an 80-character display, as there
are a few other similar assumptions here and there. Users who
need unformatted hashes can still use with-colons. Check that
SHA384 and 512 are available before using them as they are no
longer always available.
* Makefile.am: Use a local copy of libexecdir along with @PACKAGE@ * Makefile.am: Use a local copy of libexecdir along with @PACKAGE@
as GNUPG_LIBEXECDIR so it can be easily overridden at make time. as GNUPG_LIBEXECDIR so it can be easily overridden at make time.

View File

@ -112,6 +112,9 @@ int set_exec_path(const char *path,int method)
strcat(p,path); strcat(p,path);
if(DBG_EXTPROG)
log_debug("set_exec_path method %d: %s\n",method,p);
/* Notice that path is never freed. That is intentional due to the /* Notice that path is never freed. That is intentional due to the
way putenv() works. This leaks a few bytes if we call way putenv() works. This leaks a few bytes if we call
set_exec_path multiple times. */ set_exec_path multiple times. */

159
g10/g10.c
View File

@ -626,7 +626,6 @@ static char *build_list( const char *text, char letter,
const char *(*mapf)(int), int (*chkf)(int) ); const char *(*mapf)(int), int (*chkf)(int) );
static void set_cmd( enum cmd_and_opt_values *ret_cmd, static void set_cmd( enum cmd_and_opt_values *ret_cmd,
enum cmd_and_opt_values new_cmd ); enum cmd_and_opt_values new_cmd );
static void print_hex( byte *p, size_t n );
static void print_mds( const char *fname, int algo ); static void print_mds( const char *fname, int algo );
static void add_notation_data( const char *string, int which ); static void add_notation_data( const char *string, int which );
static void add_policy_url( const char *string, int which ); static void add_policy_url( const char *string, int which );
@ -2687,40 +2686,89 @@ g10_exit( int rc )
} }
/* Pretty-print hex hashes. This assumes at least an 80-character
display, but there are a few other similar assumptions in the
display code. */
static void static void
print_hex( byte *p, size_t n ) print_hex( MD_HANDLE md, int algo, const char *fname )
{ {
int i; int i,n,count,indent=0;
const byte *p;
if( n == 16 ) { if(fname)
for(i=0; i < n ; i++, p++ ) { indent=printf("%s: ",fname);
if( i )
putchar(' '); if(indent>40)
if( i && !(i%8) ) {
putchar(' '); printf("\n");
printf("%02X", *p ); indent=0;
}
} }
else if( n == 20 ) {
for(i=0; i < n ; i++, i++, p += 2 ) { if(algo==DIGEST_ALGO_RMD160)
if( i ) indent+=printf("RMD160 = ");
putchar(' '); else if(algo==DIGEST_ALGO_TIGER)
if( i == 10 ) indent+=printf(" TIGER = ");
putchar(' '); else if(algo>0)
printf("%02X%02X", *p, p[1] ); indent+=printf("%6s = ",digest_algo_to_string(algo));
else
algo=abs(algo);
count=indent;
p = md_read( md, algo );
n = md_digest_length(algo);
count+=printf("%02X",*p++);
for(i=1;i<n;i++,p++)
{
if(n==16)
{
if(count+2>79)
{
printf("\n%*s",indent," ");
count=indent;
}
else
count+=printf(" ");
if(!(i%8))
count+=printf(" ");
} }
} else if (n==20)
else { {
for(i=0; i < n ; i += 4, p += 4 ) { if(!(i%2))
if( i ) {
putchar(' '); if(count+4>79)
if( i == 12 && n <= 24 ) {
putchar(' '); printf("\n%*s",indent," ");
printf("%02X%02X%02X%02X", *p, p[1], p[2], p[3] ); count=indent;
}
else
count+=printf(" ");
}
if(!(i%10))
count+=printf(" ");
} }
else
{
if(!(i%4))
{
if(count+8>79)
{
printf("\n%*s",indent," ");
count=indent;
}
else
count+=printf(" ");
}
}
count+=printf("%02X",*p);
} }
printf("\n");
} }
static void static void
@ -2754,23 +2802,18 @@ print_mds( const char *fname, int algo )
char buf[1024]; char buf[1024];
size_t n; size_t n;
MD_HANDLE md; MD_HANDLE md;
char *pname;
if( !fname ) { if( !fname ) {
fp = stdin; fp = stdin;
#ifdef HAVE_DOSISH_SYSTEM #ifdef HAVE_DOSISH_SYSTEM
setmode ( fileno(fp) , O_BINARY ); setmode ( fileno(fp) , O_BINARY );
#endif #endif
pname = m_strdup("[stdin]: ");
} }
else { else {
pname = m_alloc(strlen(fname)+3);
strcpy(stpcpy(pname,fname),": ");
fp = fopen( fname, "rb" ); fp = fopen( fname, "rb" );
} }
if( !fp ) { if( !fp ) {
log_error("%s%s\n", pname, strerror(errno) ); log_error("%s: %s\n", fname?fname:"[stdin]", strerror(errno) );
m_free(pname);
return; return;
} }
@ -2784,14 +2827,16 @@ print_mds( const char *fname, int algo )
if( !check_digest_algo(DIGEST_ALGO_TIGER) ) if( !check_digest_algo(DIGEST_ALGO_TIGER) )
md_enable( md, DIGEST_ALGO_TIGER ); md_enable( md, DIGEST_ALGO_TIGER );
md_enable( md, DIGEST_ALGO_SHA256 ); md_enable( md, DIGEST_ALGO_SHA256 );
md_enable( md, DIGEST_ALGO_SHA384 ); if( !check_digest_algo(DIGEST_ALGO_SHA384) )
md_enable( md, DIGEST_ALGO_SHA512 ); md_enable( md, DIGEST_ALGO_SHA384 );
if( !check_digest_algo(DIGEST_ALGO_SHA512) )
md_enable( md, DIGEST_ALGO_SHA512 );
} }
while( (n=fread( buf, 1, DIM(buf), fp )) ) while( (n=fread( buf, 1, DIM(buf), fp )) )
md_write( md, buf, n ); md_write( md, buf, n );
if( ferror(fp) ) if( ferror(fp) )
log_error("%s%s\n", pname, strerror(errno) ); log_error("%s: %s\n", fname?fname:"[stdin]", strerror(errno) );
else { else {
md_final(md); md_final(md);
if ( opt.with_colons ) { if ( opt.with_colons ) {
@ -2804,35 +2849,27 @@ print_mds( const char *fname, int algo )
if( !check_digest_algo(DIGEST_ALGO_TIGER) ) if( !check_digest_algo(DIGEST_ALGO_TIGER) )
print_hashline( md, DIGEST_ALGO_TIGER, fname ); print_hashline( md, DIGEST_ALGO_TIGER, fname );
print_hashline( md, DIGEST_ALGO_SHA256, fname ); print_hashline( md, DIGEST_ALGO_SHA256, fname );
print_hashline( md, DIGEST_ALGO_SHA384, fname ); if( !check_digest_algo(DIGEST_ALGO_SHA384) )
print_hashline( md, DIGEST_ALGO_SHA512, fname ); print_hashline( md, DIGEST_ALGO_SHA384, fname );
if( !check_digest_algo(DIGEST_ALGO_SHA512) )
print_hashline( md, DIGEST_ALGO_SHA512, fname );
} }
} }
else { else {
if( algo ) { if( algo )
if( fname ) print_hex(md,-algo,fname);
fputs( pname, stdout );
print_hex(md_read(md, algo), md_digest_length(algo) );
}
else { else {
printf( "%s MD5 = ", fname?pname:"" ); print_hex( md, DIGEST_ALGO_MD5, fname );
print_hex(md_read(md, DIGEST_ALGO_MD5), 16 ); print_hex( md, DIGEST_ALGO_SHA1, fname );
printf("\n%s SHA1 = ", fname?pname:"" ); print_hex( md, DIGEST_ALGO_RMD160, fname );
print_hex(md_read(md, DIGEST_ALGO_SHA1), 20 ); if( !check_digest_algo(DIGEST_ALGO_TIGER) )
printf("\n%sRMD160 = ", fname?pname:"" ); print_hex( md, DIGEST_ALGO_TIGER, fname );
print_hex(md_read(md, DIGEST_ALGO_RMD160), 20 ); print_hex( md, DIGEST_ALGO_SHA256, fname );
if( !check_digest_algo(DIGEST_ALGO_TIGER) ) { if( !check_digest_algo(DIGEST_ALGO_SHA384) )
printf("\n%s TIGER = ", fname?pname:"" ); print_hex( md, DIGEST_ALGO_SHA384, fname );
print_hex(md_read(md, DIGEST_ALGO_TIGER), 24 ); if( !check_digest_algo(DIGEST_ALGO_SHA512) )
} print_hex( md, DIGEST_ALGO_SHA512, fname );
printf("\n%sSHA256 = ", fname?pname:"" );
print_hex(md_read(md, DIGEST_ALGO_SHA256), 32 );
printf("\n%sSHA384 = ", fname?pname:"" );
print_hex(md_read(md, DIGEST_ALGO_SHA384), 48 );
printf("\n%sSHA512 = ", fname?pname:"" );
print_hex(md_read(md, DIGEST_ALGO_SHA512), 64 );
} }
putchar('\n');
} }
} }
md_close(md); md_close(md);