From 24d46e151326b1b159603442e74540bf87897a53 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Wed, 29 Jul 2009 23:02:26 +0000 Subject: Base64, now more clever with fewer options. --- src/base64.cpp | 12 ++++++------ src/base64.h | 17 +++++++---------- src/tests/base64.cpp | 4 ++-- 3 files changed, 15 insertions(+), 18 deletions(-) (limited to 'src') diff --git a/src/base64.cpp b/src/base64.cpp index 723788b..b81d028 100644 --- a/src/base64.cpp +++ b/src/base64.cpp @@ -4,13 +4,13 @@ const char Bu::Base64::tblEnc[65] = { "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/" }; -Bu::Base64::Base64( Bu::Stream &rNext, Mode eMode ) : +Bu::Base64::Base64( Bu::Stream &rNext ) : Bu::Filter( rNext ), iBPos( 0 ), iBuf( 0 ), iTotalIn( 0 ), iTotalOut( 0 ), - eMode( eMode ) + eMode( Nothing ) { start(); @@ -54,7 +54,7 @@ void Bu::Base64::start() size_t Bu::Base64::stop() { - if( eMode == Write ) +// if( eMode |= Encode ) { char outBuf[4]; int iBUsed = 4-(3-iBPos); @@ -71,10 +71,10 @@ size_t Bu::Base64::stop() iTotalOut += rNext.write( outBuf, 4 ); return iTotalOut; } - else - { +// else +// { return iTotalIn; - } +// } } size_t Bu::Base64::read( void *pBuf, size_t nBytes ) diff --git a/src/base64.h b/src/base64.h index 2c3b331..41264e0 100644 --- a/src/base64.h +++ b/src/base64.h @@ -12,16 +12,7 @@ namespace Bu class Base64 : public Bu::Filter { public: - enum Mode - { - Encode = 0x01, - Read = 0x01, - Decode = 0x02, - Write = 0x02 - }; - - public: - Base64( Bu::Stream &rNext, Mode eMode ); + Base64( Bu::Stream &rNext ); virtual ~Base64(); virtual void start(); @@ -38,6 +29,12 @@ namespace Bu size_t iTotalOut; static const char tblEnc[65]; char tblDec[80]; + enum Mode + { + Nothing = 0x00, + Encode = 0x01, + Decode = 0x02, + }; Mode eMode; }; }; diff --git a/src/tests/base64.cpp b/src/tests/base64.cpp index 4f2d68b..eaf6a16 100644 --- a/src/tests/base64.cpp +++ b/src/tests/base64.cpp @@ -13,7 +13,7 @@ int main( int argc, char *argv[] ) argv++; Bu::File fIn( argv[0], Bu::File::Read ); Bu::File fOut( argv[1], Bu::File::WriteNew ); - Bu::Base64 bOut( fOut, Bu::Base64::Write ); + Bu::Base64 bOut( fOut ); char buf[900]; for(;;) @@ -29,7 +29,7 @@ int main( int argc, char *argv[] ) argv++; Bu::File fIn( argv[0], Bu::File::Read ); Bu::File fOut( argv[1], Bu::File::WriteNew ); - Bu::Base64 bIn( fIn, Bu::Base64::Read ); + Bu::Base64 bIn( fIn ); char buf[900]; for(;;) -- cgit v1.2.3