aboutsummaryrefslogtreecommitdiff
path: root/src/base64.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/base64.cpp')
-rw-r--r--src/base64.cpp31
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
80size_t Bu::Base64::read( void *pBuf, size_t nBytes ) 83size_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;