diff options
author | Mike Buland <eichlan@xagasoft.com> | 2009-07-29 23:02:26 +0000 |
---|---|---|
committer | Mike Buland <eichlan@xagasoft.com> | 2009-07-29 23:02:26 +0000 |
commit | 24d46e151326b1b159603442e74540bf87897a53 (patch) | |
tree | 581d72fe2bda347793dddd4457f06614636474b4 | |
parent | c2292209eb4ece185f555a5c7823726794fe34cc (diff) | |
download | libbu++-24d46e151326b1b159603442e74540bf87897a53.tar.gz libbu++-24d46e151326b1b159603442e74540bf87897a53.tar.bz2 libbu++-24d46e151326b1b159603442e74540bf87897a53.tar.xz libbu++-24d46e151326b1b159603442e74540bf87897a53.zip |
Base64, now more clever with fewer options.
Diffstat (limited to '')
-rw-r--r-- | src/base64.cpp | 12 | ||||
-rw-r--r-- | src/base64.h | 17 | ||||
-rw-r--r-- | src/tests/base64.cpp | 4 |
3 files changed, 15 insertions, 18 deletions
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] = { | |||
4 | "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/" | 4 | "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/" |
5 | }; | 5 | }; |
6 | 6 | ||
7 | Bu::Base64::Base64( Bu::Stream &rNext, Mode eMode ) : | 7 | Bu::Base64::Base64( Bu::Stream &rNext ) : |
8 | Bu::Filter( rNext ), | 8 | Bu::Filter( rNext ), |
9 | iBPos( 0 ), | 9 | iBPos( 0 ), |
10 | iBuf( 0 ), | 10 | iBuf( 0 ), |
11 | iTotalIn( 0 ), | 11 | iTotalIn( 0 ), |
12 | iTotalOut( 0 ), | 12 | iTotalOut( 0 ), |
13 | eMode( eMode ) | 13 | eMode( Nothing ) |
14 | { | 14 | { |
15 | start(); | 15 | start(); |
16 | 16 | ||
@@ -54,7 +54,7 @@ void Bu::Base64::start() | |||
54 | 54 | ||
55 | size_t Bu::Base64::stop() | 55 | size_t Bu::Base64::stop() |
56 | { | 56 | { |
57 | if( eMode == Write ) | 57 | // if( eMode |= Encode ) |
58 | { | 58 | { |
59 | char outBuf[4]; | 59 | char outBuf[4]; |
60 | int iBUsed = 4-(3-iBPos); | 60 | int iBUsed = 4-(3-iBPos); |
@@ -71,10 +71,10 @@ size_t Bu::Base64::stop() | |||
71 | iTotalOut += rNext.write( outBuf, 4 ); | 71 | iTotalOut += rNext.write( outBuf, 4 ); |
72 | return iTotalOut; | 72 | return iTotalOut; |
73 | } | 73 | } |
74 | else | 74 | // else |
75 | { | 75 | // { |
76 | return iTotalIn; | 76 | return iTotalIn; |
77 | } | 77 | // } |
78 | } | 78 | } |
79 | 79 | ||
80 | size_t Bu::Base64::read( void *pBuf, size_t nBytes ) | 80 | 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 | |||
12 | class Base64 : public Bu::Filter | 12 | class Base64 : public Bu::Filter |
13 | { | 13 | { |
14 | public: | 14 | public: |
15 | enum Mode | 15 | Base64( Bu::Stream &rNext ); |
16 | { | ||
17 | Encode = 0x01, | ||
18 | Read = 0x01, | ||
19 | Decode = 0x02, | ||
20 | Write = 0x02 | ||
21 | }; | ||
22 | |||
23 | public: | ||
24 | Base64( Bu::Stream &rNext, Mode eMode ); | ||
25 | virtual ~Base64(); | 16 | virtual ~Base64(); |
26 | 17 | ||
27 | virtual void start(); | 18 | virtual void start(); |
@@ -38,6 +29,12 @@ namespace Bu | |||
38 | size_t iTotalOut; | 29 | size_t iTotalOut; |
39 | static const char tblEnc[65]; | 30 | static const char tblEnc[65]; |
40 | char tblDec[80]; | 31 | char tblDec[80]; |
32 | enum Mode | ||
33 | { | ||
34 | Nothing = 0x00, | ||
35 | Encode = 0x01, | ||
36 | Decode = 0x02, | ||
37 | }; | ||
41 | Mode eMode; | 38 | Mode eMode; |
42 | }; | 39 | }; |
43 | }; | 40 | }; |
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[] ) | |||
13 | argv++; | 13 | argv++; |
14 | Bu::File fIn( argv[0], Bu::File::Read ); | 14 | Bu::File fIn( argv[0], Bu::File::Read ); |
15 | Bu::File fOut( argv[1], Bu::File::WriteNew ); | 15 | Bu::File fOut( argv[1], Bu::File::WriteNew ); |
16 | Bu::Base64 bOut( fOut, Bu::Base64::Write ); | 16 | Bu::Base64 bOut( fOut ); |
17 | 17 | ||
18 | char buf[900]; | 18 | char buf[900]; |
19 | for(;;) | 19 | for(;;) |
@@ -29,7 +29,7 @@ int main( int argc, char *argv[] ) | |||
29 | argv++; | 29 | argv++; |
30 | Bu::File fIn( argv[0], Bu::File::Read ); | 30 | Bu::File fIn( argv[0], Bu::File::Read ); |
31 | Bu::File fOut( argv[1], Bu::File::WriteNew ); | 31 | Bu::File fOut( argv[1], Bu::File::WriteNew ); |
32 | Bu::Base64 bIn( fIn, Bu::Base64::Read ); | 32 | Bu::Base64 bIn( fIn ); |
33 | 33 | ||
34 | char buf[900]; | 34 | char buf[900]; |
35 | for(;;) | 35 | for(;;) |