From b798359b1709af5c53b56e89d9c8453fd6844e25 Mon Sep 17 00:00:00 2001 From: Valery Yatsko Date: Sun, 20 Apr 2008 08:36:28 +0400 Subject: [PATCH] Functions replacement: ircd_baseXX_{en,de}code -> rb_baseXX_{en,de}code --- include/irc_string.h | 3 -- modules/m_challenge.c | 2 +- src/irc_string.c | 96 ------------------------------------------- 3 files changed, 1 insertion(+), 100 deletions(-) diff --git a/include/irc_string.h b/include/irc_string.h index ba1d0a5..8f348b6 100644 --- a/include/irc_string.h +++ b/include/irc_string.h @@ -124,9 +124,6 @@ const char *myctime(time_t); char *strtoken(char **save, char *str, const char *fs); -unsigned char *ircd_base64_encode(const unsigned char *str, int length); -unsigned char *ircd_base64_decode(const unsigned char *str, int length, int *ret); - /* * character macros */ diff --git a/modules/m_challenge.c b/modules/m_challenge.c index 6b5c6e1..f275324 100644 --- a/modules/m_challenge.c +++ b/modules/m_challenge.c @@ -144,7 +144,7 @@ m_challenge(struct Client *client_p, struct Client *source_p, int parc, const ch return 0; } - b_response = ircd_base64_decode((const unsigned char *)++parv[1], strlen(parv[1]), &len); + b_response = rb_base64_decode((const unsigned char *)++parv[1], strlen(parv[1]), &len); if(len != SHA_DIGEST_LENGTH || memcmp(source_p->localClient->challenge, b_response, SHA_DIGEST_LENGTH)) diff --git a/src/irc_string.c b/src/irc_string.c index 5951dd6..62cdc7e 100644 --- a/src/irc_string.c +++ b/src/irc_string.c @@ -207,102 +207,6 @@ static const short base64_reverse_table[256] = { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }; -unsigned char * -ircd_base64_encode(const unsigned char *str, int length) -{ - const unsigned char *current = str; - unsigned char *p; - unsigned char *result; - - if ((length + 2) < 0 || ((length + 2) / 3) >= (1 << (sizeof(int) * 8 - 2))) { - return NULL; - } - - result = rb_malloc(((length + 2) / 3) * 5); - p = result; - - while (length > 2) - { - *p++ = base64_table[current[0] >> 2]; - *p++ = base64_table[((current[0] & 0x03) << 4) + (current[1] >> 4)]; - *p++ = base64_table[((current[1] & 0x0f) << 2) + (current[2] >> 6)]; - *p++ = base64_table[current[2] & 0x3f]; - - current += 3; - length -= 3; - } - - if (length != 0) { - *p++ = base64_table[current[0] >> 2]; - if (length > 1) { - *p++ = base64_table[((current[0] & 0x03) << 4) + (current[1] >> 4)]; - *p++ = base64_table[(current[1] & 0x0f) << 2]; - *p++ = base64_pad; - } else { - *p++ = base64_table[(current[0] & 0x03) << 4]; - *p++ = base64_pad; - *p++ = base64_pad; - } - } - *p = '\0'; - return result; -} - -unsigned char * -ircd_base64_decode(const unsigned char *str, int length, int *ret) -{ - const unsigned char *current = str; - int ch, i = 0, j = 0, k; - unsigned char *result; - - result = rb_malloc(length + 1); - - while ((ch = *current++) != '\0' && length-- > 0) { - if (ch == base64_pad) break; - - ch = base64_reverse_table[ch]; - if (ch < 0) continue; - - switch(i % 4) { - case 0: - result[j] = ch << 2; - break; - case 1: - result[j++] |= ch >> 4; - result[j] = (ch & 0x0f) << 4; - break; - case 2: - result[j++] |= ch >>2; - result[j] = (ch & 0x03) << 6; - break; - case 3: - result[j++] |= ch; - break; - } - i++; - } - - k = j; - - if (ch == base64_pad) { - switch(i % 4) { - case 1: - free(result); - return NULL; - case 2: - k++; - case 3: - result[k++] = 0; - } - } - result[j] = '\0'; - - if(ret) - *ret = j; - - return result; -} - /* * From: Thomas Helvey */