diff --git a/Docs/Changelog_sm5.txt b/Docs/Changelog_sm5.txt index 412b687d40..b213ba6b6b 100644 --- a/Docs/Changelog_sm5.txt +++ b/Docs/Changelog_sm5.txt @@ -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] diff --git a/src/CryptManager.cpp b/src/CryptManager.cpp index 758415e2a9..04f448c570 100644 --- a/src/CryptManager.cpp +++ b/src/CryptManager.cpp @@ -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 ); } }; diff --git a/src/CryptManager.h b/src/CryptManager.h index feda635aed..64fc747ffb 100644 --- a/src/CryptManager.h +++ b/src/CryptManager.h @@ -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();