diff options
author | Mike Buland <eichlan@xagasoft.com> | 2009-07-30 20:08:24 +0000 |
---|---|---|
committer | Mike Buland <eichlan@xagasoft.com> | 2009-07-30 20:08:24 +0000 |
commit | 745a9ec043fdbe91faf26a3cfec4ecd12355f94a (patch) | |
tree | 9fb5a4c3223050ac0ea938163438a82dd44c50af /src/base64.cpp | |
parent | 3f0f30442de297859cccc18f28db83b4e755d36f (diff) | |
download | libbu++-745a9ec043fdbe91faf26a3cfec4ecd12355f94a.tar.gz libbu++-745a9ec043fdbe91faf26a3cfec4ecd12355f94a.tar.bz2 libbu++-745a9ec043fdbe91faf26a3cfec4ecd12355f94a.tar.xz libbu++-745a9ec043fdbe91faf26a3cfec4ecd12355f94a.zip |
I think I fixed a bug in Bu::Base64, we'll see what happens.
Diffstat (limited to 'src/base64.cpp')
-rw-r--r-- | src/base64.cpp | 31 |
1 files changed, 24 insertions, 7 deletions
diff --git a/src/base64.cpp b/src/base64.cpp index f6b8cce..c9a6b59 100644 --- a/src/base64.cpp +++ b/src/base64.cpp | |||
@@ -8,6 +8,9 @@ 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 | iRPos( 0 ), | ||
12 | iChars( 0 ), | ||
13 | bEosIn( false ), | ||
11 | iTotalIn( 0 ), | 14 | iTotalIn( 0 ), |
12 | iTotalOut( 0 ), | 15 | iTotalOut( 0 ), |
13 | eMode( Nothing ) | 16 | eMode( Nothing ) |
@@ -79,10 +82,25 @@ size_t Bu::Base64::stop() | |||
79 | 82 | ||
80 | size_t Bu::Base64::read( void *pBuf, size_t nBytes ) | 83 | size_t Bu::Base64::read( void *pBuf, size_t nBytes ) |
81 | { | 84 | { |
85 | if( bEosIn == true && iRPos == iChars ) | ||
86 | return 0; | ||
82 | size_t sIn = 0; | 87 | size_t sIn = 0; |
83 | char buf[4]; | 88 | char buf[4]; |
84 | while( sIn < nBytes ) | 89 | while( sIn < nBytes ) |
85 | { | 90 | { |
91 | for(; iRPos < iChars && sIn < nBytes; iRPos++, sIn++ ) | ||
92 | { | ||
93 | ((unsigned char *)pBuf)[sIn] = (iBuf>>(8*(2-iRPos)))&0xFF; | ||
94 | } | ||
95 | if( iRPos == iChars ) | ||
96 | { | ||
97 | if( bEosIn == true ) | ||
98 | return sIn; | ||
99 | else | ||
100 | iRPos = 0; | ||
101 | } | ||
102 | else if( sIn == nBytes ) | ||
103 | return sIn; | ||
86 | //if( rNext.read( buf, 4 ) == 0 ) | 104 | //if( rNext.read( buf, 4 ) == 0 ) |
87 | // return sIn; | 105 | // return sIn; |
88 | for( int j = 0; j < 4; j++ ) | 106 | for( int j = 0; j < 4; j++ ) |
@@ -95,20 +113,19 @@ size_t Bu::Base64::read( void *pBuf, size_t nBytes ) | |||
95 | j--; | 113 | j--; |
96 | } | 114 | } |
97 | } | 115 | } |
98 | int iChars = 3; | 116 | iChars = 3; |
117 | iBuf = 0; | ||
99 | for( int j = 0; j < 4; j++ ) | 118 | for( int j = 0; j < 4; j++ ) |
100 | { | 119 | { |
101 | if( buf[j] == '=' ) | 120 | if( buf[j] == '=' ) |
121 | { | ||
102 | iChars--; | 122 | iChars--; |
123 | bEosIn = true; | ||
124 | } | ||
103 | else | 125 | else |
104 | iBuf |= (tblDec[buf[j]-'+']&0x3f)<<((3-j)*6); | 126 | iBuf |= (tblDec[buf[j]-'+']&0x3f)<<((3-j)*6); |
105 | printf("%d: %06X (%02X)\n", j, iBuf, (tblDec[buf[j]-'+']&0x3f) ); | 127 | //printf("%d: %06X (%02X)\n", j, iBuf, (tblDec[buf[j]-'+']&0x3f) ); |
106 | } | 128 | } |
107 | for( int j = 0; j < iChars; j++ ) | ||
108 | { | ||
109 | ((unsigned char *)pBuf)[sIn++] = (iBuf>>(8*(2-j)))&0xFF; | ||
110 | } | ||
111 | iBuf = 0; | ||
112 | } | 129 | } |
113 | 130 | ||
114 | return sIn; | 131 | return sIn; |