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 2005/07/17 06:34:05 UTC
cvs commit: xml-security/c/src/xenc/impl XENCCipherImpl.cpp
blautenb 2005/07/16 21:34:04
Modified: c/src/utils XSECDOMUtils.cpp XSECDOMUtils.hpp
c/src/xenc/impl XENCCipherImpl.cpp
Log:
Update deserialise to only transcode the header and footer of the decrypted fragment rather than the entire piece
Revision Changes Path
1.27 +54 -1 xml-security/c/src/utils/XSECDOMUtils.cpp
Index: XSECDOMUtils.cpp
===================================================================
RCS file: /home/cvs/xml-security/c/src/utils/XSECDOMUtils.cpp,v
retrieving revision 1.26
retrieving revision 1.27
diff -u -r1.26 -r1.27
--- XSECDOMUtils.cpp 3 Feb 2005 13:53:54 -0000 1.26
+++ XSECDOMUtils.cpp 17 Jul 2005 04:34:04 -0000 1.27
@@ -383,6 +383,59 @@
}
+char DSIG_EXPORT * transcodeToUTF8(const XMLCh * src) {
+
+ // Take a UTF-16 buffer and transcode to UTF-8
+
+ safeBuffer fullDest("");
+ unsigned char outputBuf[2050];
+
+ // Grab a transcoder
+ XMLTransService::Codes failReason;
+
+#if defined(XSEC_XERCES_REQUIRES_MEMMGR)
+ XMLTranscoder* t =
+ XMLPlatformUtils::fgTransService->makeNewTranscoderFor("UTF-8",
+ failReason,
+ 2*1024,
+ XMLPlatformUtils::fgMemoryManager);
+#else
+ XMLTranscoder* t =
+ XMLPlatformUtils::fgTransService->makeNewTranscoderFor("UTF-8",
+ failReason,
+ 2*1024);
+#endif
+ Janitor<XMLTranscoder> j_t(t);
+
+ // Need to loop through, 2K at a time
+ unsigned int charactersEaten, charactersOutput;
+ unsigned int totalCharsEaten = 0;
+ unsigned int charsToEat = XMLString::stringLen(src);
+
+ while (totalCharsEaten < charsToEat) {
+
+ int toEat = charsToEat - totalCharsEaten;
+
+ if (toEat > 2048)
+ toEat = 2048;
+
+ charactersOutput = t->transcodeTo(&src[totalCharsEaten],
+ toEat,
+ (unsigned char * const) outputBuf,
+ 2048,
+ charactersEaten,
+ XMLTranscoder::UnRep_RepChar);
+
+ outputBuf[charactersOutput] = '\0';
+ fullDest.sbStrcatIn((char *) outputBuf);
+ totalCharsEaten += charactersEaten;
+ }
+
+ // Dup and output
+ return XMLString::replicate(fullDest.rawCharBuffer());
+
+}
+
// --------------------------------------------------------------------------------
// String decode/encode
// --------------------------------------------------------------------------------
1.21 +2 -1 xml-security/c/src/utils/XSECDOMUtils.hpp
Index: XSECDOMUtils.hpp
===================================================================
RCS file: /home/cvs/xml-security/c/src/utils/XSECDOMUtils.hpp,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -r1.20 -r1.21
--- XSECDOMUtils.hpp 26 Feb 2005 10:12:31 -0000 1.20
+++ XSECDOMUtils.hpp 17 Jul 2005 04:34:04 -0000 1.21
@@ -79,6 +79,7 @@
// --------------------------------------------------------------------------------
XMLCh DSIG_EXPORT * transcodeFromUTF8(const unsigned char * src);
+char DSIG_EXPORT * transcodeToUTF8(const XMLCh * src);
// --------------------------------------------------------------------------------
// Find a nominated DSIG/XENC node in a document
1.24 +16 -6 xml-security/c/src/xenc/impl/XENCCipherImpl.cpp
Index: XENCCipherImpl.cpp
===================================================================
RCS file: /home/cvs/xml-security/c/src/xenc/impl/XENCCipherImpl.cpp,v
retrieving revision 1.23
retrieving revision 1.24
diff -u -r1.23 -r1.24
--- XENCCipherImpl.cpp 26 Feb 2005 03:17:08 -0000 1.23
+++ XENCCipherImpl.cpp 17 Jul 2005 04:34:04 -0000 1.24
@@ -228,9 +228,9 @@
DOMDocumentFragment * result;
// Create the context to parse the document against
- safeBuffer sb;
+ safeBuffer sb, sbt;
sb.sbXMLChIn(DSIGConstants::s_unicodeStrEmpty);
- sb.sbXMLChAppendCh(chUnicodeMarker);
+ //sb.sbXMLChAppendCh(chUnicodeMarker);
//sb.sbXMLChCat8("<?xml version=\"1.0\" encoding=\"UTF-16\"?><");
sb.sbXMLChAppendCh(chOpenAngle);
sb.sbXMLChCat(s_tagname);
@@ -283,17 +283,27 @@
wk = wk->getParentNode();
}
sb.sbXMLChAppendCh(chCloseAngle);
+
+ char * prefix = transcodeToUTF8(sb.rawXMLChBuffer());
+ ArrayJanitor<char> j_prefix(prefix);
+
+ sbt = prefix;
+ sbt.sbStrcatIn(content.rawCharBuffer());
// Now transform the content to UTF-8
- sb.sbXMLChCat8(content.rawCharBuffer());
+ //sb.sbXMLChCat8(content.rawCharBuffer());
// Terminate the string
+ sb.sbXMLChIn(DSIGConstants::s_unicodeStrEmpty);
sb.sbXMLChAppendCh(chOpenAngle);
sb.sbXMLChAppendCh(chForwardSlash);
sb.sbXMLChCat(s_tagname);
sb.sbXMLChAppendCh(chCloseAngle);
+ char * trailer = transcodeToUTF8(sb.rawXMLChBuffer());
+ sbt.sbStrcatIn(trailer);
+
// Now we need to parse the document
XercesDOMParser * parser = new XercesDOMParser;
@@ -305,8 +315,8 @@
// Create an input source
- unsigned int bytes = XMLString::stringLen(sb.rawXMLChBuffer()) * sizeof(XMLCh);
- MemBufInputSource* memIS = new MemBufInputSource ((const XMLByte*) sb.rawBuffer(), bytes, "XSECMem");
+ unsigned int bytes = XMLString::stringLen(sbt.rawCharBuffer());
+ MemBufInputSource* memIS = new MemBufInputSource ((const XMLByte*) sbt.rawBuffer(), bytes, "XSECMem");
Janitor<MemBufInputSource> j_memIS(memIS);
int errorCount = 0;