68 lines
1.4 KiB
C++
68 lines
1.4 KiB
C++
/* -----------------------------------------------------------------------------
|
|
GSFramework
|
|
Copyright 2001-2013 Emmanuel Julien. All Rights Reserved.
|
|
----------------------------------------------------------------------------- */
|
|
|
|
|
|
#include "binding_helpers.h"
|
|
#include "hash/md5.h"
|
|
#include "hash/nsha1.h"
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
SQInteger MD5(HSQUIRRELVM vm)
|
|
{
|
|
__SQ_GETSTART(1)
|
|
__SQ_GETSTRING(source)
|
|
|
|
using namespace GS::MD5;
|
|
|
|
Digest md5;
|
|
|
|
md5_byte_t digest[16];
|
|
md5.Append((const md5_byte_t *)source, GS::String::strlen(source));
|
|
md5.Finish(digest);
|
|
|
|
char md5_string[33];
|
|
DigestToString(digest, md5_string);
|
|
md5_string[32] = 0;
|
|
|
|
__SQ_GETEND
|
|
__SQ_RETURNSTRING(md5_string)
|
|
}
|
|
SQInteger SHA1(HSQUIRRELVM vm)
|
|
{
|
|
__SQ_GETSTART(1)
|
|
__SQ_GETSTRING(source)
|
|
GS::String hash = GS::SHA1::ComputeHexa(source);
|
|
__SQ_GETEND
|
|
__SQ_RETURNSTRING(hash.c_str())
|
|
}
|
|
//------------------------------------------------------------------------------
|
|
|
|
void RegisterHashBinding(HSQUIRRELVM vm)
|
|
{
|
|
using namespace GS::Script;
|
|
|
|
/*#
|
|
Topic: Hash
|
|
#*/
|
|
|
|
/*#
|
|
Section: Hashing
|
|
Desc: Hashing
|
|
#*/
|
|
/*#
|
|
Func: MD5
|
|
Proto: String:String source
|
|
Desc: Compute a MD5 hexadecimal hash.
|
|
#*/
|
|
sq_register(vm, MD5, "MD5", _SC(".s"));
|
|
/*#
|
|
Func: SHA1
|
|
Proto: String:String source
|
|
Desc: Compute a SHA1 hexadecimal hash.
|
|
#*/
|
|
sq_register(vm, SHA1, "SHA1", _SC(".s"));
|
|
}
|