apr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From minf...@apache.org
Subject svn commit: r1490248 - in /apr/apr/trunk: CHANGES encoding/apr_base64.c include/apr_base64.h test/testbase64.c
Date Thu, 06 Jun 2013 12:06:29 GMT
Author: minfrin
Date: Thu Jun  6 12:06:29 2013
New Revision: 1490248

URL: http://svn.apache.org/r1490248
Log:
Add apr_pbase64_encode() and apr_pbase64_decode() to encode to/from
the pool.

Modified:
    apr/apr/trunk/CHANGES
    apr/apr/trunk/encoding/apr_base64.c
    apr/apr/trunk/include/apr_base64.h
    apr/apr/trunk/test/testbase64.c

Modified: apr/apr/trunk/CHANGES
URL: http://svn.apache.org/viewvc/apr/apr/trunk/CHANGES?rev=1490248&r1=1490247&r2=1490248&view=diff
==============================================================================
--- apr/apr/trunk/CHANGES [utf-8] (original)
+++ apr/apr/trunk/CHANGES [utf-8] Thu Jun  6 12:06:29 2013
@@ -1,6 +1,9 @@
                                                      -*- coding: utf-8 -*-
 Changes for APR 2.0.0
 
+  *) Add apr_pbase64_encode() and apr_pbase64_decode() to encode to/from
+     the pool. [Graham Leggett]
+
   *) Add the apr_escape interface. [Graham Leggett]
      
   *) Add support to apr_memcache for unix domain sockets. PR 54573 [Remi

Modified: apr/apr/trunk/encoding/apr_base64.c
URL: http://svn.apache.org/viewvc/apr/apr/trunk/encoding/apr_base64.c?rev=1490248&r1=1490247&r2=1490248&view=diff
==============================================================================
--- apr/apr/trunk/encoding/apr_base64.c (original)
+++ apr/apr/trunk/encoding/apr_base64.c Thu Jun  6 12:06:29 2013
@@ -188,6 +188,18 @@ APR_DECLARE(int) apr_base64_decode_binar
     return nbytesdecoded;
 }
 
+APR_DECLARE(char *) apr_pbase64_decode(apr_pool_t *p, const char *bufcoded)
+{
+    char *decoded;
+    int l;
+
+    decoded = (char *) apr_palloc(p, 1 + apr_base64_decode_len(bufcoded));
+    l = apr_base64_decode(decoded, bufcoded);
+    decoded[l] = '\0'; /* make binary sequence into string */
+
+    return decoded;
+}
+
 static const char basis_64[] =
     "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
 
@@ -267,3 +279,15 @@ APR_DECLARE(int) apr_base64_encode_binar
     *p++ = '\0';
     return (int)(p - encoded);
 }
+
+APR_DECLARE(char *) apr_pbase64_encode(apr_pool_t *p, const char *string)
+{
+    char *encoded;
+    int l = strlen(string);
+
+    encoded = (char *) apr_palloc(p, 1 + apr_base64_encode_len(l));
+    l = apr_base64_encode(encoded, string, l);
+    encoded[l] = '\0'; /* make binary sequence into string */
+
+    return encoded;
+}

Modified: apr/apr/trunk/include/apr_base64.h
URL: http://svn.apache.org/viewvc/apr/apr/trunk/include/apr_base64.h?rev=1490248&r1=1490247&r2=1490248&view=diff
==============================================================================
--- apr/apr/trunk/include/apr_base64.h (original)
+++ apr/apr/trunk/include/apr_base64.h Thu Jun  6 12:06:29 2013
@@ -88,6 +88,15 @@ APR_DECLARE(int) apr_base64_encode_binar
                  __attribute__((nonnull(1,2)));
 
 /**
+ * Encode a string into memory allocated from a pool in base 64 format
+ * @param p The pool to allocate from
+ * @param string The plaintext string
+ * @return The encoded string
+ */
+APR_DECLARE(char *) apr_pbase64_encode(apr_pool_t *p, const char *string)
+        __attribute__((nonnull(1,2)));
+
+/**
  * Determine the maximum buffer length required to decode the plain text
  * string given the encoded string.
  * @param coded_src The encoded string
@@ -120,6 +129,15 @@ APR_DECLARE(int) apr_base64_decode_binar
                                           const char *coded_src)
                  __attribute__((nonnull(1,2)));
 
+/**
+ * Decode a base64 encoded string into memory allocated from a pool
+ * @param p The pool to allocate from
+ * @param bufcoded The encoded string
+ * @return The decoded string
+ */
+APR_DECLARE(char *) apr_pbase64_decode(apr_pool_t *p, const char *bufcoded)
+        __attribute__((nonnull(1,2)));
+
 /** @} */
 #ifdef __cplusplus
 }

Modified: apr/apr/trunk/test/testbase64.c
URL: http://svn.apache.org/viewvc/apr/apr/trunk/test/testbase64.c?rev=1490248&r1=1490247&r2=1490248&view=diff
==============================================================================
--- apr/apr/trunk/test/testbase64.c (original)
+++ apr/apr/trunk/test/testbase64.c Thu Jun  6 12:06:29 2013
@@ -66,6 +66,10 @@ static void test_base64(abts_case *tc, v
         ABTS_ASSERT(tc, "base 64 encoded length", (b64_enc_len == b64_len));
         ABTS_ASSERT(tc, "base 64 encoded matches expected output",
                     (memcmp(enc, base64_tbl[i].enc, b64_enc_len) == 0));
+
+        enc = apr_pbase64_encode(pool, base64_tbl[i].orig);
+        ABTS_ASSERT(tc, "base 64 encoded from pool matches expected output",
+                (strcmp(enc, base64_tbl[i].enc) == 0))
     }
 }
 



Mime
View raw message