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 2006/04/09 05:16:39 UTC
svn commit: r392671 - in /xml/security/trunk/c/src/xenc: XENCCipher.hpp
impl/XENCCipherImpl.cpp impl/XENCCipherImpl.hpp
Author: blautenb
Date: Sat Apr 8 20:16:36 2006
New Revision: 392671
URL: http://svn.apache.org/viewcvs?rev=392671&view=rev
Log:
Support for detached versions of decrypt and encrypt where the source data is not modified.
Modified:
xml/security/trunk/c/src/xenc/XENCCipher.hpp
xml/security/trunk/c/src/xenc/impl/XENCCipherImpl.cpp
xml/security/trunk/c/src/xenc/impl/XENCCipherImpl.hpp
Modified: xml/security/trunk/c/src/xenc/XENCCipher.hpp
URL: http://svn.apache.org/viewcvs/xml/security/trunk/c/src/xenc/XENCCipher.hpp?rev=392671&r1=392670&r2=392671&view=diff
==============================================================================
--- xml/security/trunk/c/src/xenc/XENCCipher.hpp (original)
+++ xml/security/trunk/c/src/xenc/XENCCipher.hpp Sat Apr 8 20:16:36 2006
@@ -110,6 +110,25 @@
) = 0;
/**
+ * \brief Decrypt the nominated element without replacing it.
+ *
+ * Decrypts the passed in element, which must be the root
+ * node of a \<EncryptedData\> method with a type of "#Element".
+ * If not, the library will throw an XSECException exception. Rather
+ * than replacing the element with the decrypted content, the
+ * result is passed to the caller as an orphaned document fragment.
+ *
+ * @param element Root of EncryptedData DOM structyre to decrypt
+ * @returns The document fragment containing the decrypted node-set.
+ * @throws XSECException if the decryption fails, or if this is
+ * not a valid EncryptedData DOM structure.
+ */
+
+ virtual XERCES_CPP_NAMESPACE_QUALIFIER DOMNode * decryptElementDetached(
+ XERCES_CPP_NAMESPACE_QUALIFIER DOMElement * element
+ ) = 0;
+
+ /**
* \brief Decrypt currently loaded element.
*
* Decrypts the an element that was previously passed in via
@@ -131,6 +150,26 @@
virtual XERCES_CPP_NAMESPACE_QUALIFIER DOMDocument * decryptElement(void) = 0;
/**
+ * \brief Decrypt currently loaded element without replacing it.
+ *
+ * Decrypts the an element that was previously passed in via
+ * loadEncryptedData with a type of "#Element".
+ * If not, the library will throw an XSECException exception.
+ *
+ * This does not replace the currently existing DOM document. It returns
+ * an "orphaned" document fragment containing the serialised version of the
+ * decrypted data.
+ *
+ * @param element Root of EncryptedData DOM structyre to decrypt
+ * @returns The owning document with the element replaced, or NULL
+ * if the decryption fails for some reason (normally an exception).
+ * @throws XSECException if the decryption fails, or if this is
+ * not a valid EncryptedData DOM structure.
+ */
+
+ virtual XERCES_CPP_NAMESPACE_QUALIFIER DOMNode * decryptElementDetached(void) = 0;
+
+ /**
* \brief Decrypt the nominated element and put the output to an InputStream.
*
* Decrypts the passed in element, which must be the root
@@ -217,6 +256,31 @@
) = 0;
/**
+ * \brief Encrypt the nominated element without affecting the current document.
+ *
+ * Encrypts the passed in element and all children. The element
+ * is not replaced - the return node is an "orphaned" subtree from
+ * the passed in document and the original document is untouched.
+ *
+ * @param element Element (and children) to encrypt
+ * @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 resulting document fragment containing the encrypted data.
+ * @throws XSECException if the encryption fails.
+ */
+
+ virtual XERCES_CPP_NAMESPACE_QUALIFIER DOMNode * encryptElementDetached(
+ XERCES_CPP_NAMESPACE_QUALIFIER DOMElement * element,
+ encryptionMethod em,
+ const XMLCh * algorithmURI = NULL
+ ) = 0;
+
+ /**
* \brief Encrypt the children of the nominated element
*
* Encrypts the all children of the passed in element, but
@@ -242,6 +306,33 @@
const XMLCh * algorithmURI = NULL
) = 0;
+ /**
+ * \brief Encrypt the children of the nominated element
+ *
+ * Encrypts the all children of the passed in element. The input
+ * DOM node set is untouched, but the function returns an orphaned
+ * sub-tree owned by the passed in document containing the encrypted
+ * data.
+ *
+ * @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 resulting (orphaned) sub-tree from the passed in document
+ * containing the encrypted data.
+ * @throws XSECException if the encryption fails.
+ */
+
+ virtual XERCES_CPP_NAMESPACE_QUALIFIER DOMNode * encryptElementContentDetached(
+ XERCES_CPP_NAMESPACE_QUALIFIER DOMElement * element,
+ encryptionMethod em,
+ const XMLCh * algorithmURI = NULL
+ ) = 0;
+
/**
* \brief Encrypt a buffer of data as a key
*
Modified: xml/security/trunk/c/src/xenc/impl/XENCCipherImpl.cpp
URL: http://svn.apache.org/viewcvs/xml/security/trunk/c/src/xenc/impl/XENCCipherImpl.cpp?rev=392671&r1=392670&r2=392671&view=diff
==============================================================================
--- xml/security/trunk/c/src/xenc/impl/XENCCipherImpl.cpp (original)
+++ xml/security/trunk/c/src/xenc/impl/XENCCipherImpl.cpp Sat Apr 8 20:16:36 2006
@@ -462,7 +462,23 @@
}
-DOMDocument * XENCCipherImpl::decryptElement(void) {
+DOMNode * XENCCipherImpl::decryptElementDetached(DOMElement * element) {
+
+ // First of all load the element
+ if (mp_encryptedData != NULL)
+ delete mp_encryptedData;
+
+ XSECnew(mp_encryptedData,
+ XENCEncryptedDataImpl(mp_env, element));
+
+ // Load
+ mp_encryptedData->load();
+
+ return decryptElementDetached();
+
+}
+
+DOMNode * XENCCipherImpl::decryptElementDetached(void) {
XSECAlgorithmHandler *handler;
@@ -558,6 +574,16 @@
DOMElement * element = mp_encryptedData->getElement();
DOMDocumentFragment * frag = deSerialise(sb, element);
+ return frag;
+
+}
+
+DOMDocument * XENCCipherImpl::decryptElement(void) {
+
+ // Call the worker
+ DOMElement * element = mp_encryptedData->getElement();
+ DOMDocumentFragment * frag = (DOMDocumentFragment *) decryptElementDetached();
+
if (frag != NULL) {
// Have something to replace current element with
@@ -1028,7 +1054,7 @@
// Encrypt an element
// --------------------------------------------------------------------------------
-DOMDocument * XENCCipherImpl::encryptElement(DOMElement * element,
+DOMNode * XENCCipherImpl::encryptElementDetached(DOMElement * element,
encryptionMethod em,
const XMLCh * algorithmURI) {
@@ -1061,6 +1087,16 @@
encryptTXFMChain(c, em, algorithmURI);
mp_encryptedData->setType(DSIGConstants::s_unicodeStrURIXENC_ELEMENT);
+ return mp_encryptedData->getElement();
+
+}
+
+DOMDocument * XENCCipherImpl::encryptElement(DOMElement * element,
+ encryptionMethod em,
+ const XMLCh * algorithmURI) {
+
+ // Do the actual encryption work
+ encryptElementDetached(element, em, algorithmURI);
// Replace original element
DOMNode * p = element->getParentNode();
@@ -1079,6 +1115,7 @@
}
+
// --------------------------------------------------------------------------------
// Encrypt an element's children
// --------------------------------------------------------------------------------
@@ -1087,6 +1124,33 @@
XERCES_CPP_NAMESPACE_QUALIFIER DOMElement * element,
encryptionMethod em,
const XMLCh * algorithmURI) {
+
+ // Do the work
+ encryptElementContentDetached(element, em, algorithmURI);
+
+ // Delete current children
+ DOMNode * n = element->getFirstChild();
+ while (n != NULL) {
+
+ element->removeChild(n);
+ n->release();
+
+ n = element->getFirstChild();
+
+ }
+
+ // Now add the EncryptedData
+ element->appendChild(mp_encryptedData->getElement());
+
+ return mp_doc;
+
+}
+
+
+DOMNode * XENCCipherImpl::encryptElementContentDetached(
+ 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) {
@@ -1135,24 +1199,9 @@
mp_encryptedData->setType(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->getElement());
-
- return mp_doc;
+ return mp_encryptedData->getElement();
}
-
Modified: xml/security/trunk/c/src/xenc/impl/XENCCipherImpl.hpp
URL: http://svn.apache.org/viewcvs/xml/security/trunk/c/src/xenc/impl/XENCCipherImpl.hpp?rev=392671&r1=392670&r2=392671&view=diff
==============================================================================
--- xml/security/trunk/c/src/xenc/impl/XENCCipherImpl.hpp (original)
+++ xml/security/trunk/c/src/xenc/impl/XENCCipherImpl.hpp Sat Apr 8 20:16:36 2006
@@ -53,8 +53,12 @@
XERCES_CPP_NAMESPACE_QUALIFIER DOMDocument *
decryptElement(XERCES_CPP_NAMESPACE_QUALIFIER DOMElement * element);
+ XERCES_CPP_NAMESPACE_QUALIFIER DOMNode *
+ decryptElementDetached(XERCES_CPP_NAMESPACE_QUALIFIER DOMElement * element);
XERCES_CPP_NAMESPACE_QUALIFIER DOMDocument *
decryptElement(void);
+ XERCES_CPP_NAMESPACE_QUALIFIER DOMNode *
+ decryptElementDetached(void);
XSECBinTXFMInputStream * decryptToBinInputStream(
XERCES_CPP_NAMESPACE_QUALIFIER DOMElement * element
);
@@ -76,6 +80,14 @@
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);
+ XERCES_CPP_NAMESPACE_QUALIFIER DOMNode * encryptElementDetached(
+ XERCES_CPP_NAMESPACE_QUALIFIER DOMElement * element,
+ encryptionMethod em,
+ const XMLCh * uri = NULL);
+ virtual XERCES_CPP_NAMESPACE_QUALIFIER DOMNode * encryptElementContentDetached(
XERCES_CPP_NAMESPACE_QUALIFIER DOMElement * element,
encryptionMethod em,
const XMLCh * algorithmURI = NULL);