From f4b7ae5da37ea857b346ae5f6fb7def872bf8a1d Mon Sep 17 00:00:00 2001 From: Thomas Geymayer Date: Wed, 18 Jun 2014 15:59:41 +0200 Subject: [PATCH] Nasal: md5 is now in simgear. --- src/Scripting/NasalSys.cxx | 26 ++++++-------------------- 1 file changed, 6 insertions(+), 20 deletions(-) diff --git a/src/Scripting/NasalSys.cxx b/src/Scripting/NasalSys.cxx index 9ac730263..fde6319db 100644 --- a/src/Scripting/NasalSys.cxx +++ b/src/Scripting/NasalSys.cxx @@ -28,7 +28,6 @@ #include #include #include -#include #include #include @@ -719,26 +718,13 @@ static naRef f_parse_markdown(naContext c, naRef me, int argc, naRef* args) */ static naRef f_md5(naContext c, naRef me, int argc, naRef* args) { - nasal::CallContext ctx(c, argc, args); - std::string const str = ctx.requireArg(0); - - SG_MD5_CTX md5_ctx; - SG_MD5Init(&md5_ctx); - SG_MD5Update(&md5_ctx, (unsigned char*)str.c_str(), str.size()); - - unsigned char digest[MD5_DIGEST_LENGTH]; - SG_MD5Final(digest, &md5_ctx); - - // TODO make something more generic - // convert final sum to hex - const char hexChar[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'}; - std::stringstream hexMd5; - for (int i=0; i> 4]; - hexMd5 << hexChar[digest[i] & 0x0f]; - } + if( argc != 1 || !naIsString(args[0]) ) + naRuntimeError(c, "md5(): wrong type or number of arguments"); - return ctx.to_nasal(hexMd5.str()); + return nasal::to_nasal( + c, + simgear::strutils::md5(naStr_data(args[0]), naStr_len(args[0])) + ); } // Return UNIX epoch time in seconds. -- 2.39.5