Commit a650965c authored by Philipp Schafft's avatar Philipp Schafft 🦁

Cleanup: make util_base64_encode() useful for binary data.

parent de48bdd1
......@@ -176,7 +176,7 @@ static client_t *open_relay_connection (relay_server *relay)
auth_header = malloc (len);
snprintf (auth_header, len, "%s:%s", relay->username, relay->password);
esc_authorisation = util_base64_encode(auth_header);
esc_authorisation = util_base64_encode(auth_header, len);
free(auth_header);
len = strlen (esc_authorisation) + 24;
auth_header = malloc (len);
......@@ -637,7 +637,7 @@ static int update_from_master(ice_config_t *config)
len = strlen(username) + strlen(password) + 2;
authheader = malloc(len);
snprintf (authheader, len, "%s:%s", username, password);
data = util_base64_encode(authheader);
data = util_base64_encode(authheader, len);
sock_write (mastersock,
"GET /admin/streamlist.txt HTTP/1.0\r\n"
"Authorization: Basic %s\r\n"
......
......@@ -409,15 +409,13 @@ char *util_bin_to_hex(unsigned char *data, int len)
}
/* This isn't efficient, but it doesn't need to be */
char *util_base64_encode(const char *data)
{
int len = strlen(data);
char *util_base64_encode(const char *data, size_t len) {
char *out = malloc(len*4/3 + 4);
char *result = out;
int chunk;
size_t chunk;
while(len > 0) {
chunk = (len >3)?3:len;
chunk = len > 3 ? 3 : len;
*out++ = base64table[(*data & 0xFC)>>2];
*out++ = base64table[((*data & 0x03)<<4) | ((*(data+1) & 0xF0) >> 4)];
switch(chunk) {
......
......@@ -32,7 +32,7 @@ char *util_get_extension(const char *path);
char *util_get_path_from_uri(char *uri);
char *util_get_path_from_normalised_uri(const char *uri);
char *util_normalise_uri(const char *uri);
char *util_base64_encode(const char *data);
char *util_base64_encode(const char *data, size_t len);
char *util_base64_decode(const char *input);
char *util_bin_to_hex(unsigned char *data, int len);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment