PrivateKeyFactory.h 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. //
  2. // PrivateKeyFactory.h
  3. //
  4. // Library: NetSSL_OpenSSL
  5. // Package: SSLCore
  6. // Module: PrivateKeyFactory
  7. //
  8. // Definition of the PrivateKeyFactory class.
  9. //
  10. // Copyright (c) 2006-2009, Applied Informatics Software Engineering GmbH.
  11. // and Contributors.
  12. //
  13. // SPDX-License-Identifier: BSL-1.0
  14. //
  15. #ifndef NetSSL_PrivateKeyFactory_INCLUDED
  16. #define NetSSL_PrivateKeyFactory_INCLUDED
  17. #include "Poco/Net/NetSSL.h"
  18. namespace Poco {
  19. namespace Net {
  20. class PrivateKeyPassphraseHandler;
  21. class NetSSL_API PrivateKeyFactory
  22. /// A PrivateKeyFactory is responsible for creating PrivateKeyPassphraseHandlers.
  23. ///
  24. /// You don't need to access this class directly. Use the macro
  25. /// POCO_REGISTER_KEYFACTORY(namespace, PrivateKeyPassphraseHandlerName)
  26. /// instead (see the documentation of PrivateKeyPassphraseHandler for an example).
  27. {
  28. public:
  29. PrivateKeyFactory();
  30. /// Creates the PrivateKeyFactory.
  31. virtual ~PrivateKeyFactory();
  32. /// Destroys the PrivateKeyFactory.
  33. virtual PrivateKeyPassphraseHandler* create(bool onServer) const = 0;
  34. /// Creates a new PrivateKeyPassphraseHandler
  35. };
  36. class NetSSL_API PrivateKeyFactoryRegistrar
  37. /// Registrar class which automatically registers PrivateKeyFactories at the PrivateKeyFactoryMgr.
  38. ///
  39. /// You don't need to access this class directly. Use the macro
  40. /// POCO_REGISTER_KEYFACTORY(namespace, PrivateKeyPassphraseHandlerName)
  41. /// instead (see the documentation of PrivateKeyPassphraseHandler for an example).
  42. {
  43. public:
  44. PrivateKeyFactoryRegistrar(const std::string& name, PrivateKeyFactory* pFactory);
  45. /// Registers the PrivateKeyFactory with the given name at the factory manager.
  46. virtual ~PrivateKeyFactoryRegistrar();
  47. /// Destroys the PrivateKeyFactoryRegistrar.
  48. };
  49. template<typename T>
  50. class PrivateKeyFactoryImpl: public Poco::Net::PrivateKeyFactory
  51. {
  52. public:
  53. PrivateKeyFactoryImpl()
  54. {
  55. }
  56. ~PrivateKeyFactoryImpl()
  57. {
  58. }
  59. PrivateKeyPassphraseHandler* create(bool server) const
  60. {
  61. return new T(server);
  62. }
  63. };
  64. } } // namespace Poco::Net
  65. // DEPRECATED: register the factory directly at the FactoryMgr:
  66. // Poco::Net::SSLManager::instance().privateKeyFactoryMgr().setFactory(name, new Poco::Net::PrivateKeyFactoryImpl<MyKeyHandler>());
  67. #define POCO_REGISTER_KEYFACTORY(API, PKCLS) \
  68. static Poco::Net::PrivateKeyFactoryRegistrar aRegistrar(std::string(#PKCLS), new Poco::Net::PrivateKeyFactoryImpl<PKCLS>());
  69. #endif // NetSSL_PrivateKeyFactory_INCLUDED