diff options
-rw-r--r-- | include/hashcomp.h | 7 | ||||
-rw-r--r-- | include/inspstring.h | 18 | ||||
-rw-r--r-- | src/hashcomp.cpp | 21 | ||||
-rw-r--r-- | src/inspstring.cpp | 10 | ||||
-rw-r--r-- | src/modules/extra/m_ssl_gnutls.cpp | 2 | ||||
-rw-r--r-- | src/modules/extra/m_ssl_openssl.cpp | 2 |
6 files changed, 23 insertions, 37 deletions
diff --git a/include/hashcomp.h b/include/hashcomp.h index c1e8a0ec5..94c222e14 100644 --- a/include/hashcomp.h +++ b/include/hashcomp.h @@ -159,13 +159,6 @@ namespace irc static CoreExport const char* find(const char* s1, int n, char c); }; - /** Compose a hex string from raw data. - * @param raw The raw data to compose hex from - * @param rawsz The size of the raw data buffer - * @return The hex string. - */ - CoreExport std::string hex(const unsigned char *raw, size_t rawsz); - /** This typedef declares irc::string based upon irc_char_traits. */ typedef std::basic_string<char, irc_char_traits, std::allocator<char> > string; diff --git a/include/inspstring.h b/include/inspstring.h index 6864245b0..eb7b7218f 100644 --- a/include/inspstring.h +++ b/include/inspstring.h @@ -24,9 +24,23 @@ #include "config.h" #include <cstring> -/** Binary to hexadecimal conversion */ -CoreExport std::string BinToHex(const std::string& data); +/** Compose a hex string from raw data. + * @param raw The raw data to compose hex from (can be NULL if rawsize is 0) + * @param rawsize The size of the raw data buffer + * @return The hex string + */ +CoreExport std::string BinToHex(const void* raw, size_t rawsize); + /** Base64 encode */ CoreExport std::string BinToBase64(const std::string& data, const char* table = NULL, char pad = 0); /** Base64 decode */ CoreExport std::string Base64ToBin(const std::string& data, const char* table = NULL); + +/** Compose a hex string from the data in a std::string. + * @param data The data to compose hex from + * @return The hex string. + */ +inline std::string BinToHex(const std::string& data) +{ + return BinToHex(data.data(), data.size()); +} diff --git a/src/hashcomp.cpp b/src/hashcomp.cpp index 4ddf942ea..a2f99b70c 100644 --- a/src/hashcomp.cpp +++ b/src/hashcomp.cpp @@ -365,27 +365,6 @@ irc::sepstream::~sepstream() { } -std::string irc::hex(const unsigned char *raw, size_t rawsz) -{ - if (!rawsz) - return ""; - - /* EWW! This used to be using sprintf, which is WAY inefficient. -Special */ - - const char *hex = "0123456789abcdef"; - static char hexbuf[MAXBUF]; - - size_t i, j; - for (i = 0, j = 0; j < rawsz; ++j) - { - hexbuf[i++] = hex[raw[j] / 16]; - hexbuf[i++] = hex[raw[j] % 16]; - } - hexbuf[i] = 0; - - return hexbuf; -} - irc::modestacker::modestacker(bool add) : adding(add) { sequence.clear(); diff --git a/src/inspstring.cpp b/src/inspstring.cpp index 72d6c64c8..7fa4762c5 100644 --- a/src/inspstring.cpp +++ b/src/inspstring.cpp @@ -23,16 +23,16 @@ static const char hextable[] = "0123456789abcdef"; -std::string BinToHex(const std::string& data) +std::string BinToHex(const void* raw, size_t l) { - int l = data.length(); + const char* data = static_cast<const char*>(raw); std::string rv; rv.reserve(l * 2); - for(int i=0; i < l; i++) + for (size_t i = 0; i < l; i++) { unsigned char c = data[i]; - rv.append(1, hextable[c >> 4]); - rv.append(1, hextable[c & 0xF]); + rv.push_back(hextable[c >> 4]); + rv.push_back(hextable[c & 0xF]); } return rv; } diff --git a/src/modules/extra/m_ssl_gnutls.cpp b/src/modules/extra/m_ssl_gnutls.cpp index f85b886e1..2ae16c619 100644 --- a/src/modules/extra/m_ssl_gnutls.cpp +++ b/src/modules/extra/m_ssl_gnutls.cpp @@ -846,7 +846,7 @@ class ModuleSSLGnuTLS : public Module } else { - certinfo->fingerprint = irc::hex(digest, digest_size); + certinfo->fingerprint = BinToHex(digest, digest_size); } /* Beware here we do not check for errors. diff --git a/src/modules/extra/m_ssl_openssl.cpp b/src/modules/extra/m_ssl_openssl.cpp index b8f588b06..23e770c8b 100644 --- a/src/modules/extra/m_ssl_openssl.cpp +++ b/src/modules/extra/m_ssl_openssl.cpp @@ -635,7 +635,7 @@ class ModuleSSLOpenSSL : public Module } else { - certinfo->fingerprint = irc::hex(md, n); + certinfo->fingerprint = BinToHex(md, n); } if ((ASN1_UTCTIME_cmp_time_t(X509_get_notAfter(cert), ServerInstance->Time()) == -1) || (ASN1_UTCTIME_cmp_time_t(X509_get_notBefore(cert), ServerInstance->Time()) == 0)) |