diff --git a/Crypto/include/Poco/Crypto/Cipher.h b/Crypto/include/Poco/Crypto/Cipher.h index fbe0c30ae..67625d7fd 100644 --- a/Crypto/include/Poco/Crypto/Cipher.h +++ b/Crypto/include/Poco/Crypto/Cipher.h @@ -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(). diff --git a/Crypto/include/Poco/Crypto/CipherKey.h b/Crypto/include/Poco/Crypto/CipherKey.h index b102cc231..02042ec88 100644 --- a/Crypto/include/Poco/Crypto/CipherKey.h +++ b/Crypto/include/Poco/Crypto/CipherKey.h @@ -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 { diff --git a/Crypto/include/Poco/Crypto/CipherKeyImpl.h b/Crypto/include/Poco/Crypto/CipherKeyImpl.h index f7807aad9..75b3bdadb 100644 --- a/Crypto/include/Poco/Crypto/CipherKeyImpl.h +++ b/Crypto/include/Poco/Crypto/CipherKeyImpl.h @@ -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 diff --git a/Crypto/include/Poco/Crypto/CryptoException.h b/Crypto/include/Poco/Crypto/CryptoException.h index 34c15111e..8bd5b011c 100644 --- a/Crypto/include/Poco/Crypto/CryptoException.h +++ b/Crypto/include/Poco/Crypto/CryptoException.h @@ -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; diff --git a/Crypto/include/Poco/Crypto/ECDSADigestEngine.h b/Crypto/include/Poco/Crypto/ECDSADigestEngine.h index d8021619e..a3d8156fe 100644 --- a/Crypto/include/Poco/Crypto/ECDSADigestEngine.h +++ b/Crypto/include/Poco/Crypto/ECDSADigestEngine.h @@ -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. diff --git a/Crypto/include/Poco/Crypto/ECKeyImpl.h b/Crypto/include/Poco/Crypto/ECKeyImpl.h index 840764304..1795e9584 100644 --- a/Crypto/include/Poco/Crypto/ECKeyImpl.h +++ b/Crypto/include/Poco/Crypto/ECKeyImpl.h @@ -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. diff --git a/Crypto/include/Poco/Crypto/EVPPKey.h b/Crypto/include/Poco/Crypto/EVPPKey.h index fbcdad5b1..7e096ff49 100644 --- a/Crypto/include/Poco/Crypto/EVPPKey.h +++ b/Crypto/include/Poco/Crypto/EVPPKey.h @@ -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. diff --git a/Crypto/include/Poco/Crypto/KeyPairImpl.h b/Crypto/include/Poco/Crypto/KeyPairImpl.h index e6320df04..6999a46d8 100644 --- a/Crypto/include/Poco/Crypto/KeyPairImpl.h +++ b/Crypto/include/Poco/Crypto/KeyPairImpl.h @@ -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. diff --git a/Crypto/include/Poco/Crypto/PKCS12Container.h b/Crypto/include/Poco/Crypto/PKCS12Container.h index 7bb614488..9fbef7fdb 100644 --- a/Crypto/include/Poco/Crypto/PKCS12Container.h +++ b/Crypto/include/Poco/Crypto/PKCS12Container.h @@ -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; diff --git a/Crypto/include/Poco/Crypto/RSAKeyImpl.h b/Crypto/include/Poco/Crypto/RSAKeyImpl.h index 035881636..f89c3bf22 100644 --- a/Crypto/include/Poco/Crypto/RSAKeyImpl.h +++ b/Crypto/include/Poco/Crypto/RSAKeyImpl.h @@ -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. diff --git a/Crypto/include/Poco/Crypto/X509Certificate.h b/Crypto/include/Poco/Crypto/X509Certificate.h index ccdab1ce3..dbf32f3c5 100644 --- a/Crypto/include/Poco/Crypto/X509Certificate.h +++ b/Crypto/include/Poco/Crypto/X509Certificate.h @@ -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. diff --git a/Crypto/src/CipherImpl.cpp b/Crypto/src/CipherImpl.cpp index 47d975c0c..0bc2e7471 100644 --- a/Crypto/src/CipherImpl.cpp +++ b/Crypto/src/CipherImpl.cpp @@ -44,7 +44,7 @@ namespace class CryptoTransformImpl: public CryptoTransform { public: - typedef Cipher::ByteVec ByteVec; + using ByteVec = Cipher::ByteVec; enum Direction { diff --git a/Crypto/src/CryptoException.cpp b/Crypto/src/CryptoException.cpp index a4450af9b..e30940d22 100644 --- a/Crypto/src/CryptoException.cpp +++ b/Crypto/src/CryptoException.cpp @@ -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(); } diff --git a/Crypto/src/EVPPKey.cpp b/Crypto/src/EVPPKey.cpp index ffa0a78c0..d6d9e1072 100644 --- a/Crypto/src/EVPPKey.cpp +++ b/Crypto/src/EVPPKey.cpp @@ -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() { diff --git a/Crypto/src/PKCS12Container.cpp b/Crypto/src/PKCS12Container.cpp index 5c03a9ff8..a99e7dfaf 100644 --- a/Crypto/src/PKCS12Container.cpp +++ b/Crypto/src/PKCS12Container.cpp @@ -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); diff --git a/Crypto/src/X509Certificate.cpp b/Crypto/src/X509Certificate.cpp index 4af1aa9ac..43e8469d4 100644 --- a/Crypto/src/X509Certificate.cpp +++ b/Crypto/src/X509Certificate.cpp @@ -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); } diff --git a/NetSSL_OpenSSL/include/Poco/Net/X509Certificate.h b/NetSSL_OpenSSL/include/Poco/Net/X509Certificate.h index a810b2945..741ba0ef9 100644 --- a/NetSSL_OpenSSL/include/Poco/Net/X509Certificate.h +++ b/NetSSL_OpenSSL/include/Poco/Net/X509Certificate.h @@ -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. diff --git a/NetSSL_OpenSSL/src/X509Certificate.cpp b/NetSSL_OpenSSL/src/X509Certificate.cpp index 54651c3ac..f6d3ba4c1 100644 --- a/NetSSL_OpenSSL/src/X509Certificate.cpp +++ b/NetSSL_OpenSSL/src/X509Certificate.cpp @@ -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() { } diff --git a/NetSSL_Win/include/Poco/Net/X509Certificate.h b/NetSSL_Win/include/Poco/Net/X509Certificate.h index 42e317889..2258790c2 100644 --- a/NetSSL_Win/include/Poco/Net/X509Certificate.h +++ b/NetSSL_Win/include/Poco/Net/X509Certificate.h @@ -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. diff --git a/NetSSL_Win/src/X509Certificate.cpp b/NetSSL_Win/src/X509Certificate.cpp index bb8f5166f..952ef0f59 100644 --- a/NetSSL_Win/src/X509Certificate.cpp +++ b/NetSSL_Win/src/X509Certificate.cpp @@ -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); }