You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@santuario.apache.org by sc...@apache.org on 2017/12/20 18:50:57 UTC

svn commit: r1818844 - in /santuario/xml-security-cpp/trunk/xsec/framework: XSECProvider.cpp XSECProvider.hpp

Author: scantor
Date: Wed Dec 20 18:50:57 2017
New Revision: 1818844

URL: http://svn.apache.org/viewvc?rev=1818844&view=rev
Log:
Remove direct tracking of signature/cipher objects.

Modified:
    santuario/xml-security-cpp/trunk/xsec/framework/XSECProvider.cpp
    santuario/xml-security-cpp/trunk/xsec/framework/XSECProvider.hpp

Modified: santuario/xml-security-cpp/trunk/xsec/framework/XSECProvider.cpp
URL: http://svn.apache.org/viewvc/santuario/xml-security-cpp/trunk/xsec/framework/XSECProvider.cpp?rev=1818844&r1=1818843&r2=1818844&view=diff
==============================================================================
--- santuario/xml-security-cpp/trunk/xsec/framework/XSECProvider.cpp (original)
+++ santuario/xml-security-cpp/trunk/xsec/framework/XSECProvider.cpp Wed Dec 20 18:50:57 2017
@@ -47,38 +47,20 @@ XERCES_CPP_NAMESPACE_USE
 
 XSECProvider::XSECProvider() {
 
-	mp_URIResolver = new XSECURIResolverXerces();
+    mp_URIResolver = new XSECURIResolverXerces();
 #ifdef XSEC_XKMS_ENABLED
-	XSECnew(mp_xkmsMessageFactory, XKMSMessageFactoryImpl());
+    XSECnew(mp_xkmsMessageFactory, XKMSMessageFactoryImpl());
 #endif
 }
 
 XSECProvider::~XSECProvider() {
 
-	// First delete signatures
-	
-	SignatureListVectorType::iterator i;
-	
-	for (i = m_activeSignatures.begin(); i != m_activeSignatures.end(); ++i)
-		delete *i;
-
-	m_activeSignatures.clear();
-
-	if (mp_URIResolver != NULL)
-		delete mp_URIResolver;
-
-	// Now delete ciphers
-
-	CipherListVectorType::iterator j;
-	
-	for (j = m_activeCiphers.begin(); j != m_activeCiphers.end(); ++j)
-		delete *j;
-
-	m_activeCiphers.clear();
+    if (mp_URIResolver != NULL)
+        delete mp_URIResolver;
 
 #ifdef XSEC_XKMS_ENABLED
-	// Clean up XKMS stuff
-	delete mp_xkmsMessageFactory;
+    // Clean up XKMS stuff
+    delete mp_xkmsMessageFactory;
 #endif
 }
 
@@ -87,119 +69,69 @@ XSECProvider::~XSECProvider() {
 // --------------------------------------------------------------------------------
 
 
-DSIGSignature * XSECProvider::newSignatureFromDOM(DOMDocument *doc, DOMNode *sigNode) {
-
-	DSIGSignature * ret;
+DSIGSignature* XSECProvider::newSignatureFromDOM(DOMDocument* doc, DOMNode* sigNode) {
 
-	XSECnew(ret, DSIGSignature(doc, sigNode));
+    DSIGSignature* ret;
 
-	setup(ret);
+    XSECnew(ret, DSIGSignature(doc, sigNode));
 
-	return ret;
+    setup(ret);
 
+    return ret;
 }
 
-DSIGSignature * XSECProvider::newSignatureFromDOM(DOMDocument *doc) {
+DSIGSignature* XSECProvider::newSignatureFromDOM(DOMDocument* doc) {
 
-	DSIGSignature * ret;
+    DSIGSignature* ret;
 
-	DOMNode *sigNode = findDSIGNode(doc, "Signature");
+    DOMNode* sigNode = findDSIGNode(doc, "Signature");
 
-	if (sigNode == NULL) {
-		
-		throw XSECException(XSECException::SignatureCreationError,
-			"Could not find a signature node in passed in DOM document");
+    if (sigNode == NULL) {
 
-	}
+        throw XSECException(XSECException::SignatureCreationError,
+            "Could not find a signature node in passed in DOM document");
 
-	XSECnew(ret, DSIGSignature(doc, sigNode));
+    }
 
-	setup(ret);
+    XSECnew(ret, DSIGSignature(doc, sigNode));
 
-	return ret;
+    setup(ret);
 
+    return ret;
 }
 
-DSIGSignature * XSECProvider::newSignature(void) {
+DSIGSignature* XSECProvider::newSignature() {
 
-	DSIGSignature * ret;
+    DSIGSignature* ret;
 
-	XSECnew(ret, DSIGSignature());
+    XSECnew(ret, DSIGSignature());
 
-	setup(ret);
-
-	return ret;
+    setup(ret);
 
+    return ret;
 }
 
-void XSECProvider::releaseSignature(DSIGSignature * toRelease) {
-
-	// Find in the active list
-
-	SignatureListVectorType::iterator i;
-
-	m_providerMutex.lock();
-	i = m_activeSignatures.begin();
-	while (i != m_activeSignatures.end() && *i != toRelease)
-		++i;
-
-	if (i == m_activeSignatures.end()) {
-
-		m_providerMutex.unlock();
-
-		throw XSECException(XSECException::ProviderError,
-			"Attempt to release a signature that was not created by this provider");
-
-	}
-	
-	// For now - remove from list.  Would be better to recycle
-	m_activeSignatures.erase(i);
-	m_providerMutex.unlock();
-	delete toRelease;
-
+void XSECProvider::releaseSignature(DSIGSignature* toRelease) {
+    delete toRelease;
 }
 
 // --------------------------------------------------------------------------------
 //           Cipher Creation/Deletion
 // --------------------------------------------------------------------------------
 
-XENCCipher * XSECProvider::newCipher(DOMDocument * doc) {
+XENCCipher* XSECProvider::newCipher(DOMDocument* doc) {
 
-	XENCCipherImpl * ret;
+    XENCCipherImpl* ret;
 
-	XSECnew(ret, XENCCipherImpl(doc));
+    XSECnew(ret, XENCCipherImpl(doc));
 
-	setup(ret);
-
-	return ret;
+    setup(ret);
 
+    return ret;
 }
 
-void XSECProvider::releaseCipher(XENCCipher * toRelease) {
-
-	// Find in the active list
-
-	CipherListVectorType::iterator i;
-
-	m_providerMutex.lock();
-	i = m_activeCiphers.begin();
-	while (i != m_activeCiphers.end() && *i != toRelease)
-		++i;
-
-	if (i == m_activeCiphers.end()) {
-
-		m_providerMutex.unlock();
-
-		throw XSECException(XSECException::ProviderError,
-			"Attempt to release a cipher that was not created by this provider");
-
-	}
-	
-	// For now - remove from list.  Would be better to recycle
-	m_activeCiphers.erase(i);
-	m_providerMutex.unlock();
-	delete toRelease;
-
+void XSECProvider::releaseCipher(XENCCipher* toRelease) {
+    delete toRelease;
 }
 
 #ifdef XSEC_XKMS_ENABLED
@@ -207,10 +139,8 @@ void XSECProvider::releaseCipher(XENCCip
 //           XKMS Methods
 // --------------------------------------------------------------------------------
 
-XKMSMessageFactory * XSECProvider::getXKMSMessageFactory(void) {
-
-	return mp_xkmsMessageFactory;
-
+XKMSMessageFactory* XSECProvider::getXKMSMessageFactory() {
+    return mp_xkmsMessageFactory;
 }
 #endif
 
@@ -219,39 +149,24 @@ XKMSMessageFactory * XSECProvider::getXK
 // --------------------------------------------------------------------------------
 
 
-void XSECProvider::setDefaultURIResolver(XSECURIResolver * resolver) {
-
-	if (mp_URIResolver != 0)
-		delete mp_URIResolver;
+void XSECProvider::setDefaultURIResolver(XSECURIResolver* resolver) {
 
-	mp_URIResolver = resolver->clone();
+    if (mp_URIResolver != 0)
+        delete mp_URIResolver;
 
+    mp_URIResolver = resolver->clone();
 }
 
 // --------------------------------------------------------------------------------
 //           Internal functions
 // --------------------------------------------------------------------------------
 
-void XSECProvider::setup(DSIGSignature *sig) {
-
-	// Called by all Signature creation methods to set up the sig
-
-	// Add to the active list
-	m_providerMutex.lock();
-	m_activeSignatures.push_back(sig);
-	m_providerMutex.unlock();
-
-	sig->setURIResolver(mp_URIResolver);
+void XSECProvider::setup(DSIGSignature* sig) {
 
+    // Called by all Signature creation methods to set up the sig
+    sig->setURIResolver(mp_URIResolver);
 }
 
-void XSECProvider::setup(XENCCipher * cipher) {
-
-	// Called by all Signature creation methods to set up the sig
-
-	// Add to the active list
-	m_providerMutex.lock();
-	m_activeCiphers.push_back(cipher);
-	m_providerMutex.unlock();
+void XSECProvider::setup(XENCCipher* cipher) {
 
 }

Modified: santuario/xml-security-cpp/trunk/xsec/framework/XSECProvider.hpp
URL: http://svn.apache.org/viewvc/santuario/xml-security-cpp/trunk/xsec/framework/XSECProvider.hpp?rev=1818844&r1=1818843&r2=1818844&view=diff
==============================================================================
--- santuario/xml-security-cpp/trunk/xsec/framework/XSECProvider.hpp (original)
+++ santuario/xml-security-cpp/trunk/xsec/framework/XSECProvider.hpp Wed Dec 20 18:50:57 2017
@@ -21,7 +21,7 @@
  * XSEC
  *
  * XSECProvider.hpp := Main interface class that applications use to
- *					   get access to Signature and Encryption functions.
+ *                       get access to Signature and Encryption functions.
  *
  * $Id$
  *
@@ -34,8 +34,6 @@
 #include <xsec/xenc/XENCCipher.hpp>
 #include <xsec/xkms/XKMSMessageFactory.hpp>
 
-#include <xercesc/util/Mutexes.hpp>
-
 #include <vector>
 
 /**
@@ -56,205 +54,188 @@
 
 
 class XSEC_EXPORT XSECProvider {
-
-#if defined(XALAN_NO_NAMESPACES)
-	typedef vector<DSIGSignature *>			SignatureListVectorType;
-#else
-	typedef std::vector<DSIGSignature *>	SignatureListVectorType;
-#endif
-
-#if defined(XALAN_NO_NAMESPACES)
-	typedef vector<XENCCipher *>			CipherListVectorType;
-#else
-	typedef std::vector<XENCCipher *>		CipherListVectorType;
-#endif
-
 public:
 
     /** @name Constructors and Destructors */
     //@{
-	
+
     /**
-	 * \brief Default constructor.
-	 *
-	 * <p>The provider class requires no parameters for construction</p>
-	 *
-	 */
+     * \brief Default constructor.
+     *
+     * <p>The provider class requires no parameters for construction</p>
+     *
+     */
 
 
-	XSECProvider();
-	~XSECProvider();
+    XSECProvider();
+    virtual ~XSECProvider();
 
-	//@}
+    //@}
 
     /** @name Signature Creation Classes */
     //@{
-	
+
+    /**
+     * \brief DSIGSignature creator for use with existing XML signatures or templates.
+     *
+     * <p>Create a DSIGSignature object based on an already existing
+     * DSIG Signature XML node.  It is assumed that the underlying
+     * DOM structure is in place and works correctly.</p>
+     *
+     * <p>In this case, the caller can pass in the signature DOM Node for cases
+     * where there may be more than one signature in a document.  The caller
+     * needs to specify which signature tree is to be used.</p>
+     *
+     * @param doc The DOM document node in which the signature is embedded.
+     * @param sigNode The DOM node (within doc) that is to be used as the
+     *    base of the signature.
+     * @see DSIGSignature#load
+     */
+
+    DSIGSignature* newSignatureFromDOM(
+        XERCES_CPP_NAMESPACE_QUALIFIER DOMDocument* doc,
+        XERCES_CPP_NAMESPACE_QUALIFIER DOMNode* sigNode
+    );
+
+    /**
+     * \brief DSIGSignature creator for use with existing XML signatures or templates.
+     *
+     * <p>Create a DSIGSignature object based on an already existing
+     * DSIG Signature XML node.  It is assumed that the underlying
+     * DOM structure is in place and works correctly.</p>
+     *
+     * <p>In this case, the XML-Security libraries will find the signature
+     * node.</p>
+     *
+     * @note The library will <em>only</em> find and use the first signature node
+     * in the document.  If there are more, they will not be validated
+     * @param doc The DOM document node in which the signature is embedded.
+     * @see DSIGSignature#load
+     */
+
+    DSIGSignature* newSignatureFromDOM(XERCES_CPP_NAMESPACE_QUALIFIER DOMDocument* doc);
+
+    /**
+     * \brief DSIGSignature creator for creating new XML signatures.
+     *
+     * <p>Create an empty DSIGSignature object that can be used to create new
+     * signature values.  The returned signature object needs to be initialised
+     * with a document so a blank signature DOM structure can be created</p>
+     *
+     * @see DSIGSignature#createBlankSignature
+     */
+
+    DSIGSignature* newSignature();
+
+    /**
+     * \brief Method for destroying DSIGSignature objects created via this provider.
+     *
+     * <p>The provider keeps track of all signature objects created during the lifetime
+     * of the provider.  This method can be called to delete a signature whilst the
+     * provider is still in scope.  Otherwise the objects will be automatically
+     * deleted when the provider object goes out of scope.</p>
+     *
+     * <p>In cases where the DSIGSignature has been used to create a new DOM structure,
+     * it can be safely deleted once the signature operations have been completed without
+     * impacting the underlying DOM structure.</p>
+     *
+     * @param toRelease The DSIGSignature object to be deleted.
+     * @todo The DSIGSignature objects are fairly bulky in terms of creation and deletion.
+     * There should be a capability to store "released" objects in a re-use stack.  At the
+     * moment the Provider class simply deletes the objects.
+     * @see DSIGSignature#createBlankSignature
+     */
+
+    void releaseSignature(DSIGSignature* toRelease);
+
+    //@}
+
+    /** @name Encryption Creation Functions */
+    //@{
+
     /**
-	 * \brief DSIGSignature creator for use with existing XML signatures or templates.
-	 *
-	 * <p>Create a DSIGSignature object based on an already existing
-	 * DSIG Signature XML node.  It is assumed that the underlying
-	 * DOM structure is in place and works correctly.</p>
-	 *
-	 * <p>In this case, the caller can pass in the signature DOM Node for cases
-	 * where there may be more than one signature in a document.  The caller
-	 * needs to specify which signature tree is to be used.</p>
-	 *
-	 * @param doc The DOM document node in which the signature is embedded.
-	 * @param sigNode The DOM node (within doc) that is to be used as the 
-	 *	base of the signature.
-	 * @see DSIGSignature#load
-	 */
-
-	DSIGSignature * newSignatureFromDOM(
-		XERCES_CPP_NAMESPACE_QUALIFIER DOMDocument *doc, 
-		XERCES_CPP_NAMESPACE_QUALIFIER DOMNode *sigNode
-	);
-
-    /**
-	 * \brief DSIGSignature creator for use with existing XML signatures or templates.
-	 *
-	 * <p>Create a DSIGSignature object based on an already existing
-	 * DSIG Signature XML node.  It is assumed that the underlying
-	 * DOM structure is in place and works correctly.</p>
-	 *
-	 * <p>In this case, the XML-Security libraries will find the signature
-	 * node.</p>
-	 *
-	 * @note The library will <em>only</em> find and use the first signature node
-	 * in the document.  If there are more, they will not be validated
-	 * @param doc The DOM document node in which the signature is embedded.
-	 * @see DSIGSignature#load
-	 */
-	
-	DSIGSignature * newSignatureFromDOM(XERCES_CPP_NAMESPACE_QUALIFIER DOMDocument *doc);
-
-    /**
-	 * \brief DSIGSignature creator for creating new XML signatures.
-	 *
-	 * <p>Create an empty DSIGSignature object that can be used to create new
-	 * signature values.  The returned signature object needs to be initialised
-	 * with a document so a blank signature DOM structure can be created</p>
-	 *
-	 * @see DSIGSignature#createBlankSignature
-	 */
-	
-	DSIGSignature * newSignature(void);
-
-    /**
-	 * \brief Method for destroying DSIGSignature objects created via this provider.
-	 *
-	 * <p>The provider keeps track of all signature objects created during the lifetime
-	 * of the provider.  This method can be called to delete a signature whilst the 
-	 * provider is still in scope.  Otherwise the objects will be automatically
-	 * deleted when the provider object goes out of scope.</p>
-	 * 
-	 * <p>In cases where the DSIGSignature has been used to create a new DOM structure,
-	 * it can be safely deleted once the signature operations have been completed without
-	 * impacting the underlying DOM structure.</p>
-	 *
-	 * @param toRelease The DSIGSignature object to be deleted.
-	 * @todo The DSIGSignature objects are fairly bulky in terms of creation and deletion.
-	 * There should be a capability to store "released" objects in a re-use stack.  At the
-	 * moment the Provider class simply deletes the objects.
-	 * @see DSIGSignature#createBlankSignature
-	 */
-
-	void releaseSignature(DSIGSignature * toRelease);
-
-	//@}
-
-	/** @name Encryption Creation Functions */
-	//@{
-
-	/**
-	 * \brief Create an XENCCipher object based on a particular DOM Document
-	 *
-	 * XENCCipher is an engine class that is used to wrap encryption/decryption
-	 * functions.  Unlike the Signature functions, only a XENCCipher object attached
-	 * to a particular document is required.  Arbitrary objects within this document
-	 * can then be encrypted/decrypted using this class.
-	 *
-	 * @param doc Document to attach the XENCCipher to.
-	 * @returns An implementation object for XENCCipher
-	 */
-
-	XENCCipher * newCipher(XERCES_CPP_NAMESPACE_QUALIFIER DOMDocument * doc);
-
-	/**
-	 * \brief Method to delete XENCCipher objects created via this provider
-	 *
-	 * <p>The provider keeps track of all objects by it.  This method can be used
-	 * to delete any previously created XENCCipher objects prior to the provider
-	 * being deleted.  Any XENCCipher objects not released using this function will
-	 * automatically be deleted when the provider goes out of scope (or is itself
-	 * deleted).
-	 *
-	 * @param toRelease The XENCCipher object to be deleted
-	 */
+     * \brief Create an XENCCipher object based on a particular DOM Document
+     *
+     * XENCCipher is an engine class that is used to wrap encryption/decryption
+     * functions.  Unlike the Signature functions, only a XENCCipher object attached
+     * to a particular document is required.  Arbitrary objects within this document
+     * can then be encrypted/decrypted using this class.
+     *
+     * @param doc Document to attach the XENCCipher to.
+     * @returns An implementation object for XENCCipher
+     */
 
-	void releaseCipher(XENCCipher * toRelease);
+    XENCCipher* newCipher(XERCES_CPP_NAMESPACE_QUALIFIER DOMDocument* doc);
 
-	//@}
+    /**
+     * \brief Method to delete XENCCipher objects created via this provider
+     *
+     * <p>The provider keeps track of all objects by it.  This method can be used
+     * to delete any previously created XENCCipher objects prior to the provider
+     * being deleted.  Any XENCCipher objects not released using this function will
+     * automatically be deleted when the provider goes out of scope (or is itself
+     * deleted).
+     *
+     * @param toRelease The XENCCipher object to be deleted
+     */
+
+    void releaseCipher(XENCCipher* toRelease);
+
+    //@}
 
 #ifdef XSEC_XKMS_ENABLED
-	/** @name XKMS Functions */
-	//@{
+    /** @name XKMS Functions */
+    //@{
 
-	/**
-	 * \brief Obtain a pointer to the XKMSMessageFactory.
-	 *
-	 * The XKMSMessageFactory is used to create and manipulate XKMS messages.
-	 *
-	 * @note Unlike other objects created by the provider, only one 
-	 * XKMSMessageFactory is ever instantiated for a particular provider.
-	 * Applications should <b>never</b> delete the Factory, as it is taken
-	 * care of by the provider.
-	 */
+    /**
+     * \brief Obtain a pointer to the XKMSMessageFactory.
+     *
+     * The XKMSMessageFactory is used to create and manipulate XKMS messages.
+     *
+     * @note Unlike other objects created by the provider, only one
+     * XKMSMessageFactory is ever instantiated for a particular provider.
+     * Applications should <b>never</b> delete the Factory, as it is taken
+     * care of by the provider.
+     */
 
-	XKMSMessageFactory * getXKMSMessageFactory(void);
+    XKMSMessageFactory* getXKMSMessageFactory(void);
 #endif
 
-	/** @name Environmental Options */
-	//@{
+    /** @name Environmental Options */
+    //@{
 
-	/**
-	 * \brief Set the default URIResolver.
-	 *
-	 * DSIGSignature objects require a URIResolver to allow them to de-reference
-	 * URIs in reference elements.
-	 *
-	 * This function sets the resolver that will be used for all
-	 * signatures created after this is set.  The resolver is
-	 * cloned, so the object passed in can be safely deleted once the
-	 * function has been completed.
-	 */
+    /**
+     * \brief Set the default URIResolver.
+     *
+     * DSIGSignature objects require a URIResolver to allow them to de-reference
+     * URIs in reference elements.
+     *
+     * This function sets the resolver that will be used for all
+     * signatures created after this is set.  The resolver is
+     * cloned, so the object passed in can be safely deleted once the
+     * function has been completed.
+     */
 
-	void setDefaultURIResolver(XSECURIResolver * resolver);
+    void setDefaultURIResolver(XSECURIResolver* resolver);
 
-	//@}
+    //@}
 
 private:
 
-	// Copy constructor is disabled
-	XSECProvider(const XSECProvider &);
-	XSECProvider * operator = (const XSECProvider &);
-
-	// Internal functions
+    // Copy constructor is disabled
+    XSECProvider(const XSECProvider&);
+    XSECProvider* operator=(const XSECProvider&);
 
-	void setup(DSIGSignature *sig);
-	void setup(XENCCipher *cipher);
+    // Internal functions
 
-	SignatureListVectorType						m_activeSignatures;
-	CipherListVectorType						m_activeCiphers;
+    void setup(DSIGSignature* sig);
+    void setup(XENCCipher* cipher);
 
 #ifdef XSEC_XKMS_ENABLED
-	XKMSMessageFactory							* mp_xkmsMessageFactory;
+    XKMSMessageFactory* mp_xkmsMessageFactory;
 #endif
 
-	XSECURIResolver								* mp_URIResolver;
-	XERCES_CPP_NAMESPACE_QUALIFIER XMLMutex		m_providerMutex;
+    XSECURIResolver* mp_URIResolver;
 };
 
 /** @} */