diff options
-rw-r--r-- | include/anope.h | 11 | ||||
-rw-r--r-- | modules/core/enc_sha256.cpp | 5 | ||||
-rw-r--r-- | src/misc.cpp | 23 |
3 files changed, 37 insertions, 2 deletions
diff --git a/include/anope.h b/include/anope.h index 4cd8fc2b0..be5c2f964 100644 --- a/include/anope.h +++ b/include/anope.h @@ -153,6 +153,11 @@ namespace Anope inline size_type length() const { return this->_string.length(); } /** + * Resizes the string content to n characters. + */ + inline void resize(size_type n) { return this->_string.resize(n); } + + /** * Erases characters from the string. */ inline iterator erase(const iterator &i) { return this->_string.erase(i); } @@ -311,6 +316,12 @@ namespace Anope * @return a vector with pointers to the messagehandlers (you can bind more than one handler to a message) */ extern CoreExport std::vector<Message *> FindMessage(const string &name); + + /** Converts a string to hex + * @param the data to be converted + * @return a anope::string containing the hex value + */ + extern CoreExport string Hex(const string &data); } /** sepstream allows for splitting token seperated lists. diff --git a/modules/core/enc_sha256.cpp b/modules/core/enc_sha256.cpp index b0369ee21..15dfce120 100644 --- a/modules/core/enc_sha256.cpp +++ b/modules/core/enc_sha256.cpp @@ -138,6 +138,7 @@ class ESHA256 : public Module Anope::string buf2; for (int i = 0; i < 8; ++i) UNPACK32(iv[i], reinterpret_cast<unsigned char *>(&buf[i << 2])); + buf[32] = '\0'; b64_encode(buf, buf2); return buf2; } @@ -262,7 +263,7 @@ class ESHA256 : public Module EventReturn OnEncrypt(const Anope::string &src, Anope::string &dest) { - char digest[SHA256_DIGEST_SIZE]; + char digest[SHA256_DIGEST_SIZE+1]; Anope::string cpass; SHA256Context ctx; std::stringstream buf; @@ -275,7 +276,7 @@ class ESHA256 : public Module SHA256Init(&ctx); SHA256Update(&ctx, reinterpret_cast<const unsigned char *>(src.c_str()), src.length()); SHA256Final(&ctx, reinterpret_cast<unsigned char *>(digest)); - + digest[SHA256_DIGEST_SIZE] = '\0'; b64_encode(digest, cpass); buf << "sha256:" << cpass << ":" << GetIVString(); Alog(LOG_DEBUG_2) << "(enc_sha256) hashed password from [" << src << "] to [" << buf.str() << " ]"; diff --git a/src/misc.cpp b/src/misc.cpp index e24301d44..cac6b8b08 100644 --- a/src/misc.cpp +++ b/src/misc.cpp @@ -1296,3 +1296,26 @@ bool str_is_cidr(const Anope::string &str, uint32 &ip, uint32 &mask, Anope::stri return true; } + +/********************************************************************************/ + +/** Converts a string to hex + * @param the data to be converted + * @return a anope::string containing the hex value + */ + +Anope::string Anope::Hex(const Anope::string &data) +{ + const char hextable[] = "0123456789abcdef"; + + int l = data.length(); + Anope::string rv; + for(int i=0; i < l; i++) + { + unsigned char c = data[i]; + rv += hextable[c >> 4]; + rv += hextable[c & 0xF]; + } + return rv; +} + |