mirror of
git://git.gnupg.org/gnupg.git
synced 2025-01-10 13:04:23 +01:00
* 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.
This commit is contained in:
parent
443e083f4a
commit
d52392f9e1
@ -1,3 +1,10 @@
|
|||||||
|
2003-02-05 David Shaw <dshaw@jabberwocky.com>
|
||||||
|
|
||||||
|
* 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.
|
||||||
|
|
||||||
2003-02-04 David Shaw <dshaw@jabberwocky.com>
|
2003-02-04 David Shaw <dshaw@jabberwocky.com>
|
||||||
|
|
||||||
* armor.c (parse_hash_header, armor_filter): Accept the new SHAs
|
* armor.c (parse_hash_header, armor_filter): Accept the new SHAs
|
||||||
|
145
g10/g10.c
145
g10/g10.c
@ -605,7 +605,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 );
|
||||||
@ -2569,40 +2568,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
|
||||||
@ -2636,23 +2684,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;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2673,7 +2716,7 @@ print_mds( const char *fname, int algo )
|
|||||||
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 ) {
|
||||||
@ -2691,30 +2734,18 @@ print_mds( const char *fname, int algo )
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
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) ) {
|
print_hex( md, DIGEST_ALGO_SHA384, fname );
|
||||||
printf("\n%s TIGER = ", fname?pname:"" );
|
print_hex( md, DIGEST_ALGO_SHA512, fname );
|
||||||
print_hex(md_read(md, DIGEST_ALGO_TIGER), 24 );
|
|
||||||
}
|
|
||||||
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);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user