Functions replacement: ircd_baseXX_{en,de}code -> rb_baseXX_{en,de}code
This commit is contained in:
parent
f55930ac2e
commit
6af128685d
3 changed files with 1 additions and 100 deletions
|
@ -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
|
||||
*/
|
||||
|
|
|
@ -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))
|
||||
|
|
|
@ -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 <tomh@inxpress.net>
|
||||
*/
|
||||
|
|
Loading…
Reference in a new issue