blautenb    2003/09/15 04:51:20

  Modified:    c/src/utils XSECPlatformUtils.hpp XSECPlatformUtils.cpp
  Log:
  Implementation and initialisation of AlgorithmMapper
  
  Revision  Changes    Path
  1.9       +51 -1     xml-security/c/src/utils/XSECPlatformUtils.hpp
  
  Index: XSECPlatformUtils.hpp
  ===================================================================
  RCS file: /home/cvs/xml-security/c/src/utils/XSECPlatformUtils.hpp,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- XSECPlatformUtils.hpp     5 Jul 2003 10:30:37 -0000       1.8
  +++ XSECPlatformUtils.hpp     15 Sep 2003 11:51:20 -0000      1.9
  @@ -76,6 +76,9 @@
   #include <xsec/framework/XSECDefs.hpp>
   #include <xsec/enc/XSECCryptoProvider.hpp>
   
  +class XSECAlgorithmMapper;
  +class XSECAlgorithmHandler;
  +
   #include <stdio.h>
   
   /**
  @@ -114,6 +117,32 @@
   
        static XSECCryptoProvider * g_cryptoProvider;
   
  +     /**
  +      * \brief The global Algorithm Mapper
  +      *
  +      * The algorithm mapper is used to map algorithm type URI strings
  +      * to algorithm implementations.  Note that this is a level of
  +      * indirection above actual cryptographic algorithms.  For example:
  +      *
  +      * URI = http://www.w3.org/2001/04/xmlenc#tripledes-cbc
  +      *
  +      * is the URI for 3DES in CBC mode.  The mapper will return an
  +      * algorithm handler that understands what this means in terms of
  +      * IVs and how to call the XSECCryptoKey interface.  It then uses the
  +      * cryptographic provider to actually perform the encryption.
  +      *
  +      * This allows applications to provide new algorithm types.  The
  +      * mapper is used to map the type string to the means of doing the
  +      * encryption, and a new XSECCryptoKey derivative can be provided
  +      * to perform the actual crypo work.
  +      *
  +      * @note The provider should only be added to via the
  +      * XSECPlatformUtils::addAlgorithmHandler() call.
  +      *
  +      * @see #addAlgorithmHandler()
  +      */
  +
  +     static const XSECAlgorithmMapper * g_algorithmMapper;
   
        /**
         * \brief Initialise the library
  @@ -146,6 +175,27 @@
         */
   
        static void SetCryptoProvider(XSECCryptoProvider * p);
  +
  +     /**
  +      * \brief Add a new algorithm Handler
  +      *
  +      * Application developers can extend the XSECAlgorithmHandler class to
  +      * implement new cryptographic algorithms.  This will then allow the
  +      * library to call the provided handler whenever trying to process a
  +      * type it doesn't understand.
  +      *
  +      * Any handler previously registered for this URI will be overwritten,
  +      * allowing callers to overwrite the handlers for default URIs.
  +      *
  +      * @see XSECAlgorithmHandler
  +      * @note This is <b>not</b> thread safe.  Algorithm handlers should
  +      * be added prior to any processing of signatures etc.
  +      * @param uri Type URI that maps to this handler
  +      * @param handler The handler to be used whenever this URI is seen by
  +      * the library.
  +      */
  +
  +     static void registerAlgorithmHandler(const XMLCh * uri, const 
XSECAlgorithmHandler & handler);
   
        /**
         * \brief Terminate
  
  
  
  1.8       +28 -1     xml-security/c/src/utils/XSECPlatformUtils.cpp
  
  Index: XSECPlatformUtils.cpp
  ===================================================================
  RCS file: /home/cvs/xml-security/c/src/utils/XSECPlatformUtils.cpp,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- XSECPlatformUtils.cpp     5 Jul 2003 10:30:37 -0000       1.7
  +++ XSECPlatformUtils.cpp     15 Sep 2003 11:51:20 -0000      1.8
  @@ -73,6 +73,9 @@
   #include <xsec/utils/XSECPlatformUtils.hpp>
   #include <xsec/framework/XSECError.hpp>
   #include <xsec/dsig/DSIGConstants.hpp>
  +#include <xsec/framework/XSECAlgorithmMapper.hpp>
  +
  +#include "../xenc/impl/XENCCipherImpl.hpp"
   
   #if defined(_WIN32)
   #include <xsec/utils/winutils/XSECBinHTTPURIInputStream.hpp>
  @@ -90,6 +93,11 @@
   int XSECPlatformUtils::initCount = 0;
   XSECCryptoProvider * XSECPlatformUtils::g_cryptoProvider = NULL;
   
  +// Have a const copy for external usage
  +const XSECAlgorithmMapper * XSECPlatformUtils::g_algorithmMapper = NULL;
  +
  +XSECAlgorithmMapper * internalMapper = NULL;
  +
   // Determine default crypto provider
   
   #if defined (HAVE_OPENSSL)
  @@ -121,6 +129,13 @@
        // Initialise the safeBuffer system
        safeBuffer::init();
   
  +     // Initialise Algorithm Mapper
  +     XSECnew(internalMapper, XSECAlgorithmMapper);
  +     g_algorithmMapper = internalMapper;
  +
  +     // Initialise the XENCCipherImpl class
  +     XENCCipherImpl::Initialise();
  +
   };
   
   void XSECPlatformUtils::SetCryptoProvider(XSECCryptoProvider * p) {
  @@ -138,6 +153,9 @@
        if (--initCount > 0)
                return;
   
  +     // Clean out the algorithm mapper
  +     delete internalMapper;
  +
        if (g_cryptoProvider != NULL)
                delete g_cryptoProvider;
   
  @@ -149,3 +167,12 @@
   #endif
   
   }
  +
  +void XSECPlatformUtils::registerAlgorithmHandler(
  +             const XMLCh * uri, 
  +             const XSECAlgorithmHandler & handler) {
  +
  +     internalMapper->registerHandler(uri, handler);
  +
  +}
  +
  
  
  

Reply via email to