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/11/10 03:48:23 UTC

cvs commit: xml-security/c/src/xenc/impl XENCCipherImpl.cpp XENCCipherImpl.hpp

blautenb    2003/11/09 18:48:23

  Modified:    c/src/xenc XENCCipher.hpp
               c/src/xenc/impl XENCCipherImpl.cpp XENCCipherImpl.hpp
  Log:
  Implementation of encryptElementContent
  
  Revision  Changes    Path
  1.11      +27 -1     xml-security/c/src/xenc/XENCCipher.hpp
  
  Index: XENCCipher.hpp
  ===================================================================
  RCS file: /home/cvs/xml-security/c/src/xenc/XENCCipher.hpp,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- XENCCipher.hpp	4 Nov 2003 11:28:36 -0000	1.10
  +++ XENCCipher.hpp	10 Nov 2003 02:48:23 -0000	1.11
  @@ -239,6 +239,32 @@
   	) = 0;
   
   	/**
  +	 * \brief Encrypt the children of the nominated element
  +	 * 
  +	 * Encrypts the all children of the passed in element, but
  +	 * leaves the element itself in place, with one new child - an
  +	 * EncryptedData node of type #content
  +	 *
  +	 * @param element Element whose children are to be encrypted
  +	 * @param em The encryptionMethod to use for this encryption.  Use
  +	 * ENCRYPT_NONE if a user defined type is required.
  +	 * @param algorithmURI If ENCRYPT_NONE is passed in, this will be
  +	 * used to set the algorithm URI.  If this is also NULL - no
  +	 * EncryptionMethod will be set.  <b>NULL Value Unsupported if em not
  +	 * set!  It's use could cause problems!</b>
  +	 *
  +	 * @returns The owning document with the element's children replaced, or NULL
  +	 * if the decryption fails for some reason (normally an exception).
  +	 * @throws XSECException if the encryption fails.
  +	 */
  +
  +	virtual XERCES_CPP_NAMESPACE_QUALIFIER DOMDocument * encryptElementContent(
  +		XERCES_CPP_NAMESPACE_QUALIFIER DOMElement * element,
  +		encryptionMethod em,
  +		const XMLCh * algorithmURI = NULL
  +	) = 0;
  +
  +	/**
   	 * \brief Encrypt a buffer of data as a key
   	 *
   	 * Encrypts the passed in data and creates an EncryptedKey element
  
  
  
  1.15      +82 -3     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.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- XENCCipherImpl.cpp	4 Nov 2003 11:28:36 -0000	1.14
  +++ XENCCipherImpl.cpp	10 Nov 2003 02:48:23 -0000	1.15
  @@ -77,6 +77,7 @@
   #include <xsec/transformers/TXFMSB.hpp>
   #include <xsec/transformers/TXFMURL.hpp>
   #include <xsec/transformers/TXFMDocObject.hpp>
  +#include <xsec/transformers/TXFMConcatChains.hpp>
   #include <xsec/utils/XSECDOMUtils.hpp>
   #include <xsec/framework/XSECEnv.hpp>
   #include <xsec/enc/XSECKeyInfoResolver.hpp>
  @@ -343,9 +344,7 @@
   	// Create an input source
   
   	unsigned int bytes = XMLString::stringLen(sb.rawXMLChBuffer()) * sizeof(XMLCh);
  -	char * utf = XMLString::transcode(sb.rawXMLChBuffer());
   	MemBufInputSource* memIS = new MemBufInputSource ((const XMLByte*) sb.rawBuffer(), bytes, "XSECMem");
  -	//MemBufInputSource* memIS = new MemBufInputSource ((const XMLByte*) utf, strlen(utf), "XSECMem");
   	Janitor<MemBufInputSource> j_memIS(memIS);
   
   	int errorCount = 0;
  @@ -1031,9 +1030,89 @@
   
   	p->replaceChild(mp_encryptedData->getDOMNode(), element);
   
  +	// Clear up the old child
  +	element->release();
  +
  +	return mp_doc;
  +
  +}
  +
  +// --------------------------------------------------------------------------------
  +//			Encrypt an element's children
  +// --------------------------------------------------------------------------------
  +
  +DOMDocument * XENCCipherImpl::encryptElementContent(
  +		XERCES_CPP_NAMESPACE_QUALIFIER DOMElement * element,
  +		encryptionMethod em,
  +		const XMLCh * algorithmURI) {
  +
  +	// Make sure we have a key before we do anything too drastic
  +	if (mp_key == NULL) {
  +		throw XSECException(XSECException::CipherError, 
  +			"XENCCipherImpl::encryptElement - No key set");
  +	}
  +
  +	// Create a transform chain to do the encryption
  +	// We use a concat transformer so we can concatinate the bytestreams
  +	// from the serialisation of each child in turn
  +
  +	TXFMConcatChains * tcat;
  +	XSECnew(tcat, TXFMConcatChains(mp_doc));
  +	TXFMChain * c;
  +	XSECnew(c, TXFMChain(tcat));
  +	Janitor<TXFMChain> j_c(c);
  +
  +	DOMNode *n = element->getFirstChild();
  +	
  +	while (n != NULL) {
  +
  +		TXFMDocObject * tdocObj;
  +		XSECnew(tdocObj, TXFMDocObject(mp_doc));
  +		TXFMChain * tc;
  +		XSECnew(tc, TXFMChain(tdocObj));
  +
  +		// Add to the concat object, which will own it, so if anything throws
  +		// the memory will be released.
  +
  +		tcat->setInput(tc);
  +		tdocObj->setInput(mp_doc, n);
  +
  +		// Now need to serialise the element - easiest to just use a canonicaliser
  +		TXFMC14n *tc14n;
  +		XSECnew(tc14n, TXFMC14n(mp_doc));
  +		tc->appendTxfm(tc14n);
  +
  +		tc14n->activateComments();
  +		tc14n->setExclusive();
  +
  +		n = n->getNextSibling();
  +
  +	}
  +
  +	encryptTXFMChain(c, em, algorithmURI);
  +
  +	mp_encryptedData->setTypeURI(DSIGConstants::s_unicodeStrURIXENC_CONTENT);
  +
  +	// Delete current children 
  +	n = element->getFirstChild();
  +	while (n != NULL) {
  +
  +		element->removeChild(n);
  +		n->release();
  +
  +		n = element->getFirstChild();
  +
  +	}
  +	
  +	// Now add the EncryptedData
  +	element->appendChild(mp_encryptedData->getDOMNode());
  +
   	return mp_doc;
   
   }
  +
  +
  +
   
   // --------------------------------------------------------------------------------
   //			Pretty Print functions
  
  
  
  1.13      +5 -1      xml-security/c/src/xenc/impl/XENCCipherImpl.hpp
  
  Index: XENCCipherImpl.hpp
  ===================================================================
  RCS file: /home/cvs/xml-security/c/src/xenc/impl/XENCCipherImpl.hpp,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- XENCCipherImpl.hpp	4 Nov 2003 11:28:36 -0000	1.12
  +++ XENCCipherImpl.hpp	10 Nov 2003 02:48:23 -0000	1.13
  @@ -116,6 +116,10 @@
   		XERCES_CPP_NAMESPACE_QUALIFIER DOMElement * element,
   		encryptionMethod em,
   		const XMLCh * uri = NULL);
  +	virtual XERCES_CPP_NAMESPACE_QUALIFIER DOMDocument * encryptElementContent(
  +		XERCES_CPP_NAMESPACE_QUALIFIER DOMElement * element,
  +		encryptionMethod em,
  +		const XMLCh * algorithmURI = NULL);
   
   	// Encrypt a key
   	virtual XENCEncryptedKey * encryptKey(