/src/poco/Crypto/include/Poco/Crypto/KeyPairImpl.h
Line | Count | Source |
1 | | // |
2 | | // KeyPairImpl.h |
3 | | // |
4 | | // |
5 | | // Library: Crypto |
6 | | // Package: CryptoCore |
7 | | // Module: KeyPairImpl |
8 | | // |
9 | | // Definition of the KeyPairImpl class. |
10 | | // |
11 | | // Copyright (c) 2008, Applied Informatics Software Engineering GmbH. |
12 | | // and Contributors. |
13 | | // |
14 | | // SPDX-License-Identifier: BSL-1.0 |
15 | | // |
16 | | |
17 | | |
18 | | #ifndef Crypto_KeyPairImplImpl_INCLUDED |
19 | | #define Crypto_KeyPairImplImpl_INCLUDED |
20 | | |
21 | | |
22 | | #include "Poco/Crypto/Crypto.h" |
23 | | #include "Poco/Crypto/OpenSSLInitializer.h" |
24 | | #include "Poco/RefCountedObject.h" |
25 | | #include "Poco/AutoPtr.h" |
26 | | #include <string> |
27 | | #include <vector> |
28 | | |
29 | | |
30 | | namespace Poco::Crypto { |
31 | | |
32 | | |
33 | | class Crypto_API KeyPairImpl: public Poco::RefCountedObject |
34 | | /// Class KeyPairImpl |
35 | | { |
36 | | public: |
37 | | enum Type |
38 | | { |
39 | | KT_RSA_IMPL = 0, |
40 | | KT_EC_IMPL |
41 | | }; |
42 | | |
43 | | using Ptr = Poco::AutoPtr<KeyPairImpl>; |
44 | | using ByteVec = std::vector<unsigned char>; |
45 | | |
46 | | KeyPairImpl(const std::string& name, Type type); |
47 | | /// Create KeyPairImpl with specified type and name. |
48 | | |
49 | | virtual ~KeyPairImpl(); |
50 | | /// Destroys the KeyPairImpl. |
51 | | |
52 | | virtual int size() const = 0; |
53 | | /// Returns the key size. |
54 | | |
55 | | virtual void save(const std::string& publicKeyFile, |
56 | | const std::string& privateKeyFile = "", |
57 | | const std::string& privateKeyPassphrase = "") const = 0; |
58 | | /// Exports the public and private keys to the given files. |
59 | | /// |
60 | | /// If an empty filename is specified, the corresponding key |
61 | | /// is not exported. |
62 | | |
63 | | virtual void save(std::ostream* pPublicKeyStream, |
64 | | std::ostream* pPrivateKeyStream = nullptr, |
65 | | const std::string& privateKeyPassphrase = "") const = 0; |
66 | | /// Exports the public and private key to the given streams. |
67 | | /// |
68 | | /// If a null pointer is passed for a stream, the corresponding |
69 | | /// key is not exported. |
70 | | |
71 | | const std::string& name() const; |
72 | | /// Returns key pair name |
73 | | |
74 | | Type type() const; |
75 | | /// Returns key pair type |
76 | | |
77 | | private: |
78 | | KeyPairImpl(); |
79 | | |
80 | | std::string _name; |
81 | | Type _type; |
82 | | OpenSSLInitializer _openSSLInitializer; |
83 | | }; |
84 | | |
85 | | |
86 | | // |
87 | | // inlines |
88 | | // |
89 | | |
90 | | |
91 | | inline const std::string& KeyPairImpl::name() const |
92 | 0 | { |
93 | 0 | return _name; |
94 | 0 | } |
95 | | |
96 | | |
97 | | inline KeyPairImpl::Type KeyPairImpl::type() const |
98 | 0 | { |
99 | 0 | return _type; |
100 | 0 | } |
101 | | |
102 | | |
103 | | } // namespace Poco::Crypto |
104 | | |
105 | | |
106 | | #endif // Crypto_KeyPairImplImpl_INCLUDED |