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 | |
16 | |
17 | #ifndef NetSSL_PrivateKeyFactory_INCLUDED |
18 | #define NetSSL_PrivateKeyFactory_INCLUDED |
19 | |
20 | |
21 | #include "Poco/Net/NetSSL.h" |
22 | |
23 | |
24 | namespace Poco { |
25 | namespace Net { |
26 | |
27 | |
28 | class PrivateKeyPassphraseHandler; |
29 | |
30 | |
31 | class NetSSL_API PrivateKeyFactory |
32 | /// A PrivateKeyFactory is responsible for creating PrivateKeyPassphraseHandlers. |
33 | /// |
34 | /// You don't need to access this class directly. Use the macro |
35 | /// POCO_REGISTER_KEYFACTORY(namespace, PrivateKeyPassphraseHandlerName) |
36 | /// instead (see the documentation of PrivateKeyPassphraseHandler for an example). |
37 | { |
38 | public: |
39 | PrivateKeyFactory(); |
40 | /// Creates the PrivateKeyFactory. |
41 | |
42 | virtual ~PrivateKeyFactory(); |
43 | /// Destroys the PrivateKeyFactory. |
44 | |
45 | virtual PrivateKeyPassphraseHandler* create(bool onServer) const = 0; |
46 | /// Creates a new PrivateKeyPassphraseHandler |
47 | }; |
48 | |
49 | |
50 | class NetSSL_API PrivateKeyFactoryRegistrar |
51 | /// Registrar class which automatically registers PrivateKeyFactories at the PrivateKeyFactoryMgr. |
52 | /// |
53 | /// You don't need to access this class directly. Use the macro |
54 | /// POCO_REGISTER_KEYFACTORY(namespace, PrivateKeyPassphraseHandlerName) |
55 | /// instead (see the documentation of PrivateKeyPassphraseHandler for an example). |
56 | |
57 | { |
58 | public: |
59 | PrivateKeyFactoryRegistrar(const std::string& name, PrivateKeyFactory* pFactory); |
60 | /// Registers the PrivateKeyFactory with the given name at the factory manager. |
61 | |
62 | virtual ~PrivateKeyFactoryRegistrar(); |
63 | /// Destroys the PrivateKeyFactoryRegistrar. |
64 | }; |
65 | |
66 | |
67 | template<typename T> |
68 | class PrivateKeyFactoryImpl: public Poco::Net::PrivateKeyFactory |
69 | { |
70 | public: |
71 | PrivateKeyFactoryImpl() |
72 | { |
73 | } |
74 | |
75 | ~PrivateKeyFactoryImpl() |
76 | { |
77 | } |
78 | |
79 | PrivateKeyPassphraseHandler* create(bool server) const |
80 | { |
81 | return new T(server); |
82 | } |
83 | }; |
84 | |
85 | |
86 | } } // namespace Poco::Net |
87 | |
88 | |
89 | // DEPRECATED: register the factory directly at the FactoryMgr: |
90 | // Poco::Net::SSLManager::instance().privateKeyFactoryMgr().setFactory(name, new Poco::Net::PrivateKeyFactoryImpl<MyKeyHandler>()); |
91 | #define POCO_REGISTER_KEYFACTORY(API, PKCLS) \ |
92 | static Poco::Net::PrivateKeyFactoryRegistrar aRegistrar(std::string(#PKCLS), new Poco::Net::PrivateKeyFactoryImpl<PKCLS>()); |
93 | |
94 | |
95 | #endif // NetSSL_PrivateKeyFactory_INCLUDED |
96 | |