aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorlloyd <[email protected]>2010-10-28 19:44:07 +0000
committerlloyd <[email protected]>2010-10-28 19:44:07 +0000
commite6fc6b5225df382c8d7f8193047e60853c594d19 (patch)
treebf4add6ffa32b04a91738bf9c3712aa36eab0086 /src
parentd1d41321c8d3d6f6273659342e93f02e865ab6bf (diff)
Use standalone encoder for end of message padding too
Diffstat (limited to 'src')
-rw-r--r--src/filters/codec_filt/b64_filt.cpp29
-rw-r--r--src/filters/codec_filt/b64_filt.h7
2 files changed, 9 insertions, 27 deletions
diff --git a/src/filters/codec_filt/b64_filt.cpp b/src/filters/codec_filt/b64_filt.cpp
index 2db6ac3ca..8a90f8b5f 100644
--- a/src/filters/codec_filt/b64_filt.cpp
+++ b/src/filters/codec_filt/b64_filt.cpp
@@ -1,6 +1,6 @@
/*
* Base64 Encoder/Decoder
-* (C) 1999-2008 Jack Lloyd
+* (C) 1999-2010 Jack Lloyd
*
* Distributed under the terms of the Botan license
*/
@@ -55,7 +55,8 @@ Base64_Encoder::Base64_Encoder(bool breaks, size_t length, bool t_n) :
/*
* Encode and send a block
*/
-void Base64_Encoder::encode_and_send(const byte input[], size_t length)
+void Base64_Encoder::encode_and_send(const byte input[], size_t length,
+ bool final_inputs)
{
while(length)
{
@@ -63,7 +64,7 @@ void Base64_Encoder::encode_and_send(const byte input[], size_t length)
size_t consumed = 0;
size_t produced = base64_encode(reinterpret_cast<char*>(&out[0]), input,
- proc, consumed, false);
+ proc, consumed, final_inputs);
do_output(&out[0], produced);
@@ -126,27 +127,7 @@ void Base64_Encoder::write(const byte input[], size_t length)
*/
void Base64_Encoder::end_msg()
{
- size_t start_of_last_block = 3 * (position / 3),
- left_over = position % 3;
- encode_and_send(&in[0], start_of_last_block);
-
- if(left_over)
- {
- SecureVector<byte> remainder(3);
- copy_mem(&remainder[0], &in[start_of_last_block], left_over);
-
- size_t consumed;
- base64_encode(reinterpret_cast<char*>(&out[0]), &remainder[0], 3, consumed, false);
-
- size_t empty_bits = 8 * (3 - left_over), index = 4 - 1;
- while(empty_bits >= 8)
- {
- out[index--] = '=';
- empty_bits -= 6;
- }
-
- do_output(&out[0], 4);
- }
+ encode_and_send(&in[0], position, true);
if(trailing_newline || (out_position && line_length))
send('\n');
diff --git a/src/filters/codec_filt/b64_filt.h b/src/filters/codec_filt/b64_filt.h
index 8918049a2..e7cbfae1d 100644
--- a/src/filters/codec_filt/b64_filt.h
+++ b/src/filters/codec_filt/b64_filt.h
@@ -1,6 +1,6 @@
/*
* Base64 Encoder/Decoder
-* (C) 1999-2007 Jack Lloyd
+* (C) 1999-2010 Jack Lloyd
*
* Distributed under the terms of the Botan license
*/
@@ -41,8 +41,9 @@ class BOTAN_DLL Base64_Encoder : public Filter
Base64_Encoder(bool breaks = false, size_t length = 72,
bool t_n = false);
private:
- void encode_and_send(const byte[], size_t);
- void do_output(const byte[], size_t);
+ void encode_and_send(const byte input[], size_t length,
+ bool final_inputs = false);
+ void do_output(const byte output[], size_t length);
const size_t line_length;
const bool trailing_newline;