cleanup and modernization

This commit is contained in:
Günter Obiltschnig 2020-01-10 12:20:30 +01:00
parent 3a1f246ecc
commit e1f09a602b
20 changed files with 145 additions and 73 deletions

View File

@ -84,8 +84,8 @@ class Crypto_API Cipher: public Poco::RefCountedObject
/// sink.close();
{
public:
typedef Poco::AutoPtr<Cipher> Ptr;
typedef std::vector<unsigned char> ByteVec;
using Ptr = Poco::AutoPtr<Cipher>;
using ByteVec = std::vector<unsigned char>;
enum Encoding
/// Transport encoding to use for encryptString() and decryptString().

View File

@ -57,8 +57,8 @@ class Crypto_API CipherKey
///
{
public:
typedef CipherKeyImpl::Mode Mode;
typedef CipherKeyImpl::ByteVec ByteVec;
using Mode = CipherKeyImpl::Mode;
using ByteVec = CipherKeyImpl::ByteVec;
enum
{

View File

@ -37,8 +37,8 @@ class CipherKeyImpl: public RefCountedObject
/// An implementation of the CipherKey class for OpenSSL's crypto library.
{
public:
typedef std::vector<unsigned char> ByteVec;
typedef Poco::AutoPtr<CipherKeyImpl> Ptr;
using Ptr = Poco::AutoPtr<CipherKeyImpl>;
using ByteVec = std::vector<unsigned char>;
enum Mode
/// Cipher mode of operation. This mode determines how multiple blocks

View File

@ -38,10 +38,10 @@ public:
OpenSSLException(const std::string& msg, const std::string& arg, int code = 0);
OpenSSLException(const std::string& msg, const Poco::Exception& exc, int code = 0);
OpenSSLException(const OpenSSLException& exc);
~OpenSSLException() throw();
~OpenSSLException() noexcept;
OpenSSLException& operator = (const OpenSSLException& exc);
const char* name() const throw();
const char* className() const throw();
const char* name() const noexcept;
const char* className() const noexcept;
Poco::Exception* clone() const;
void rethrow() const;

View File

@ -99,7 +99,7 @@ class Crypto_API ECDSASignature
/// A helper class for dealing with ECDSA signatures.
{
public:
typedef std::vector<unsigned char> ByteVec;
using ByteVec = std::vector<unsigned char>;
explicit ECDSASignature(const ByteVec& derSignature);
/// Creates the ECDSASignature from a DER-encoded signature.

View File

@ -44,8 +44,8 @@ class ECKeyImpl: public KeyPairImpl
/// Elliptic Curve key clas implementation.
{
public:
typedef Poco::AutoPtr<ECKeyImpl> Ptr;
typedef std::vector<unsigned char> ByteVec;
using Ptr = Poco::AutoPtr<ECKeyImpl>;
using ByteVec = std::vector<unsigned char>;
ECKeyImpl(const EVPPKey& key);
/// Constructs ECKeyImpl by extracting the EC key.

View File

@ -81,18 +81,14 @@ public:
EVPPKey(const EVPPKey& other);
/// Copy constructor.
EVPPKey& operator=(const EVPPKey& other);
/// Assignment operator.
#ifdef POCO_ENABLE_CPP11
EVPPKey(EVPPKey&& other);
EVPPKey(EVPPKey&& other) noexcept;
/// Move constructor.
EVPPKey& operator=(EVPPKey&& other);
/// Assignment move operator.
EVPPKey& operator = (const EVPPKey& other);
/// Assignment operator.
#endif // POCO_ENABLE_CPP11
EVPPKey& operator = (EVPPKey&& other) noexcept;
/// Assignment move operator.
~EVPPKey();
/// Destroys the EVPPKey.

View File

@ -41,8 +41,8 @@ public:
KT_EC_IMPL
};
typedef Poco::AutoPtr<KeyPairImpl> Ptr;
typedef std::vector<unsigned char> ByteVec;
using Ptr = Poco::AutoPtr<KeyPairImpl>;
using ByteVec = std::vector<unsigned char>;
KeyPairImpl(const std::string& name, Type type);
/// Create KeyPairImpl with specified type and name.

View File

@ -36,8 +36,8 @@ class Crypto_API PKCS12Container
/// This class implements PKCS#12 container functionality.
{
public:
typedef X509Certificate::List CAList;
typedef std::vector<std::string> CANameList;
using CAList = X509Certificate::List;
using CANameList = std::vector<std::string>;
explicit PKCS12Container(std::istream& istr, const std::string& password = "");
/// Creates the PKCS12Container object from a stream.
@ -48,19 +48,15 @@ public:
PKCS12Container(const PKCS12Container& cont);
/// Copy constructor.
PKCS12Container(PKCS12Container&& cont) noexcept;
/// Move constructor.
PKCS12Container& operator = (const PKCS12Container& cont);
/// Assignment operator.
#ifdef POCO_ENABLE_CPP11
PKCS12Container(PKCS12Container&& cont);
/// Move constructor.
PKCS12Container& operator = (PKCS12Container&& cont);
PKCS12Container& operator = (PKCS12Container&& cont) noexcept;
/// Move assignment operator.
#endif // POCO_ENABLE_CPP11
~PKCS12Container();
/// Destroys the PKCS12Container.
@ -90,7 +86,7 @@ private:
void load(PKCS12* pPKCS12, const std::string& password = "");
std::string extractFriendlyName(X509* pCert);
typedef std::unique_ptr<X509Certificate> CertPtr;
using CertPtr = std::unique_ptr<X509Certificate>;
OpenSSLInitializer _openSSLInitializer;
EVP_PKEY* _pKey;

View File

@ -47,8 +47,8 @@ class RSAKeyImpl: public KeyPairImpl
/// class RSAKeyImpl
{
public:
typedef Poco::AutoPtr<RSAKeyImpl> Ptr;
typedef std::vector<unsigned char> ByteVec;
using Ptr = Poco::AutoPtr<RSAKeyImpl>;
using ByteVec = std::vector<unsigned char>;
RSAKeyImpl(const EVPPKey& key);
/// Constructs ECKeyImpl by extracting the EC key.

View File

@ -36,7 +36,7 @@ class Crypto_API X509Certificate
/// This class represents a X509 Certificate.
{
public:
typedef std::vector<X509Certificate> List;
using List = std::vector<X509Certificate>;
enum NID
/// Name identifier for extracting information from
@ -74,9 +74,15 @@ public:
X509Certificate(const X509Certificate& cert);
/// Creates the certificate by copying another one.
X509Certificate(X509Certificate&& cert) noexcept;
/// Creates the certificate by moving another one.
X509Certificate& operator = (const X509Certificate& cert);
/// Assigns a certificate.
X509Certificate& operator = (X509Certificate&& cert) noexcept;
/// Move assignment.
void swap(X509Certificate& cert);
/// Exchanges the certificate with another one.

View File

@ -44,7 +44,7 @@ namespace
class CryptoTransformImpl: public CryptoTransform
{
public:
typedef Cipher::ByteVec ByteVec;
using ByteVec = Cipher::ByteVec;
enum Direction
{

View File

@ -56,7 +56,7 @@ OpenSSLException::OpenSSLException(const OpenSSLException& exc): CryptoException
}
OpenSSLException::~OpenSSLException() throw()
OpenSSLException::~OpenSSLException() noexcept
{
}
@ -68,13 +68,13 @@ OpenSSLException& OpenSSLException::operator = (const OpenSSLException& exc)
}
const char* OpenSSLException::name() const throw()
const char* OpenSSLException::name() const noexcept
{
return "OpenSSLException";
}
const char* OpenSSLException::className() const throw()
const char* OpenSSLException::className() const noexcept
{
return typeid(*this).name();
}

View File

@ -89,7 +89,15 @@ EVPPKey::EVPPKey(const EVPPKey& other)
}
EVPPKey& EVPPKey::operator=(const EVPPKey& other)
EVPPKey::EVPPKey(EVPPKey&& other) noexcept:
_pEVPPKey(other._pEVPPKey)
{
other._pEVPPKey = nullptr;
poco_check_ptr(_pEVPPKey);
}
EVPPKey& EVPPKey::operator = (const EVPPKey& other)
{
duplicate(other._pEVPPKey, &_pEVPPKey);
poco_check_ptr(_pEVPPKey);
@ -97,16 +105,7 @@ EVPPKey& EVPPKey::operator=(const EVPPKey& other)
}
#ifdef POCO_ENABLE_CPP11
EVPPKey::EVPPKey(EVPPKey&& other): _pEVPPKey(other._pEVPPKey)
{
other._pEVPPKey = nullptr;
poco_check_ptr(_pEVPPKey);
}
EVPPKey& EVPPKey::operator=(EVPPKey&& other)
EVPPKey& EVPPKey::operator = (EVPPKey&& other) noexcept
{
_pEVPPKey = other._pEVPPKey;
other._pEVPPKey = nullptr;
@ -114,7 +113,6 @@ EVPPKey& EVPPKey::operator=(EVPPKey&& other)
return *this;
}
#endif // POCO_ENABLE_CPP11
EVPPKey::~EVPPKey()
{

View File

@ -88,38 +88,30 @@ PKCS12Container& PKCS12Container::operator = (const PKCS12Container& other)
}
#ifdef POCO_ENABLE_CPP11
PKCS12Container::PKCS12Container(PKCS12Container&& other):
PKCS12Container::PKCS12Container(PKCS12Container&& other) noexcept:
_pKey(other._pKey),
_pX509Cert(std::move(other._pX509Cert)),
_caCertList(std::move(other._caCertList)),
_caCertNames(std::move(other._caCertNames)),
_pkcsFriendlyName(std::move(other._pkcsFriendlyName))
{
other._pKey = 0;
other._pKey = nullptr;
}
PKCS12Container& PKCS12Container::operator = (PKCS12Container&& other)
PKCS12Container& PKCS12Container::operator = (PKCS12Container&& other) noexcept
{
if (&other != this)
{
if (_pKey) EVP_PKEY_free(_pKey);
_pKey = other._pKey; other._pKey = 0;
_pX509Cert = std::move(other._pX509Cert);
_caCertList = std::move(other._caCertList);
_caCertNames = std::move(other._caCertNames);
_pkcsFriendlyName = std::move(other._pkcsFriendlyName);
}
if (_pKey) EVP_PKEY_free(_pKey);
_pKey = other._pKey; other._pKey = nullptr;
_pX509Cert = std::move(other._pX509Cert);
_caCertList = std::move(other._caCertList);
_caCertNames = std::move(other._caCertNames);
_pkcsFriendlyName = std::move(other._pkcsFriendlyName);
return *this;
}
#endif // POCO_ENABLE_CPP11
PKCS12Container::~PKCS12Container()
{
if (_pKey) EVP_PKEY_free(_pKey);

View File

@ -90,6 +90,16 @@ X509Certificate::X509Certificate(const X509Certificate& cert):
}
X509Certificate::X509Certificate(X509Certificate&& cert) noexcept:
_issuerName(std::move(cert._issuerName)),
_subjectName(std::move(cert._subjectName)),
_serialNumber(std::move(cert._serialNumber)),
_pCert(cert._pCert)
{
cert._pCert = nullptr;
}
X509Certificate& X509Certificate::operator = (const X509Certificate& cert)
{
X509Certificate tmp(cert);
@ -98,6 +108,16 @@ X509Certificate& X509Certificate::operator = (const X509Certificate& cert)
}
X509Certificate& X509Certificate::operator = (X509Certificate&& cert) noexcept
{
_issuerName = std::move(cert._issuerName);
_subjectName = std::move(cert._subjectName);
_serialNumber = std::move(cert._serialNumber);
_pCert = cert._pCert; cert._pCert = nullptr;
return *this;
}
void X509Certificate::swap(X509Certificate& cert)
{
using std::swap;
@ -110,7 +130,7 @@ void X509Certificate::swap(X509Certificate& cert)
X509Certificate::~X509Certificate()
{
X509_free(_pCert);
if (_pCert) X509_free(_pCert);
}

View File

@ -60,9 +60,21 @@ public:
X509Certificate(const Poco::Crypto::X509Certificate& cert);
/// Creates the certificate by copying another one.
X509Certificate(const X509Certificate& cert);
/// Creates the certificate by copying another one.
X509Certificate(X509Certificate&& cert) noexcept;
/// Creates the certificate by moving another one.
X509Certificate& operator = (const Poco::Crypto::X509Certificate& cert);
/// Assigns a certificate.
X509Certificate& operator = (const X509Certificate& cert);
/// Assigns a certificate.
X509Certificate& operator = (X509Certificate&& cert) noexcept;
/// Moves a certificate.
~X509Certificate();
/// Destroys the X509Certificate.

View File

@ -61,6 +61,18 @@ X509Certificate::X509Certificate(const Poco::Crypto::X509Certificate& cert):
}
X509Certificate::X509Certificate(const X509Certificate& cert):
Poco::Crypto::X509Certificate(cert)
{
}
X509Certificate::X509Certificate(X509Certificate&& cert) noexcept:
Poco::Crypto::X509Certificate(std::move(cert))
{
}
X509Certificate& X509Certificate::operator = (const Poco::Crypto::X509Certificate& cert)
{
X509Certificate tmp(cert);
@ -69,6 +81,21 @@ X509Certificate& X509Certificate::operator = (const Poco::Crypto::X509Certificat
}
X509Certificate& X509Certificate::operator = (const X509Certificate& cert)
{
X509Certificate tmp(cert);
swap(tmp);
return *this;
}
X509Certificate& X509Certificate::operator = (X509Certificate&& cert) noexcept
{
Poco::Crypto::X509Certificate::operator = (cert);
return *this;
}
X509Certificate::~X509Certificate()
{
}

View File

@ -76,8 +76,14 @@ public:
X509Certificate(const X509Certificate& cert);
/// Creates the certificate by copying another one.
X509Certificate(X509Certificate&& cert) noexcept;
/// Creates the certificate by moving another one.
X509Certificate& operator = (const X509Certificate& cert);
/// Assigns a certificate.
X509Certificate& operator = (X509Certificate&& cert) noexcept;
/// Move-assigns a certificate.
void swap(X509Certificate& cert);
/// Exchanges the certificate with another one.

View File

@ -75,6 +75,15 @@ X509Certificate::X509Certificate(const X509Certificate& cert):
}
X509Certificate::X509Certificate(X509Certificate&& cert) noexcept:
_issuerName(std::move(cert._issuerName)),
_subjectName(std::move(cert._subjectName)),
_pCert(cert._pCert)
{
cert._pCert = nullptr;
}
X509Certificate::X509Certificate(PCCERT_CONTEXT pCert, bool shared):
_pCert(pCert)
{
@ -97,6 +106,16 @@ X509Certificate& X509Certificate::operator = (const X509Certificate& cert)
}
X509Certificate& X509Certificate::operator = (X509Certificate&& cert) noexcept
{
_issuerName = std::move(cert._issuerName);
_subjectName = std::move(cert._subjectName);
_pCert = cert._pCert; cert._pCert = nullptr;
return *this;
}
void X509Certificate::swap(X509Certificate& cert)
{
using std::swap;
@ -108,7 +127,7 @@ void X509Certificate::swap(X509Certificate& cert)
X509Certificate::~X509Certificate()
{
CertFreeCertificateContext(_pCert);
if (_pCert) CertFreeCertificateContext(_pCert);
}