mirror of
https://github.com/pocoproject/poco.git
synced 2025-10-27 19:10:20 +01:00
add capability to construct EVPPKey from ECKey and RSAKey; RSA EVPPKey tests, RSA KeyPairImpl type bugfix
This commit is contained in:
@@ -31,7 +31,7 @@ namespace Crypto {
|
||||
POCO_DECLARE_EXCEPTION(Crypto_API, CryptoException, Poco::Exception)
|
||||
|
||||
|
||||
class OpenSSLException : public CryptoException
|
||||
class Crypto_API OpenSSLException : public CryptoException
|
||||
{
|
||||
public:
|
||||
OpenSSLException(int code = 0);
|
||||
|
||||
@@ -30,6 +30,10 @@ namespace Poco {
|
||||
namespace Crypto {
|
||||
|
||||
|
||||
class ECKey;
|
||||
class RSAKey;
|
||||
|
||||
|
||||
class Crypto_API EVPPKey
|
||||
/// Utility class for conversion of native keys to EVP.
|
||||
/// Currently, only RSA and EC keys are supported.
|
||||
@@ -79,11 +83,14 @@ public:
|
||||
int type() const;
|
||||
/// Retuns the EVPPKey type NID.
|
||||
|
||||
bool isSupported(int type) const;
|
||||
/// Returns true if OpenSSL type is supported
|
||||
|
||||
operator const EVP_PKEY*() const;
|
||||
/// Returns const pointer to the EVP_PKEY structure.
|
||||
/// Returns const pointer to the OpenSSL EVP_PKEY structure.
|
||||
|
||||
operator EVP_PKEY*();
|
||||
/// Returns pointer to the EVP_PKEY structure.
|
||||
/// Returns pointer to the OpenSSL EVP_PKEY structure.
|
||||
|
||||
private:
|
||||
EVPPKey();
|
||||
@@ -91,6 +98,9 @@ private:
|
||||
void newECKey(const char* group);
|
||||
|
||||
void duplicate(EVP_PKEY* pEVPPKey);
|
||||
|
||||
void setKey(ECKey* pKey);
|
||||
void setKey(RSAKey* pKey);
|
||||
void setKey(EC_KEY* pKey);
|
||||
void setKey(RSA* pKey);
|
||||
|
||||
@@ -109,15 +119,19 @@ inline int EVPPKey::type() const
|
||||
}
|
||||
|
||||
|
||||
inline bool EVPPKey::isSupported(int type) const
|
||||
{
|
||||
return type == EVP_PKEY_EC || type == EVP_PKEY_RSA;
|
||||
}
|
||||
|
||||
|
||||
inline EVPPKey::operator const EVP_PKEY*() const
|
||||
/// Returns const pointer to the EVP_PKEY structure.
|
||||
{
|
||||
return _pEVPPKey;
|
||||
}
|
||||
|
||||
|
||||
inline EVPPKey::operator EVP_PKEY*()
|
||||
/// Returns pointer to the EVP_PKEY structure.
|
||||
{
|
||||
return _pEVPPKey;
|
||||
}
|
||||
|
||||
@@ -76,7 +76,7 @@ public:
|
||||
/// Returns key pair type
|
||||
|
||||
private:
|
||||
KeyPairImpl::Ptr _pImpl;
|
||||
KeyPairImpl::Ptr _pImpl;
|
||||
};
|
||||
|
||||
|
||||
@@ -113,6 +113,12 @@ inline KeyPairImpl::Ptr KeyPair::impl() const
|
||||
}
|
||||
|
||||
|
||||
inline KeyPair::Type KeyPair::type() const
|
||||
{
|
||||
return (KeyPair::Type)impl()->type();
|
||||
}
|
||||
|
||||
|
||||
} } // namespace Poco::Crypto
|
||||
|
||||
|
||||
|
||||
@@ -50,8 +50,6 @@ public:
|
||||
typedef Poco::AutoPtr<RSAKeyImpl> Ptr;
|
||||
typedef std::vector<unsigned char> ByteVec;
|
||||
|
||||
RSAKeyImpl() = delete;
|
||||
|
||||
RSAKeyImpl(const EVPPKey& key);
|
||||
/// Constructs ECKeyImpl by extracting the EC key.
|
||||
|
||||
@@ -109,6 +107,8 @@ public:
|
||||
/// key is not exported.
|
||||
|
||||
private:
|
||||
RSAKeyImpl();
|
||||
|
||||
void freeRSA();
|
||||
static ByteVec convertToByteVec(const BIGNUM* bn);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user