diff options
author | pixel <pixel> | 2007-09-28 09:23:36 +0000 |
---|---|---|
committer | pixel <pixel> | 2007-09-28 09:23:36 +0000 |
commit | 926d091d36bead33fcd18c1b2d1552a047070a25 (patch) | |
tree | aee0084dda2e76c7f36ee3d993dff183dab869cd /lib/LuaHttp.cc | |
parent | 6e53dbca553d1d4567d29c70ae767a43be3ad3d9 (diff) |
Having HashFunction used in the various Http classes
Diffstat (limited to 'lib/LuaHttp.cc')
-rw-r--r-- | lib/LuaHttp.cc | 46 |
1 files changed, 32 insertions, 14 deletions
diff --git a/lib/LuaHttp.cc b/lib/LuaHttp.cc index 4dea10e..3324dff 100644 --- a/lib/LuaHttp.cc +++ b/lib/LuaHttp.cc @@ -17,14 +17,14 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -/* $Id: LuaHttp.cc,v 1.21 2007-07-27 10:05:52 pixel Exp $ */ +/* $Id: LuaHttp.cc,v 1.22 2007-09-28 09:23:36 pixel Exp $ */ -#include "md5.h" #include "Domain.h" #include "LuaHttp.h" #include "LuaHandle.h" #include "LuaTask.h" #include "Base64.h" +#include "HashFunction.h" class LuaDomain : public Domain { public: @@ -121,6 +121,8 @@ enum HttpResponse_functions_t { HTTPRESPONSE_BASE64_ENCODE, HTTPRESPONSE_BASE64_DECODE, HTTPRESPONSE_MD5, + HTTPRESPONSE_SHA1, + HTTPRESPONSE_SHA256, }; struct lua_functypes_t HttpResponse_methods[] = { @@ -134,6 +136,8 @@ struct lua_functypes_t HttpResponse_functions[] = { { HTTPRESPONSE_BASE64_ENCODE, "Base64Encode", 1, 1, { BLUA_STRING } }, { HTTPRESPONSE_BASE64_DECODE, "Base64Decode", 1, 1, { BLUA_STRING } }, { HTTPRESPONSE_MD5, "MD5", 1, 1, { BLUA_STRING } }, + { HTTPRESPONSE_SHA1, "SHA1", 1, 1, { BLUA_STRING } }, + { HTTPRESPONSE_SHA256, "SHA256", 1, 1, { BLUA_STRING } }, { -1, 0, 0, 0, 0 } }; @@ -146,6 +150,8 @@ class sLua_HttpResponse : public Base { DECLARE_FUNCTION(HttpResponse, HTTPRESPONSE_BASE64_ENCODE); DECLARE_FUNCTION(HttpResponse, HTTPRESPONSE_BASE64_DECODE); DECLARE_FUNCTION(HttpResponse, HTTPRESPONSE_MD5); + DECLARE_FUNCTION(HttpResponse, HTTPRESPONSE_SHA1); + DECLARE_FUNCTION(HttpResponse, HTTPRESPONSE_SHA256); private: static int HttpResponse_proceed(Lua * L, int n, HttpResponse * obj, int caller); static int HttpResponse_proceed_statics(Lua * L, int n, int caller); @@ -166,6 +172,8 @@ void LuaHttpResponse::pushstatics(Lua * L) throw (GeneralException) { PUSH_FUNCTION(HttpResponse, HTTPRESPONSE_BASE64_ENCODE); PUSH_FUNCTION(HttpResponse, HTTPRESPONSE_BASE64_DECODE); PUSH_FUNCTION(HttpResponse, HTTPRESPONSE_MD5); + PUSH_FUNCTION(HttpResponse, HTTPRESPONSE_SHA1); + PUSH_FUNCTION(HttpResponse, HTTPRESPONSE_SHA256); export_enum(L, HTTP_200_OK); export_enum(L, HTTP_301_PERM_MOVED); @@ -243,10 +251,6 @@ int sLua_HttpResponse::HttpResponse_proceed_statics(Lua * L, int n, int caller) String enc, dec; char * enc_t; const char * dec_t; - md5_context ctx; - unsigned char md5sum[16]; - String md5sum_r; - static const char hconv[] = "0123456789ABCDEF"; switch (caller) { case HTTPRESPONSE_NEWHTTPRESPONSE: @@ -273,15 +277,29 @@ int sLua_HttpResponse::HttpResponse_proceed_statics(Lua * L, int n, int caller) case HTTPRESPONSE_MD5: dec = L->tostring(); - dec_t = dec.to_charp(); - md5_starts(&ctx); - md5_update(&ctx, (uint8 *) dec_t, dec.strlen()); - md5_finish(&ctx, md5sum); - for (i = 0; i < 16; i++) { - md5sum_r = md5sum_r + hconv[md5sum[i] >> 4]; - md5sum_r = md5sum_r + hconv[md5sum[i] % 16]; + { + MD5 h; + h.Update(dec); + L->push(h.Finish()); + } + r = 1; + break; + case HTTPRESPONSE_SHA1: + dec = L->tostring(); + { + SHA1 h; + h.Update(dec); + L->push(h.Finish()); + } + r = 1; + break; + case HTTPRESPONSE_SHA256: + dec = L->tostring(); + { + SHA256 h; + h.Update(dec); + L->push(h.Finish()); } - L->push(md5sum_r); r = 1; break; } |