hi:

I use apr 1.2.8.
The function 'apr_base64_encode' may be has a bug?

This function return the length of the encoded string,but i find the return
is not correct.
Please read my code.

Thanks.
/*-------------------------------------------------------------------------*/
#include "global.h"
#include "test_apr_base64.h"
/*-------------------------------------------------------------------------*/
const char * test_apr_base64(void)
{
        static const char msg[] = "test_apr_base64.apr_base64_encode failed.";
        static const char msg2[] = "test_apr_base64.apr_base64_decode failed.";

        unsigned char plain[]    = 
"·þÁËÀ©´óÈý½Ç·ãÈ÷µÄ»ú°¢·É»úÈ÷µÄ¾­·ÑÀ­roweuroew1Á¢¿ÌÈö½¿¸¥À¼¿ËÈ÷µÄ£»È÷µÄ·¢¾ßfjfsdafjsadfjdslajfflsdajfljfa¸½¼ÓÈü¶¾À±¾ü·þÁË£»sadjf";
        unsigned char cipher[]   = 
"t/7By8CptPPI/b3Ht+PI97XEu/qworfJu/rI97XEvq230cCtcm93ZXVyb2V3McGiv8zI9r2/uKXAvL/LyPe1xKO7yPe1xLeivt9mamZzZGFmanNhZGZqZHNsYWpmZmxzZGFqZmxqZmG4vbzTyPy2vsCxvvy3/sHLo7tzYWRqZg==";

        unsigned char *ret = NULL;
        char buffer[PATH_MAX];
        int i = 0, in_len = 0, out_len = 0, ret_len = 0;
        time_t tv_sec, tv_sec2;

/*-------------------------------------------------------------------------*/
        /* part 1
         * performance test
         */
        in_len = (int)strlen(plain);
        out_len = (int)strlen(cipher);

        memset(&tv_sec, 0, sizeof(time_t));
        memset(&tv_sec2, 0, sizeof(time_t));
        tv_sec = time(NULL);

        for (i = 0; i < 500000; i++) {
                memset(buffer, 0, sizeof(buffer));
                ret_len = apr_base64_encode(buffer, plain, in_len);
                
                /* may be a bug, ret_len is not correct */
                /*if (ret_len != out_len) {
                        return msg;
                }*/

                if (memcmp(buffer, cipher, out_len) != 0) {
                        return msg;
                }
        
                memset(buffer, 0, sizeof(buffer));
                ret_len = apr_base64_decode(buffer, cipher);
                if (ret_len != in_len) {
                        return msg2;
                }
                if (memcmp(buffer, plain, in_len) != 0) {
                        return msg2;
                }
        }

        tv_sec2 = time(NULL);
        printf("performance test elapse time = %d\n", (int)(tv_sec2 - tv_sec));

        return NULL;
}
/*-------------------------------------------------------------------------*/
/*-------------------------------------------------------------------------*/
#ifndef _TEST_APR_BASE64_H
#define _TEST_APR_BASE64_H
/*-------------------------------------------------------------------------*/
/*#include "xxx.h"*/
/*-------------------------------------------------------------------------*/
#ifdef __cplusplus
extern "C"{
#endif
/*-------------------------------------------------------------------------*/

const char * test_apr_base64(void);
/*-------------------------------------------------------------------------*/
#ifdef __cplusplus
}
#endif
/*-------------------------------------------------------------------------*/
#endif /* _TEST_APR_BASE64_H */
/*-------------------------------------------------------------------------*/

Reply via email to