X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=libraries%2Fliblutil%2Fbase64.c;h=e59dc8d9ee0b1cb5fabce5bdd948170ead7c72d4;hb=198879bd5f1baa09e5dc7a951db980a932cd5db5;hp=6f4b88fe8d985c779261c44955c727b690d9c5c7;hpb=dd51f860420a21b9d813600709d82a3d86e56e9b;p=openldap
diff --git a/libraries/liblutil/base64.c b/libraries/liblutil/base64.c
index 6f4b88fe8d..e59dc8d9ee 100644
--- a/libraries/liblutil/base64.c
+++ b/libraries/liblutil/base64.c
@@ -1,9 +1,21 @@
-/*
- * Modified by Kurt D. Zeilenga for inclusion into OpenLDAP
+/* base64.c -- routines to encode/decode base64 data */
+/* $OpenLDAP$ */
+/* This work is part of OpenLDAP Software .
+ *
+ * Copyright 1998-2009 The OpenLDAP Foundation.
+ * Portions Copyright 1998-2003 Kurt D. Zeilenga.
+ * Portions Copyright 1995 IBM Corporation.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted only as authorized by the OpenLDAP
+ * Public License.
+ *
+ * A copy of this license is available in the file LICENSE in the
+ * top-level directory of the distribution or, alternatively, at
+ * .
*/
-
-/*
- * Copyright (c) 1996, 1998 by Internet Software Consortium.
+/* Portions Copyright (c) 1996, 1998 by Internet Software Consortium.
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
@@ -18,37 +30,16 @@
* ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
* SOFTWARE.
*/
-
-/*
- * Portions Copyright (c) 1995 by International Business Machines, Inc.
- *
- * International Business Machines, Inc. (hereinafter called IBM) grants
- * permission under its copyrights to use, copy, modify, and distribute this
- * Software with or without fee, provided that the above copyright notice and
- * all paragraphs of this notice appear in all copies, and that the name of IBM
- * not be used in connection with the marketing of any product incorporating
- * the Software or modifications thereof, without specific, written prior
- * permission.
- *
- * To the extent it has a right to do so, IBM grants an immunity from suit
- * under its patents, if any, for the use, sale or manufacture of products to
- * the extent that such products are used for performing Domain Name System
- * dynamic updates in TCP/IP networks by means of the Software. No immunity is
- * granted for any product per se or for any other function of any product.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", AND IBM DISCLAIMS ALL WARRANTIES,
- * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
- * PARTICULAR PURPOSE. IN NO EVENT SHALL IBM BE LIABLE FOR ANY SPECIAL,
- * DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER ARISING
- * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE, EVEN
- * IF IBM IS APPRISED OF THE POSSIBILITY OF SUCH DAMAGES.
+/* This work is based upon Base64 routines (developed by IBM) found
+ * Berkeley Internet Name Daemon (BIND) as distributed by ISC. They
+ * were adapted for inclusion in OpenLDAP Software by Kurt D. Zeilenga.
*/
#include "portable.h"
-#include
-#include
-
+#include
+#include
+#include
#include
/* include socket.h to get sys/types.h and/or winsock2.h */
@@ -56,8 +47,6 @@
#include "lutil.h"
-#define Assert(Cond) if (!(Cond)) abort()
-
static const char Base64[] =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
static const char Pad64 = '=';
@@ -126,7 +115,7 @@ static const char Pad64 = '=';
*/
int
-b64_ntop(
+lutil_b64_ntop(
u_char const *src,
size_t srclength,
char *target,
@@ -147,10 +136,10 @@ b64_ntop(
output[1] = ((input[0] & 0x03) << 4) + (input[1] >> 4);
output[2] = ((input[1] & 0x0f) << 2) + (input[2] >> 6);
output[3] = input[2] & 0x3f;
- Assert(output[0] < 64);
- Assert(output[1] < 64);
- Assert(output[2] < 64);
- Assert(output[3] < 64);
+ assert(output[0] < 64);
+ assert(output[1] < 64);
+ assert(output[2] < 64);
+ assert(output[3] < 64);
if (datalength + 4 > targsize)
return (-1);
@@ -170,9 +159,9 @@ b64_ntop(
output[0] = input[0] >> 2;
output[1] = ((input[0] & 0x03) << 4) + (input[1] >> 4);
output[2] = ((input[1] & 0x0f) << 2) + (input[2] >> 6);
- Assert(output[0] < 64);
- Assert(output[1] < 64);
- Assert(output[2] < 64);
+ assert(output[0] < 64);
+ assert(output[1] < 64);
+ assert(output[2] < 64);
if (datalength + 4 > targsize)
return (-1);
@@ -197,7 +186,7 @@ b64_ntop(
*/
int
-b64_pton(
+lutil_b64_pton(
char const *src,
u_char *target,
size_t targsize)
@@ -209,7 +198,7 @@ b64_pton(
tarindex = 0;
while ((ch = *src++) != '\0') {
- if (isspace(ch)) /* Skip whitespace anywhere. */
+ if (isascii(ch) && isspace(ch)) /* Skip whitespace anywhere. */
continue;
if (ch == Pad64)
@@ -279,7 +268,7 @@ b64_pton(
case 2: /* Valid, means one byte of info */
/* Skip any number of spaces. */
for ((void)NULL; ch != '\0'; ch = *src++)
- if (!isspace(ch))
+ if (! (isascii(ch) && isspace(ch)))
break;
/* Make sure there is another trailing = sign. */
if (ch != Pad64)
@@ -294,7 +283,7 @@ b64_pton(
* whitespace after it?
*/
for ((void)NULL; ch != '\0'; ch = *src++)
- if (!isspace(ch))
+ if (! (isascii(ch) && isspace(ch)))
return (-1);
/*