summaryrefslogtreecommitdiff
path: root/src/or/connection.c
diff options
context:
space:
mode:
authorYawning Angel <yawning@schwanenlied.me>2015-04-10 11:25:08 +0000
committerNick Mathewson <nickm@torproject.org>2015-04-23 09:06:58 -0400
commit196499da73afa5c8000154aafe36c10b9ee43901 (patch)
treefb6343334ed05db14dbe3e8a14a2e18ee1534d08 /src/or/connection.c
parentba2485f7df51b2daafaff8567320c34a22731e8e (diff)
downloadtor-196499da73afa5c8000154aafe36c10b9ee43901.tar.gz
tor-196499da73afa5c8000154aafe36c10b9ee43901.zip
Use a custom Base64 encoder with more control over the output format.
Diffstat (limited to 'src/or/connection.c')
-rw-r--r--src/or/connection.c19
1 files changed, 3 insertions, 16 deletions
diff --git a/src/or/connection.c b/src/or/connection.c
index 369df67363..5610815589 100644
--- a/src/or/connection.c
+++ b/src/or/connection.c
@@ -4440,25 +4440,12 @@ alloc_http_authenticator(const char *authenticator)
/* an authenticator in Basic authentication
* is just the string "username:password" */
const size_t authenticator_length = strlen(authenticator);
- /* The base64_encode function needs a minimum buffer length
- * of 66 bytes. */
- const size_t base64_authenticator_length = (authenticator_length/48+1)*66;
+ const size_t base64_authenticator_length =
+ base64_encode_size(authenticator_length, 0) + 1;
char *base64_authenticator = tor_malloc(base64_authenticator_length);
if (base64_encode(base64_authenticator, base64_authenticator_length,
- authenticator, authenticator_length) < 0) {
+ authenticator, authenticator_length, 0) < 0) {
tor_free(base64_authenticator); /* free and set to null */
- } else {
- int i = 0, j = 0;
- ssize_t len = strlen(base64_authenticator);
-
- /* remove all newline occurrences within the string */
- for (i=0; i < len; ++i) {
- if ('\n' != base64_authenticator[i]) {
- base64_authenticator[j] = base64_authenticator[i];
- ++j;
- }
- }
- base64_authenticator[j]='\0';
}
return base64_authenticator;
}