[CryptManager] Added SHA1File Lua binding.

This commit is contained in:
AJ Kelly
2011-05-20 01:56:49 -05:00
parent 38246f7fea
commit 60669635b4
3 changed files with 30 additions and 0 deletions
+4
View File
@@ -8,6 +8,10 @@ ________________________________________________________________________________
StepMania 5.0 $NEXT | 20110xyy
--------------------------------------------------------------------------------
2011/05/20
----------
* [CryptManager] Added SHA1File Lua binding. [AJ]
2011/05/19
----------
* [BPMDisplay] Add CourseCycleSpeed metric. [AJ]
+25
View File
@@ -404,6 +404,23 @@ RString CryptManager::GetSHA1ForString( RString sData )
return RString( (const char *) digest, sizeof(digest) );
}
RString CryptManager::GetSHA1ForFile( RString fn )
{
RageFile file;
if( !file.Open( fn, RageFile::READ ) )
{
LOG->Warn( "GetSHA1: Failed to open file '%s'", fn.c_str() );
return RString();
}
int iHash = register_hash( &sha1_desc );
ASSERT( iHash >= 0 );
unsigned char digest[20];
HashFile( file, digest, iHash );
return RString( (const char *) digest, sizeof(digest) );
}
RString CryptManager::GetPublicKeyFileName()
{
return PUBLIC_KEY_PATH;
@@ -455,12 +472,20 @@ public:
lua_pushstring( L, sha1out );
return 1;
}
static int SHA1File( T* p, lua_State *L )
{
RString sha1fout;
sha1fout = p->GetSHA1ForFile(SArg(1));
lua_pushstring( L, sha1fout );
return 1;
}
LunaCryptManager()
{
ADD_METHOD( MD5String );
ADD_METHOD( MD5File );
ADD_METHOD( SHA1String );
ADD_METHOD( SHA1File );
}
};
+1
View File
@@ -27,6 +27,7 @@ public:
static RString GetMD5ForFile( RString fn ); // in binary
static RString GetMD5ForString( RString sData ); // in binary
static RString GetSHA1ForString( RString sData ); // in binary
static RString GetSHA1ForFile( RString fn ); // in binary
static RString GetPublicKeyFileName();