Go to the source code of this file.
Functions | |
char * | b64enc (const unsigned char *data, int len) |
int | b64enc_buf (const unsigned char *data, int len, char *dest) |
char * | b64dec (const unsigned char *data, int len) |
int | b64dec_buf (const unsigned char *data, int len, char *dest) |
const char * | b64enc_int (int i) |
Calculate the base64 value of an int. | |
char * | b64enc_int_buf (int i, char *dest) |
int | b64dec_int (const char *b) |
Decodes a base64 string into an int. |
char* b64dec | ( | const unsigned char * | data, | |
int | len | |||
) |
Definition at line 69 of file base64.c.
References b64dec_buf().
00070 { 00071 char *dest; 00072 00073 dest = malloc(len+1); 00074 b64dec_buf(data, len, dest); 00075 return(dest); 00076 }
int b64dec_buf | ( | const unsigned char * | data, | |
int | len, | |||
char * | dest | |||
) |
Definition at line 78 of file base64.c.
Referenced by b64dec().
00079 { 00080 unsigned char c; 00081 int cur = 0, val = 0, i = 0; 00082 00083 while (len) { 00084 c = *data; 00085 len--; 00086 data++; 00087 00088 if (c >= 'A' && c <= 'Z') val = c - 'A'; 00089 else if (c >= 'a' && c <= 'z') val = c - 'a' + 26; 00090 else if (c >= '0' && c <= '9') val = c - '0' + 52; 00091 else if (c == '+') val = 62; 00092 else if (c == '/') val = 63; 00093 else if (c == '=') break; 00094 else continue; 00095 00096 switch (cur++) { 00097 case 0: 00098 dest[i] = (val << 2) & 0xfc; 00099 break; 00100 case 1: 00101 dest[i] |= (val >> 4) & 0x03; 00102 i++; 00103 dest[i] = (val << 4) & 0xf0; 00104 break; 00105 case 2: 00106 dest[i] |= (val >> 2) & 0x0f; 00107 i++; 00108 dest[i] = (val << 6) & 0xc0; 00109 break; 00110 case 3: 00111 dest[i] |= val & 0x3f; 00112 i++; 00113 cur = 0; 00114 break; 00115 } 00116 } 00117 dest[i] = 0; 00118 return(i); 00119 }
int b64dec_int | ( | const char * | b | ) |
Decodes a base64 string into an int.
b | A base64 string. |
Definition at line 156 of file base64.c.
References base64to.
Referenced by get_entity(), got_actchan(), got_away(), got_chat(), got_join(), got_login(), got_newbot(), got_nickchange(), got_nlinked(), got_part(), recving_login(), and sending_login().
00157 { 00158 int i = 0; 00159 00160 while (*b) i = (i << 6) + base64to[(unsigned char) *b++]; 00161 return i; 00162 }
char* b64enc | ( | const unsigned char * | data, | |
int | len | |||
) |
Definition at line 29 of file base64.c.
References b64enc_buf().
00030 { 00031 char *dest; 00032 00033 dest = malloc(4 * len / 3 + 4); 00034 b64enc_buf(data, len, dest); 00035 return(dest); 00036 }
int b64enc_buf | ( | const unsigned char * | data, | |
int | len, | |||
char * | dest | |||
) |
Definition at line 38 of file base64.c.
References b64chars.
Referenced by b64enc(), and make_password().
00039 { 00040 char *buf = dest; 00041 00042 /* Encode 3 bytes at a time. */ 00043 while (len >= 3) { 00044 buf[0] = b64chars[(data[0] >> 2) & 0x3f]; 00045 buf[1] = b64chars[((data[0] << 4) & 0x30) | ((data[1] >> 4) & 0xf)]; 00046 buf[2] = b64chars[((data[1] << 2) & 0x3c) | ((data[2] >> 6) & 0x3)]; 00047 buf[3] = b64chars[data[2] & 0x3f]; 00048 data += 3; 00049 buf += 4; 00050 len -= 3; 00051 } 00052 00053 if (len > 0) { 00054 buf[0] = b64chars[(data[0] >> 2) & 0x3f]; 00055 buf[1] = b64chars[(data[0] << 4) & 0x30]; 00056 if (len > 1) { 00057 buf[1] += (data[1] >> 4) & 0xf; 00058 buf[2] = b64chars[(data[1] << 2) & 0x3c]; 00059 } 00060 else buf[2] = '='; 00061 buf[3] = '='; 00062 buf += 4; 00063 } 00064 00065 *buf = '\0'; 00066 return(buf - dest); 00067 }
const char* b64enc_int | ( | int | i | ) |
Calculate the base64 value of an int.
i | The number to convert. |
Definition at line 177 of file base64.c.
References tobase64.
Referenced by on_chanmsg(), on_extension(), on_join(), on_login(), on_new_bot(), on_nick(), on_part(), on_quit(), partymember_new(), recving_login(), and sending_login().
00178 { 00179 char *pos; 00180 static char ret[12]; 00181 00182 pos = ret + 11; 00183 *pos = 0; 00184 00185 do { 00186 --pos; 00187 *pos = tobase64[i & 0x3F]; 00188 i >>= 6; 00189 } while (i); 00190 00191 return pos; 00192 }
char* b64enc_int_buf | ( | int | i, | |
char * | dest | |||
) |