[Ace-users] [ace-bugs] Bug in ACE_Base64
Krishnakumar B
kitty at dre.vanderbilt.edu
Fri Dec 14 22:16:47 CST 2007
Hi Folks,
On Thu, 13 Dec 2007 10:30:51 PM -0600, J.T. Conklin wrote:
> alick_nie <alick_nie at 163.com> writes:
>> I have encounter a problem when using ACE_Base64 encode method.
>>
>> For exameple, when "abcdfgi" is encoded under base 64 algorithm, the
>> result should be "YWJjZGZnaQ==". But the result, which ACE_base64
>> returns, add a "\n" to the end of "YWJjZGZnaQ==".
>>
>> How can I get the right result?
>
> Hi,
>
> The ACE_Base64 implementation is "right", just not what you want.
> When it encodes the data, the output is split into 72 column "chunks"
> (RFC 2045 allows up to 76 columns) each terminated by a newline.
Yes, it's true that the ACE encoder doesn't allow you to customize the use
of chunks.
Alick, can you please apply the following patch to see if it helps? I have
not compiled or tested it, but I think it might fix it.
-kitty.
diff -ubBw /Users/kitty/Codecs.cpp.orig /Users/kitty/Codecs.cpp
--- /Users/kitty/Codecs.cpp.orig 2007-12-14 23:05:22.000000000 -0500
+++ /Users/kitty/Codecs.cpp 2007-12-14 23:09:31.000000000 -0500
@@ -97,8 +97,6 @@
result[pos++] = alphabet[(bits >> 6) & 0x3f];
result[pos++] = pad;
}
- if (cols > 0)
- result[pos++] = '\n';
}
result[pos] = 0;
*output_len = pos;
@@ -117,7 +115,6 @@
|| ACE_OS::ace_isspace (*ptr)))
++ptr;
size_t len = ptr - input;
- len = ((len + 3) / 4) * 3 + 1 ;
return len;
}
@@ -130,17 +127,11 @@
if (!input)
return 0;
- size_t result_len = ACE_Base64::length (input);
+ size_t input_len = ACE_Base64::length (input);
+ size_t result_len = ((input_len + 3) / 4) * 3 + 1 ;
ACE_Byte* result = 0;
ACE_NEW_RETURN (result, ACE_Byte[result_len], 0);
- ACE_Byte* ptr = const_cast<ACE_Byte*> (input);
- while (*ptr != 0 &&
- (member_[*(ptr)] == 1 || *ptr == pad
- || ACE_OS::ace_isspace (*ptr)))
- ++ptr;
- size_t input_len = ptr - input;
-
int char_count = 0;
int bits = 0;
size_t pos = 0;
--
Krishnakumar B <kitty at dre dot vanderbilt dot edu>
Institute for Software Integrated Systems, Dept. of EECS, Vanderbilt University
More information about the Ace-users
mailing list