Ignore:
Timestamp:
Nov 20, 2009, 4:38:19 AM (12 years ago)
Author:
charles
Message:

(trunk libT) #2096: add code magnet URL parser and unit tests

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/utils.c

    r9497 r9531  
    903903
    904904void
    905 tr_sha1_to_hex( char *          out,
    906                 const uint8_t * sha1 )
    907 {
     905tr_sha1_to_hex( char * out, const uint8_t * sha1 )
     906{
     907    int i;
    908908    static const char hex[] = "0123456789abcdef";
    909     int               i;
    910 
    911     for( i = 0; i < 20; i++ )
    912     {
    913         unsigned int val = *sha1++;
     909
     910    for( i=0; i<20; ++i )
     911    {
     912        const unsigned int val = *sha1++;
    914913        *out++ = hex[val >> 4];
    915914        *out++ = hex[val & 0xf];
    916915    }
     916
    917917    *out = '\0';
     918}
     919
     920void
     921tr_hex_to_sha1( uint8_t * out, const char * in )
     922{
     923    int i;
     924    static const char hex[] = "0123456789abcdef";
     925
     926    for( i=0; i<20; ++i )
     927    {
     928        const int hi = strchr( hex, *in++ ) - hex;
     929        const int lo = strchr( hex, *in++ ) - hex;
     930        *out++ = (uint8_t)( (hi<<4) | lo );
     931    }
    918932}
    919933
Note: See TracChangeset for help on using the changeset viewer.