]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_md5.cpp
Remove spanningtree override of /LUSERS
[user/henk/code/inspircd.git] / src / modules / m_md5.cpp
index 2771ba495468afeab069fb21f9fa99e5e6d893db..6b74dae2ee5f385ed72ddaa6e0ea8145e0d126e5 100644 (file)
@@ -39,7 +39,7 @@ typedef unsigned char byte;
 
 /** An MD5 context, used by m_opermd5
  */
-class MD5Context : public classbase
+class MD5Context
 {
  public:
        word32 buf[4];
@@ -47,7 +47,7 @@ class MD5Context : public classbase
        word32 in[16];
 };
 
-class ModuleMD5 : public Module
+class MD5Provider : public HashProvider
 {
        void byteSwap(word32 *buf, unsigned words)
        {
@@ -258,59 +258,36 @@ class ModuleMD5 : public Module
                }
                *dest++ = 0;
        }
-
-       unsigned int *key;
-       char* chars;
-
  public:
-
-       ModuleMD5(InspIRCd* Me)
-               : Module(Me), key(NULL), chars(NULL)
+       std::string sum(const std::string& data)
        {
-               ServerInstance->Modules->PublishInterface("HashRequest", this);
-               Implementation eventlist[] = { I_OnRequest };
-               ServerInstance->Modules->Attach(eventlist, this, 1);
+               char res[16];
+               MyMD5(res, (void*)data.data(), data.length(), NULL);
+               return std::string(res, 16);
        }
 
-       virtual ~ModuleMD5()
+       std::string sumIV(unsigned int* IV, const char* HexMap, const std::string &sdata)
        {
-               ServerInstance->Modules->UnpublishInterface("HashRequest", this);
+               char res[33];
+               GenHash(sdata.data(), res, HexMap, IV, sdata.length());
+               return res;
        }
 
+       MD5Provider(Module* parent) : HashProvider(parent, "hash/md5") {}
+};
 
-       virtual const char* OnRequest(Request* request)
+class ModuleMD5 : public Module
+{
+       MD5Provider md5;
+ public:
+       ModuleMD5() : md5(this)
        {
-               HashRequest* MD5 = (HashRequest*)request;
-
-               if (strcmp("KEY", request->GetId()) == 0)
-               {
-                       this->key = (unsigned int*)MD5->GetKeyData();
-               }
-               else if (strcmp("HEX", request->GetId()) == 0)
-               {
-                       this->chars = (char*)MD5->GetOutputs();
-               }
-               else if (strcmp("SUM", request->GetId()) == 0)
-               {
-                       static char data[MAXBUF];
-                       GenHash(MD5->GetHashData().data(), data, chars ? chars : "0123456789abcdef", key, MD5->GetHashData().length());
-                       return data;
-               }
-               else if (strcmp("NAME", request->GetId()) == 0)
-               {
-                       return "md5";
-               }
-               else if (strcmp("RESET", request->GetId()) == 0)
-               {
-                       this->chars = NULL;
-                       this->key = NULL;
-               }
-               return NULL;
+               ServerInstance->Modules->AddService(md5);
        }
 
-       virtual Version GetVersion()
+       Version GetVersion()
        {
-               return Version("Allows for MD5 encrypted oper passwords",VF_VENDOR|VF_SERVICEPROVIDER,API_VERSION);
+               return Version("Implements MD5 hashing",VF_VENDOR);
        }
 };