lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Shmuel Zeigerman wrote:
Lua 5.0 compatibility is back :)

The old patch was attached in the previous message.
This attachment is right. Sorry for the noise. :(

--
Shmuel
--- md5lib.c	Tue May 08 19:06:34 2007
+++ md5lib_new.c	Wed May 09 16:21:22 2007
@@ -18,6 +18,7 @@
 #endif
 
 #include "md5.h"
+static const char hexchars[] = "0123456789abcdef";
 
 
 /**
@@ -171,6 +172,24 @@
 }
 
 
+/**
+*  @param message: arbitrary binary string.
+*  @return String with the md5 hash value converted to hexadecimal digits
+*/
+static int sumhexa (lua_State *L) {
+  char buff[16], buff2[32];
+  size_t l;
+  const char *message = luaL_checklstring(L, 1, &l);
+  md5(message, l, buff);
+  for(l=0; l<16; ++l) {
+    buff2[l+l] = hexchars[(unsigned char)buff[l] >> 4];
+    buff2[l+l+1] = hexchars[buff[l] & 0xf];
+  }
+  lua_pushlstring(L, buff2, 32L);
+  return 1;
+}
+
+
 /*
 ** Assumes the table is on top of the stack.
 */
@@ -192,11 +211,12 @@
   {"exor", ex_or},
   {"crypt", crypt},
   {"decrypt", decrypt},
+  {"sumhexa", sumhexa},
   {NULL, NULL}
 };
 
 
-int luaopen_md5_core (lua_State *L) {
+int luaopen_md5 (lua_State *L) {
   luaL_openlib(L, "md5", md5lib, 0);
   set_info (L);
   return 1;