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 { 31 namespace Crypto { 32 33 34 class KeyPairImpl: public Poco::RefCountedObject 35 /// Class KeyPairImpl 36 { 37 public: 38 enum Type 39 { 40 KT_RSA_IMPL = 0, 41 KT_EC_IMPL 42 }; 43 44 using Ptr = Poco::AutoPtr<KeyPairImpl>; 45 using ByteVec = std::vector<unsigned char>; 46 47 KeyPairImpl(const std::string& name, Type type); 48 /// Create KeyPairImpl with specified type and name. 49 50 virtual ~KeyPairImpl(); 51 /// Destroys the KeyPairImpl. 52 53 virtual int size() const = 0; 54 /// Returns the key size. 55 56 virtual void save(const std::string& publicKeyFile, 57 const std::string& privateKeyFile = "", 58 const std::string& privateKeyPassphrase = "") const = 0; 59 /// Exports the public and private keys to the given files. 60 /// 61 /// If an empty filename is specified, the corresponding key 62 /// is not exported. 63 64 virtual void save(std::ostream* pPublicKeyStream, 65 std::ostream* pPrivateKeyStream = 0, 66 const std::string& privateKeyPassphrase = "") const = 0; 67 /// Exports the public and private key to the given streams. 68 /// 69 /// If a null pointer is passed for a stream, the corresponding 70 /// key is not exported. 71 72 const std::string& name() const; 73 /// Returns key pair name 74 75 Type type() const; 76 /// Returns key pair type 77 78 private: 79 KeyPairImpl(); 80 81 std::string _name; 82 Type _type; 83 OpenSSLInitializer _openSSLInitializer; 84 }; 85 86 87 // 88 // inlines 89 // 90 91 name()92inline const std::string& KeyPairImpl::name() const 93 { 94 return _name; 95 } 96 97 type()98inline KeyPairImpl::Type KeyPairImpl::type() const 99 { 100 return _type; 101 } 102 103 104 } } // namespace Poco::Crypto 105 106 107 #endif // Crypto_KeyPairImplImpl_INCLUDED 108