summaryrefslogtreecommitdiff
path: root/src/misc.cpp
diff options
context:
space:
mode:
authorNaram Qashat <cyberbotx@cyberbotx.com>2010-08-08 21:53:32 -0400
committerNaram Qashat <cyberbotx@cyberbotx.com>2010-08-08 21:53:32 -0400
commitbbff5ae4d3961d5c2bff61e7d989c4a69c17ffc7 (patch)
tree5c0eeb19ef090c61aac3e0dea98a71d8a78166c1 /src/misc.cpp
parentde7643a14faf01d84aac8f078608dde13be831b6 (diff)
Add a db-upgrade to convert base64-encoded encrypted passwords to hexadecimal strings of the raw data, add in Anope::Hex for C-style strings and added Anope::Unhex, modified the encryption modules to use Hex and Unhex.
Diffstat (limited to 'src/misc.cpp')
-rw-r--r--src/misc.cpp45
1 files changed, 44 insertions, 1 deletions
diff --git a/src/misc.cpp b/src/misc.cpp
index 048949d0c..b3c298dcd 100644
--- a/src/misc.cpp
+++ b/src/misc.cpp
@@ -1319,7 +1319,6 @@ bool str_is_cidr(const Anope::string &str, uint32 &ip, uint32 &mask, Anope::stri
* @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";
@@ -1335,3 +1334,47 @@ Anope::string Anope::Hex(const Anope::string &data)
return rv;
}
+Anope::string Anope::Hex(const char *data, unsigned len)
+{
+ const char hextable[] = "0123456789abcdef";
+
+ Anope::string rv;
+ for (size_t i = 0; i < len; ++i)
+ {
+ unsigned char c = data[i];
+ rv += hextable[c >> 4];
+ rv += hextable[c & 0xF];
+ }
+ return rv;
+}
+
+/** Converts a string from hex
+ * @param src The data to be converted
+ * @param dest The destination string
+ */
+void Anope::Unhex(const Anope::string &src, Anope::string &dest)
+{
+ size_t len = src.length();
+ Anope::string rv;
+ for (size_t i = 0; i < len; i += 2)
+ {
+ char h = src[i], l = src[i + 1];
+ unsigned char byte = (h >= 'a' ? h - 'a' + 10 : h - '0') << 4;
+ byte += (l >= 'a' ? l - 'a' + 10 : l - '0');
+ rv += byte;
+ }
+ dest = rv;
+}
+
+void Anope::Unhex(const Anope::string &src, char *dest)
+{
+ size_t len = src.length(), destpos = 0;
+ for (size_t i = 0; i < len; i += 2)
+ {
+ char h = src[i], l = src[i + 1];
+ unsigned char byte = (h >= 'a' ? h - 'a' + 10 : h - '0') << 4;
+ byte += (l >= 'a' ? l - 'a' + 10 : l - '0');
+ dest[destpos++] = byte;
+ }
+ dest[destpos] = 0;
+}