added tr_sha1_to_hex()

This commit is contained in:
Charles Kerr 2008-02-25 20:21:22 +00:00
parent aafadf7170
commit d2f1c7aff3
3 changed files with 16 additions and 5 deletions

View File

@ -192,11 +192,7 @@ tr_metainfoParse( tr_info * inf, const benc_val_t * meta_in, const char * tag )
return TR_EINVALID;
}
for( i = 0; i < SHA_DIGEST_LENGTH; i++ )
{
snprintf( inf->hashString + i * 2, sizeof( inf->hashString ) - i * 2,
"%02x", inf->hash[i] );
}
tr_sha1_to_hex( inf->hashString, inf->hash );
savedname( inf->torrent, sizeof( inf->torrent ), inf->hashString, tag );
/* comment */

View File

@ -883,3 +883,16 @@ tr_getRatio( double numerator, double denominator )
return ratio;
}
void
tr_sha1_to_hex( char * out, const uint8_t * sha1 )
{
static const char hex[] = "0123456789abcdef";
int i;
for (i = 0; i < 20; i++) {
unsigned int val = *sha1++;
*out++ = hex[val >> 4];
*out++ = hex[val & 0xf];
}
*out = '\0';
}

View File

@ -138,6 +138,8 @@ void tr_set_compare( const void * a, size_t aCount,
int tr_compareUint16( uint16_t a, uint16_t b );
int tr_compareUint32( uint32_t a, uint32_t b );
void tr_sha1_to_hex( char * out, const uint8_t * sha1 );
/***
****
***/