add HexToBinary, move to RageUtil
This commit is contained in:
@@ -221,17 +221,6 @@ bool CryptManager::Verify( RString sPath, RString sSignature )
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static RString BinaryToHex( const unsigned char *string, int iNumBytes )
|
|
||||||
{
|
|
||||||
RString s;
|
|
||||||
for( int i=0; i<iNumBytes; i++ )
|
|
||||||
{
|
|
||||||
unsigned val = string[i];
|
|
||||||
s += ssprintf( "%x", val );
|
|
||||||
}
|
|
||||||
return s;
|
|
||||||
}
|
|
||||||
|
|
||||||
RString CryptManager::GetMD5ForFile( RString fn )
|
RString CryptManager::GetMD5ForFile( RString fn )
|
||||||
{
|
{
|
||||||
struct MD5Context md5c;
|
struct MD5Context md5c;
|
||||||
|
|||||||
@@ -113,6 +113,36 @@ bool IsHexVal( const RString &s )
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
RString BinaryToHex( const unsigned char *string, int iNumBytes )
|
||||||
|
{
|
||||||
|
RString s;
|
||||||
|
for( int i=0; i<iNumBytes; i++ )
|
||||||
|
{
|
||||||
|
unsigned val = string[i];
|
||||||
|
s += ssprintf( "%x", val );
|
||||||
|
}
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool HexToBinary( const RString &s, unsigned char *stringOut )
|
||||||
|
{
|
||||||
|
if( !IsHexVal(s) )
|
||||||
|
return false;
|
||||||
|
|
||||||
|
for( int i=0; true; i++ )
|
||||||
|
{
|
||||||
|
if( (int)s.size() <= i*2 )
|
||||||
|
break;
|
||||||
|
RString sByte = s.substr( i*2, 2 );
|
||||||
|
|
||||||
|
uint8_t val = 0;
|
||||||
|
if( sscanf( sByte, "%hx", &val ) != 1 )
|
||||||
|
return false;
|
||||||
|
stringOut[i] = val;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
float HHMMSSToSeconds( const RString &sHHMMSS )
|
float HHMMSSToSeconds( const RString &sHHMMSS )
|
||||||
{
|
{
|
||||||
vector<RString> arrayBits;
|
vector<RString> arrayBits;
|
||||||
|
|||||||
@@ -241,6 +241,8 @@ float fmodfp( float x, float y );
|
|||||||
int power_of_two( int input );
|
int power_of_two( int input );
|
||||||
bool IsAnInt( const RString &s );
|
bool IsAnInt( const RString &s );
|
||||||
bool IsHexVal( const RString &s );
|
bool IsHexVal( const RString &s );
|
||||||
|
RString BinaryToHex( const unsigned char *string, int iNumBytes );
|
||||||
|
bool HexToBinary( const RString &s, unsigned char *stringOut );
|
||||||
float HHMMSSToSeconds( const RString &sHMS );
|
float HHMMSSToSeconds( const RString &sHMS );
|
||||||
RString SecondsToHHMMSS( float fSecs );
|
RString SecondsToHHMMSS( float fSecs );
|
||||||
RString SecondsToMSSMsMs( float fSecs );
|
RString SecondsToMSSMsMs( float fSecs );
|
||||||
|
|||||||
Reference in New Issue
Block a user