You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@santuario.apache.org by bl...@apache.org on 2003/10/25 12:30:55 UTC
cvs commit: xml-security/c/src/transformers TXFMBase64.hpp TXFMBase64.cpp
blautenb 2003/10/25 03:30:55
Modified: c/src/transformers TXFMBase64.hpp TXFMBase64.cpp
Log:
Add buffering to cater for input > 2048 bytes
Revision Changes Path
1.9 +4 -2 xml-security/c/src/transformers/TXFMBase64.hpp
Index: TXFMBase64.hpp
===================================================================
RCS file: /home/cvs/xml-security/c/src/transformers/TXFMBase64.hpp,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- TXFMBase64.hpp 11 Sep 2003 11:11:29 -0000 1.8
+++ TXFMBase64.hpp 25 Oct 2003 10:30:54 -0000 1.9
@@ -106,7 +106,9 @@
TXFMBase64();
bool m_complete; // Is the work done
- unsigned char m_base64Buffer[2050]; // Always keep 2K of data
+ unsigned char m_outputBuffer[2050]; // Always keep 2K of data
+ unsigned char m_inputBuffer[1026]; // Always read 1026 bytes (encoding grows)
+ unsigned int m_remaining; // How much data is left in the buffer?
XSECCryptoBase64 * mp_b64;
bool m_doDecode; // Are we encoding or decoding?
};
1.7 +76 -20 xml-security/c/src/transformers/TXFMBase64.cpp
Index: TXFMBase64.cpp
===================================================================
RCS file: /home/cvs/xml-security/c/src/transformers/TXFMBase64.cpp,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- TXFMBase64.cpp 11 Sep 2003 11:11:29 -0000 1.6
+++ TXFMBase64.cpp 25 Oct 2003 10:30:54 -0000 1.7
@@ -79,6 +79,7 @@
TXFMBase64::TXFMBase64(DOMDocument *doc, bool decode) : TXFMBase(doc) {
m_complete = false; // Nothing yet to output
+ m_remaining = 0;
m_doDecode = decode;
mp_b64 = XSECPlatformUtils::g_cryptoProvider->base64();
@@ -138,36 +139,91 @@
unsigned int TXFMBase64::readBytes(XMLByte * const toFill, unsigned int maxToFill) {
+ unsigned int ret, fill, leftToFill;
+
+ ret = 0; // How much have we copied?
+ leftToFill = maxToFill; // Still have to copy in entire thing
+
+ while (ret != maxToFill && (m_complete == false || m_remaining > 0)) {
+
+ if (m_remaining != 0) {
+
+ // Copy anything remaining in the buffer to the output
+
+ fill = (leftToFill > m_remaining ? m_remaining : leftToFill);
+ memcpy(&toFill[ret], m_outputBuffer, fill);
+
+ if (fill < m_remaining)
+ memmove(m_outputBuffer, m_outputBuffer + fill, (m_remaining - fill));
+
+ m_remaining -= fill;
+ leftToFill -= fill;
+ ret += fill;
+ }
+
+ // Now do some crypting
+
+ if (m_complete == false && m_remaining == 0) {
+
+ unsigned int sz = input->readBytes(m_inputBuffer, 1024);
+
+ if (m_doDecode) {
+
+ if (sz == 0) {
+ m_complete = true;
+ m_remaining = mp_b64->decodeFinish(m_outputBuffer, 2048);
+ }
+ else
+ m_remaining = mp_b64->decode(m_inputBuffer, sz, m_outputBuffer, 2048);
+ }
+ else {
+
+ if (sz == 0) {
+ m_complete = true;
+ m_remaining = mp_b64->encodeFinish(m_outputBuffer, 3072);
+ }
+ else
+ m_remaining = mp_b64->encode(m_inputBuffer, sz, m_outputBuffer, 2048);
+ }
+ }
+
+ }
+
+ return ret;
+#if 0
unsigned int ret, fill;
if (m_complete)
return 0;
fill = (maxToFill > 2000 ? 2000 : maxToFill);
+ ret = 0;
+ while (ret == 0 && !m_complete) {
+
+ unsigned int sz = input->readBytes(m_base64Buffer, fill / 2);
- unsigned int sz = input->readBytes(m_base64Buffer, fill);
-
- if (m_doDecode) {
- if (sz == 0)
- ret = mp_b64->decodeFinish((unsigned char *) toFill, maxToFill);
- else
- ret = mp_b64->decode(m_base64Buffer, sz, (unsigned char *) toFill, maxToFill);
-
- if (ret == 0)
- m_complete = true;
- }
- else {
- if (sz == 0)
- ret = mp_b64->encodeFinish((unsigned char *) toFill, maxToFill);
- else
- ret = mp_b64->encode(m_base64Buffer, sz, (unsigned char *) toFill, maxToFill);
+ if (m_doDecode) {
+ if (sz == 0)
+ ret = mp_b64->decodeFinish((unsigned char *) toFill, maxToFill);
+ else
+ ret = mp_b64->decode(m_base64Buffer, sz, (unsigned char *) toFill, maxToFill);
+
+ if (ret == 0)
+ m_complete = true;
+ }
+ else {
+ if (sz == 0) {
+ ret = mp_b64->encodeFinish((unsigned char *) toFill, maxToFill);
+ m_complete = true;
+ }
+ else
+ ret = mp_b64->encode(m_base64Buffer, sz, (unsigned char *) toFill, maxToFill);
- if (ret == 0)
- m_complete = true;
+ }
}
return ret;
-
+#endif
}
DOMDocument *TXFMBase64::getDocument() {