diff --git a/ActiveRecord/Compiler/src/CodeGenerator.cpp b/ActiveRecord/Compiler/src/CodeGenerator.cpp index c318e626dd..de4f2e200e 100644 --- a/ActiveRecord/Compiler/src/CodeGenerator.cpp +++ b/ActiveRecord/Compiler/src/CodeGenerator.cpp @@ -11,6 +11,7 @@ #include "CodeGenerator.h" #include "Poco/StringTokenizer.h" #include +#include using namespace std::string_literals; @@ -21,8 +22,8 @@ namespace ActiveRecord { namespace Compiler { -CodeGenerator::CodeGenerator(const std::string& source, std::ostream& stream): - _source(source), +CodeGenerator::CodeGenerator(std::string source, std::ostream& stream): + _source(std::move(source)), _stream(stream) { } diff --git a/ActiveRecord/Compiler/src/CodeGenerator.h b/ActiveRecord/Compiler/src/CodeGenerator.h index 043bd22c11..429cb3ef98 100644 --- a/ActiveRecord/Compiler/src/CodeGenerator.h +++ b/ActiveRecord/Compiler/src/CodeGenerator.h @@ -25,7 +25,7 @@ namespace Compiler { class CodeGenerator { public: - CodeGenerator(const std::string& source, std::ostream& stream); + CodeGenerator(std::string source, std::ostream& stream); static std::vector splitNameSpace(const std::string& nameSpace); diff --git a/ActiveRecord/Compiler/src/Compiler.cpp b/ActiveRecord/Compiler/src/Compiler.cpp index 6fca2d9bcf..a074c6ddd0 100644 --- a/ActiveRecord/Compiler/src/Compiler.cpp +++ b/ActiveRecord/Compiler/src/Compiler.cpp @@ -41,17 +41,16 @@ class CompilerApp: public Application { public: CompilerApp() - { - } + = default; protected: - void initialize(Application& self) + void initialize(Application& self) override { loadConfiguration(); // load default configuration files, if present Application::initialize(self); } - void defineOptions(OptionSet& options) + void defineOptions(OptionSet& options) override { Application::defineOptions(options); @@ -197,7 +196,7 @@ class CompilerApp: public Application } } - int main(const ArgVec& args) + int main(const ArgVec& args) override { if (!_helpRequested) { diff --git a/ActiveRecord/Compiler/src/HeaderGenerator.cpp b/ActiveRecord/Compiler/src/HeaderGenerator.cpp index 915741bff2..299c870e6c 100644 --- a/ActiveRecord/Compiler/src/HeaderGenerator.cpp +++ b/ActiveRecord/Compiler/src/HeaderGenerator.cpp @@ -20,9 +20,9 @@ namespace ActiveRecord { namespace Compiler { -HeaderGenerator::HeaderGenerator(const std::string& source, std::ostream& stream, const Class& clazz, const ClassMap& classes): - CodeGenerator(source, stream), - _class(clazz), +HeaderGenerator::HeaderGenerator(std::string source, std::ostream& stream, Class clazz, const ClassMap& classes): + CodeGenerator(std::move(source), stream), + _class(std::move(clazz)), _classes(classes) { } diff --git a/ActiveRecord/Compiler/src/HeaderGenerator.h b/ActiveRecord/Compiler/src/HeaderGenerator.h index e91e012ac7..24c904f644 100644 --- a/ActiveRecord/Compiler/src/HeaderGenerator.h +++ b/ActiveRecord/Compiler/src/HeaderGenerator.h @@ -24,7 +24,7 @@ namespace Compiler { class HeaderGenerator: public CodeGenerator { public: - HeaderGenerator(const std::string& source, std::ostream& stream, const Class& clazz, const ClassMap& classes); + HeaderGenerator(std::string source, std::ostream& stream, Class clazz, const ClassMap& classes); void generate() const; void writeClass() const; diff --git a/ActiveRecord/Compiler/src/ImplGenerator.cpp b/ActiveRecord/Compiler/src/ImplGenerator.cpp index 3a550cba90..3a72f2a979 100644 --- a/ActiveRecord/Compiler/src/ImplGenerator.cpp +++ b/ActiveRecord/Compiler/src/ImplGenerator.cpp @@ -9,7 +9,9 @@ #include "ImplGenerator.h" + #include "Poco/Exception.h" +#include using namespace std::string_literals; @@ -20,9 +22,9 @@ namespace ActiveRecord { namespace Compiler { -ImplGenerator::ImplGenerator(const std::string& source, std::ostream& stream, const Class& clazz, const ClassMap& classes): +ImplGenerator::ImplGenerator(const std::string& source, std::ostream& stream, Class clazz, const ClassMap& classes): CodeGenerator(source, stream), - _class(clazz), + _class(std::move(clazz)), _classes(classes) { } diff --git a/ActiveRecord/Compiler/src/ImplGenerator.h b/ActiveRecord/Compiler/src/ImplGenerator.h index 63aea23ced..339cdb5488 100644 --- a/ActiveRecord/Compiler/src/ImplGenerator.h +++ b/ActiveRecord/Compiler/src/ImplGenerator.h @@ -24,7 +24,7 @@ namespace Compiler { class ImplGenerator: public CodeGenerator { public: - ImplGenerator(const std::string& source, std::ostream& stream, const Class& clazz, const ClassMap& classes); + ImplGenerator(const std::string& source, std::ostream& stream, Class clazz, const ClassMap& classes); void generate() const; void writeClassMembers() const; diff --git a/ActiveRecord/Compiler/src/Parser.cpp b/ActiveRecord/Compiler/src/Parser.cpp index 94401f9950..841db463a6 100644 --- a/ActiveRecord/Compiler/src/Parser.cpp +++ b/ActiveRecord/Compiler/src/Parser.cpp @@ -27,8 +27,7 @@ namespace Compiler { Parser::Parser() -{ -} += default; ClassMap Parser::parse(const std::string& systemId, std::istream& stream) @@ -90,7 +89,7 @@ void Parser::startElement(const Poco::XML::XMLString& uri, const Poco::XML::XMLS void Parser::endElement(const Poco::XML::XMLString& uri, const Poco::XML::XMLString& localName, const Poco::XML::XMLString& qname) { - poco_assert (_elemStack.size() > 0); + poco_assert (!_elemStack.empty()); if (qname == "class") { @@ -250,7 +249,7 @@ std::string Parser::convertCamelCase(const std::string& name) { if (Poco::Ascii::isUpper(c)) { - if (!(result.empty() || result.back() == '_')) + if (!result.empty() && result.back() != '_') { result += '_'; } diff --git a/ActiveRecord/Compiler/src/Parser.h b/ActiveRecord/Compiler/src/Parser.h index 9b639a7733..ea9f78503a 100644 --- a/ActiveRecord/Compiler/src/Parser.h +++ b/ActiveRecord/Compiler/src/Parser.h @@ -34,9 +34,9 @@ class Parser: protected Poco::XML::DefaultHandler protected: // ContentHandler - void setDocumentLocator(const Poco::XML::Locator* pLocator); - void startElement(const Poco::XML::XMLString& uri, const Poco::XML::XMLString& localName, const Poco::XML::XMLString& qname, const Poco::XML::Attributes& attributes); - void endElement(const Poco::XML::XMLString& uri, const Poco::XML::XMLString& localName, const Poco::XML::XMLString& qname); + void setDocumentLocator(const Poco::XML::Locator* pLocator) override; + void startElement(const Poco::XML::XMLString& uri, const Poco::XML::XMLString& localName, const Poco::XML::XMLString& qname, const Poco::XML::Attributes& attributes) override; + void endElement(const Poco::XML::XMLString& uri, const Poco::XML::XMLString& localName, const Poco::XML::XMLString& qname) override; void handleProject(const Poco::XML::Attributes& attributes); void handleClass(const Poco::XML::Attributes& attributes); void handleProperty(const Poco::XML::Attributes& attributes); diff --git a/ActiveRecord/include/Poco/ActiveRecord/ActiveRecord.h b/ActiveRecord/include/Poco/ActiveRecord/ActiveRecord.h index c8d2860f7a..ec09939f4f 100644 --- a/ActiveRecord/include/Poco/ActiveRecord/ActiveRecord.h +++ b/ActiveRecord/include/Poco/ActiveRecord/ActiveRecord.h @@ -73,7 +73,7 @@ class ActiveRecordLib_API ActiveRecordBase: public Poco::RefCountedObject protected: ActiveRecordBase() = default; - ~ActiveRecordBase() = default; + ~ActiveRecordBase() override = default; template static Poco::AutoPtr withContext(Poco::AutoPtr pObj, Context::Ptr pContext) @@ -110,13 +110,13 @@ class ActiveRecord: public ActiveRecordBase /// Returns the unique ID of the object. // ActiveRecordBase - std::string toString() const; - bool isValid() const; + std::string toString() const override; + bool isValid() const override; protected: ActiveRecord() = default; ActiveRecord(ID id): _id(id) {}; - ~ActiveRecord() = default; + ~ActiveRecord() override = default; ActiveRecord(const ActiveRecord& other): _id(other._id) @@ -171,7 +171,7 @@ class ActiveRecordLib_API KeylessActiveRecord: public ActiveRecordBase using Ptr = Poco::AutoPtr; // ActiveRecordBase - std::string toString() const; + std::string toString() const override; protected: template diff --git a/ActiveRecord/include/Poco/ActiveRecord/Context.h b/ActiveRecord/include/Poco/ActiveRecord/Context.h index bb5cda0a39..13481e5bfe 100644 --- a/ActiveRecord/include/Poco/ActiveRecord/Context.h +++ b/ActiveRecord/include/Poco/ActiveRecord/Context.h @@ -33,13 +33,13 @@ class ActiveRecordLib_API Context: public Poco::RefCountedObject public: using Ptr = Poco::AutoPtr; - explicit Context(const Poco::Data::Session& session); + explicit Context(Poco::Data::Session session); /// Creates the Context from an existing Poco::Data::Session. Context(const std::string& connector, const std::string& connectionString); /// Creates the Context from a connector name and connection string. - ~Context() = default; + ~Context() override = default; /// Destroys the Context. Poco::Data::Session& session(); diff --git a/ActiveRecord/include/Poco/ActiveRecord/StatementPlaceholderProvider.h b/ActiveRecord/include/Poco/ActiveRecord/StatementPlaceholderProvider.h index 5273f4b67e..558d6224b1 100644 --- a/ActiveRecord/include/Poco/ActiveRecord/StatementPlaceholderProvider.h +++ b/ActiveRecord/include/Poco/ActiveRecord/StatementPlaceholderProvider.h @@ -40,16 +40,16 @@ class ActiveRecordLib_API StatementPlaceholderProvider class ActiveRecordLib_API DefaultStatementPlaceholderProvider: public StatementPlaceholderProvider { public: - void reset(); - std::string next(); + void reset() override; + std::string next() override; }; class ActiveRecordLib_API PostgresStatementPlaceholderProvider: public StatementPlaceholderProvider { public: - void reset(); - std::string next(); + void reset() override; + std::string next() override; private: int _n = 1; diff --git a/ActiveRecord/src/Context.cpp b/ActiveRecord/src/Context.cpp index 499ba090e2..bf986a35b7 100644 --- a/ActiveRecord/src/Context.cpp +++ b/ActiveRecord/src/Context.cpp @@ -12,6 +12,8 @@ // +#include + #include "Poco/ActiveRecord/Context.h" @@ -19,8 +21,8 @@ namespace Poco { namespace ActiveRecord { -Context::Context(const Poco::Data::Session& session): - _session(session) +Context::Context(Poco::Data::Session session): + _session(std::move(session)) { } diff --git a/ActiveRecord/src/StatementPlaceholderProvider.cpp b/ActiveRecord/src/StatementPlaceholderProvider.cpp index 85e6140c27..98da885ed4 100644 --- a/ActiveRecord/src/StatementPlaceholderProvider.cpp +++ b/ActiveRecord/src/StatementPlaceholderProvider.cpp @@ -24,8 +24,7 @@ namespace ActiveRecord { StatementPlaceholderProvider::~StatementPlaceholderProvider() -{ -} += default; void DefaultStatementPlaceholderProvider::reset() diff --git a/Crypto/include/Poco/Crypto/Cipher.h b/Crypto/include/Poco/Crypto/Cipher.h index c0a6188fc2..e1384853b3 100644 --- a/Crypto/include/Poco/Crypto/Cipher.h +++ b/Crypto/include/Poco/Crypto/Cipher.h @@ -95,7 +95,7 @@ class Crypto_API Cipher: public Poco::RefCountedObject ENC_BINHEX_NO_LF = 0x82 /// BinHex-encoded output, no linefeeds }; - virtual ~Cipher(); + ~Cipher() override; /// Destroys the Cipher. virtual const std::string& name() const = 0; diff --git a/Crypto/include/Poco/Crypto/CipherImpl.h b/Crypto/include/Poco/Crypto/CipherImpl.h index 49a7476f83..028b8dec8f 100644 --- a/Crypto/include/Poco/Crypto/CipherImpl.h +++ b/Crypto/include/Poco/Crypto/CipherImpl.h @@ -33,19 +33,19 @@ class CipherImpl: public Cipher /// An implementation of the Cipher class for OpenSSL's crypto library. { public: - CipherImpl(const CipherKey& key); + CipherImpl(CipherKey key); /// Creates a new CipherImpl object for the given CipherKey. - virtual ~CipherImpl(); + ~CipherImpl() override; /// Destroys the CipherImpl. - const std::string& name() const; + const std::string& name() const override; /// Returns the name of the cipher. - CryptoTransform::Ptr createEncryptor(); + CryptoTransform::Ptr createEncryptor() override; /// Creates an encryptor object. - CryptoTransform::Ptr createDecryptor(); + CryptoTransform::Ptr createDecryptor() override; /// Creates a decryptor object. private: diff --git a/Crypto/include/Poco/Crypto/CipherKeyImpl.h b/Crypto/include/Poco/Crypto/CipherKeyImpl.h index 75b3bdadb2..e322035063 100644 --- a/Crypto/include/Poco/Crypto/CipherKeyImpl.h +++ b/Crypto/include/Poco/Crypto/CipherKeyImpl.h @@ -64,8 +64,8 @@ class CipherKeyImpl: public RefCountedObject /// and iteration count. CipherKeyImpl(const std::string& name, - const ByteVec& key, - const ByteVec& iv); + ByteVec key, + ByteVec iv); /// Creates a new CipherKeyImpl object, using the /// given cipher name, key and initialization vector. @@ -73,7 +73,7 @@ class CipherKeyImpl: public RefCountedObject /// Creates a new CipherKeyImpl object. Autoinitializes key /// and initialization vector. - virtual ~CipherKeyImpl(); + ~CipherKeyImpl() override; /// Destroys the CipherKeyImpl. const std::string& name() const; @@ -107,7 +107,7 @@ class CipherKeyImpl: public RefCountedObject /// Returns the cipher object private: - void generateKey(const std::string& passphrase, + void generateKey(const std::string& password, const std::string& salt, int iterationCount); /// Generates key and IV from a password and optional salt string. diff --git a/Crypto/include/Poco/Crypto/Crypto.h b/Crypto/include/Poco/Crypto/Crypto.h index 7b857cf31b..125b555062 100644 --- a/Crypto/include/Poco/Crypto/Crypto.h +++ b/Crypto/include/Poco/Crypto/Crypto.h @@ -187,7 +187,7 @@ inline std::string& getError(std::string& msg) while ((err = ERR_get_error())) { if (!msg.empty()) msg.append(1, '\n'); - msg.append(ERR_error_string(err, 0)); + msg.append(ERR_error_string(err, nullptr)); } return msg; } diff --git a/Crypto/include/Poco/Crypto/CryptoException.h b/Crypto/include/Poco/Crypto/CryptoException.h index 8bd5b011c4..632276aeb2 100644 --- a/Crypto/include/Poco/Crypto/CryptoException.h +++ b/Crypto/include/Poco/Crypto/CryptoException.h @@ -38,12 +38,12 @@ class Crypto_API OpenSSLException : public CryptoException 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() noexcept; + ~OpenSSLException() noexcept override; OpenSSLException& operator = (const OpenSSLException& exc); - const char* name() const noexcept; - const char* className() const noexcept; - Poco::Exception* clone() const; - void rethrow() const; + const char* name() const noexcept override; + const char* className() const noexcept override; + Poco::Exception* clone() const override; + void rethrow() const override; private: void setExtMessage(); diff --git a/Crypto/include/Poco/Crypto/CryptoStream.h b/Crypto/include/Poco/Crypto/CryptoStream.h index e823733925..122b9c2a71 100644 --- a/Crypto/include/Poco/Crypto/CryptoStream.h +++ b/Crypto/include/Poco/Crypto/CryptoStream.h @@ -42,14 +42,14 @@ class Crypto_API CryptoStreamBuf: public Poco::BufferedStreamBuf CryptoStreamBuf(std::istream& istr, CryptoTransform::Ptr pTransform, std::streamsize bufferSize = 8192); CryptoStreamBuf(std::ostream& ostr, CryptoTransform::Ptr pTransform, std::streamsize bufferSize = 8192); - virtual ~CryptoStreamBuf(); + ~CryptoStreamBuf() override; void close(); /// Flushes all buffers and finishes the encryption. protected: - int readFromDevice(char* buffer, std::streamsize length); - int writeToDevice(const char* buffer, std::streamsize length); + int readFromDevice(char* buffer, std::streamsize length) override; + int writeToDevice(const char* buffer, std::streamsize length) override; private: CryptoTransform::Ptr _pTransform; @@ -73,7 +73,7 @@ class Crypto_API CryptoIOS: public virtual std::ios public: CryptoIOS(std::istream& istr, CryptoTransform::Ptr pTransform, std::streamsize bufferSize = 8192); CryptoIOS(std::ostream& ostr, CryptoTransform::Ptr pTransform, std::streamsize bufferSize = 8192); - ~CryptoIOS(); + ~CryptoIOS() override; CryptoStreamBuf* rdbuf(); protected: @@ -97,7 +97,7 @@ class Crypto_API CryptoInputStream: public CryptoIOS, public std::istream CryptoInputStream(std::istream& istr, Cipher& cipher, std::streamsize bufferSize = 8192); /// Create a new encrypting CryptoInputStream object using the given cipher. - ~CryptoInputStream(); + ~CryptoInputStream() override; /// Destroys the CryptoInputStream. }; @@ -121,7 +121,7 @@ class Crypto_API CryptoOutputStream: public CryptoIOS, public std::ostream CryptoOutputStream(std::ostream& ostr, Cipher& cipher, std::streamsize bufferSize = 8192); /// Create a new decrypting CryptoOutputStream object using the given cipher. - ~CryptoOutputStream(); + ~CryptoOutputStream() override; /// Destroys the CryptoOutputStream. void close(); @@ -137,7 +137,7 @@ class Crypto_API DecryptingInputStream: public CryptoIOS, public std::istream DecryptingInputStream(std::istream& istr, Cipher& cipher, std::streamsize bufferSize = 8192); /// Create a new DecryptingInputStream object using the given cipher. - ~DecryptingInputStream(); + ~DecryptingInputStream() override; /// Destroys the DecryptingInputStream. }; @@ -150,7 +150,7 @@ class Crypto_API DecryptingOutputStream: public CryptoIOS, public std::ostream DecryptingOutputStream(std::ostream& ostr, Cipher& cipher, std::streamsize bufferSize = 8192); /// Create a new DecryptingOutputStream object using the given cipher. - ~DecryptingOutputStream(); + ~DecryptingOutputStream() override; /// Destroys the DecryptingOutputStream. void close(); @@ -166,7 +166,7 @@ class Crypto_API EncryptingInputStream: public CryptoIOS, public std::istream EncryptingInputStream(std::istream& istr, Cipher& cipher, std::streamsize bufferSize = 8192); /// Create a new EncryptingInputStream object using the given cipher. - ~EncryptingInputStream(); + ~EncryptingInputStream() override; /// Destroys the EncryptingInputStream. }; @@ -179,7 +179,7 @@ class Crypto_API EncryptingOutputStream: public CryptoIOS, public std::ostream EncryptingOutputStream(std::ostream& ostr, Cipher& cipher, std::streamsize bufferSize = 8192); /// Create a new EncryptingOutputStream object using the given cipher. - ~EncryptingOutputStream(); + ~EncryptingOutputStream() override; /// Destroys the EncryptingOutputStream. void close(); diff --git a/Crypto/include/Poco/Crypto/DigestEngine.h b/Crypto/include/Poco/Crypto/DigestEngine.h index 1c30e769d5..f2ab705fb8 100644 --- a/Crypto/include/Poco/Crypto/DigestEngine.h +++ b/Crypto/include/Poco/Crypto/DigestEngine.h @@ -33,14 +33,14 @@ class Crypto_API DigestEngine: public Poco::DigestEngine /// digest algorithms supported by OpenSSL. { public: - DigestEngine(const std::string& name); + DigestEngine(std::string name); /// Creates a DigestEngine using the digest with the given name /// (e.g., "MD5", "SHA1", "SHA256", "SHA512", etc.). /// See the OpenSSL documentation for a list of supported digest algorithms. /// /// Throws a Poco::NotFoundException if no algorithm with the given name exists. - ~DigestEngine(); + ~DigestEngine() override; /// Destroys the DigestEngine. const std::string& algorithm() const; @@ -50,12 +50,12 @@ class Crypto_API DigestEngine: public Poco::DigestEngine /// Returns the NID (OpenSSL object identifier) of the digest algorithm. // DigestEngine - std::size_t digestLength() const; - void reset(); - const Poco::DigestEngine::Digest& digest(); + std::size_t digestLength() const override; + void reset() override; + const Poco::DigestEngine::Digest& digest() override; protected: - void updateImpl(const void* data, std::size_t length); + void updateImpl(const void* data, std::size_t length) override; private: std::string _name; diff --git a/Crypto/include/Poco/Crypto/ECDSADigestEngine.h b/Crypto/include/Poco/Crypto/ECDSADigestEngine.h index a3d8156fef..95392f728c 100644 --- a/Crypto/include/Poco/Crypto/ECDSADigestEngine.h +++ b/Crypto/include/Poco/Crypto/ECDSADigestEngine.h @@ -47,7 +47,7 @@ class Crypto_API ECDSADigestEngine: public Poco::DigestEngine { public: - ECDSADigestEngine(const ECKey& key, const std::string &name); + ECDSADigestEngine(ECKey key, const std::string &name); /// Creates the ECDSADigestEngine with the given ECDSA key, /// using the hash algorithm with the given name /// (e.g., "SHA1", "SHA256", "SHA512", etc.). @@ -55,17 +55,17 @@ class Crypto_API ECDSADigestEngine: public Poco::DigestEngine /// /// Throws a Poco::NotFoundException if no algorithm with the given name exists. - ~ECDSADigestEngine(); + ~ECDSADigestEngine() override; /// Destroys the ECDSADigestEngine. - std::size_t digestLength() const; + std::size_t digestLength() const override; /// Returns the length of the digest in bytes. - void reset(); + void reset() override; /// Resets the engine so that a new /// digest can be computed. - const DigestEngine::Digest& digest(); + const DigestEngine::Digest& digest() override; /// Finishes the computation of the digest /// (the first time it's called) and /// returns the message digest. @@ -85,7 +85,7 @@ class Crypto_API ECDSADigestEngine: public Poco::DigestEngine /// Returns true if the signature can be verified, false otherwise. protected: - void updateImpl(const void* data, std::size_t length); + void updateImpl(const void* data, std::size_t length) override; private: ECKey _key; diff --git a/Crypto/include/Poco/Crypto/ECKey.h b/Crypto/include/Poco/Crypto/ECKey.h index 950b86928f..f6d7212823 100644 --- a/Crypto/include/Poco/Crypto/ECKey.h +++ b/Crypto/include/Poco/Crypto/ECKey.h @@ -49,7 +49,7 @@ class Crypto_API ECKey: public KeyPair ECKey(const X509Certificate& cert); /// Extracts the EC public key from the given certificate. - ECKey(const PKCS12Container& cert); + ECKey(const PKCS12Container& cont); /// Extracts the EC private key from the given certificate. ECKey(const std::string& eccGroup); @@ -65,7 +65,7 @@ class Crypto_API ECKey: public KeyPair /// If a private key is specified, you don't need to specify a public key file. /// OpenSSL will auto-create the public key from the private key. - ECKey(std::istream* pPublicKeyStream, std::istream* pPrivateKeyStream = 0, const std::string& privateKeyPassphrase = ""); + ECKey(std::istream* pPublicKeyStream, std::istream* pPrivateKeyStream = nullptr, const std::string& privateKeyPassphrase = ""); /// Creates the ECKey, by reading public and private key from the given streams and /// using the given passphrase for the private key. /// @@ -74,13 +74,13 @@ class Crypto_API ECKey: public KeyPair /// If a private key is specified, you don't need to specify a public key file. /// OpenSSL will auto-create the public key from the private key. - ECKey(const ECKey& key); + ECKey(const ECKey& other); /// Creates the ECKey by copying another one. - ECKey(ECKey&& key) noexcept; + ECKey(ECKey&& other) noexcept; /// Creates the ECKey by moving another one. - ~ECKey(); + ~ECKey() override; /// Destroys the ECKey. ECKey& operator = (const ECKey& other); diff --git a/Crypto/include/Poco/Crypto/ECKeyImpl.h b/Crypto/include/Poco/Crypto/ECKeyImpl.h index f9c1b1d42f..de1c1ee77a 100644 --- a/Crypto/include/Poco/Crypto/ECKeyImpl.h +++ b/Crypto/include/Poco/Crypto/ECKeyImpl.h @@ -53,10 +53,10 @@ class ECKeyImpl: public KeyPairImpl ECKeyImpl(const X509Certificate& cert); /// Constructs ECKeyImpl by extracting the EC public key from the given certificate. - ECKeyImpl(const PKCS12Container& cert); + ECKeyImpl(const PKCS12Container& cont); /// Constructs ECKeyImpl by extracting the EC private key from the given certificate. - ECKeyImpl(int eccGroup); + ECKeyImpl(int curve); /// Creates the ECKey of the specified group. Creates a new public/private keypair using the given parameters. /// Can be used to sign data and verify signatures. @@ -70,7 +70,7 @@ class ECKeyImpl: public KeyPairImpl /// is not null. If a private key file is specified, you don't need to /// specify a public key file. OpenSSL will auto-create it from the private key. - ~ECKeyImpl(); + ~ECKeyImpl() override; /// Destroys the ECKeyImpl. EC_KEY* getECKey(); @@ -79,7 +79,7 @@ class ECKeyImpl: public KeyPairImpl const EC_KEY* getECKey() const; /// Returns the OpenSSL EC key. - int size() const; + int size() const override; /// Returns the EC key length in bits. int groupId() const; @@ -90,15 +90,15 @@ class ECKeyImpl: public KeyPairImpl void save(const std::string& publicKeyFile, const std::string& privateKeyFile = "", - const std::string& privateKeyPassphrase = "") const; + const std::string& privateKeyPassphrase = "") const override; /// Exports the public and private keys to the given files. /// /// If an empty filename is specified, the corresponding key /// is not exported. void save(std::ostream* pPublicKeyStream, - std::ostream* pPrivateKeyStream = 0, - const std::string& privateKeyPassphrase = "") const; + std::ostream* pPrivateKeyStream = nullptr, + const std::string& privateKeyPassphrase = "") const override; /// Exports the public and private key to the given streams. /// /// If a null pointer is passed for a stream, the corresponding diff --git a/Crypto/include/Poco/Crypto/EVPCipherImpl.h b/Crypto/include/Poco/Crypto/EVPCipherImpl.h index b85d7eaaa1..41d8959b2c 100644 --- a/Crypto/include/Poco/Crypto/EVPCipherImpl.h +++ b/Crypto/include/Poco/Crypto/EVPCipherImpl.h @@ -38,20 +38,20 @@ class EVPCipherImpl: public Cipher /// requires the private key. { public: - EVPCipherImpl(const EVPPKey& key); + EVPCipherImpl(EVPPKey key); /// Creates a new EVPCipherImpl object for the given EVPPKey /// and using the given padding mode. - virtual ~EVPCipherImpl(); + ~EVPCipherImpl() override; /// Destroys the EVPCipherImpl. - const std::string& name() const; + const std::string& name() const override; /// Returns the name of the Cipher. - CryptoTransform::Ptr createEncryptor(); + CryptoTransform::Ptr createEncryptor() override; /// Creates an encryptor object. - CryptoTransform::Ptr createDecryptor(); + CryptoTransform::Ptr createDecryptor() override; /// Creates a decryptor object. private: diff --git a/Crypto/include/Poco/Crypto/EVPPKey.h b/Crypto/include/Poco/Crypto/EVPPKey.h index 6f53a96f57..0b44d1bf32 100644 --- a/Crypto/include/Poco/Crypto/EVPPKey.h +++ b/Crypto/include/Poco/Crypto/EVPPKey.h @@ -63,7 +63,7 @@ class Crypto_API EVPPKey EVPPKey(const X509Certificate& cert); /// Constructs EVPPKey from the given certificate. - EVPPKey(const PKCS12Container& cert); + EVPPKey(const PKCS12Container& cont); /// Constructs EVPPKey from the given container. #if OPENSSL_VERSION_NUMBER >= 0x10000000L @@ -86,7 +86,7 @@ class Crypto_API EVPPKey #endif // OPENSSL_VERSION_NUMBER >= 0x10000000L #if OPENSSL_VERSION_NUMBER >= 0x30000000L - explicit EVPPKey(const std::vector* publicKey, const std::vector* privateKey, unsigned long exponent, int type); + explicit EVPPKey(const std::vector* public_key, const std::vector* private_key, unsigned long exponent, int type); #endif explicit EVPPKey(EVP_PKEY* pEVPPKey); @@ -150,7 +150,7 @@ class Crypto_API EVPPKey /// If an empty filename is specified, the corresponding key /// is not exported. - void save(std::ostream* pPublicKeyStream, std::ostream* pPrivateKeyStream = 0, const std::string& privateKeyPassphrase = "") const; + void save(std::ostream* pPublicKeyStream, std::ostream* pPrivateKeyStream = nullptr, const std::string& privateKeyPassphrase = "") const; /// Exports the public and/or private key to the given streams. /// /// If a null pointer is passed for a stream, the corresponding @@ -182,7 +182,7 @@ class Crypto_API EVPPKey #endif static int type(const EVP_PKEY* pEVPPKey); void checkType(); - void newECKey(const char* group); + void newECKey(const char* ecCurveName); void duplicate(EVP_PKEY* pEVPPKey); //@ deprecated @@ -216,7 +216,7 @@ class Crypto_API EVPPKey poco_check_ptr (ppKey); poco_assert_dbg (!*ppKey); - FILE* pFile = 0; + FILE* pFile = nullptr; if (!keyFile.empty()) { if (!getFunc) *ppKey = (K*)EVP_PKEY_new(); @@ -234,11 +234,11 @@ class Crypto_API EVPPKey if (pFile) { - pem_password_cb* pCB = pass.empty() ? (pem_password_cb*)0 : &passCB; - void* pPassword = pass.empty() ? (void*)0 : (void*)pass.c_str(); + pem_password_cb* pCB = pass.empty() ? (pem_password_cb*)nullptr : &passCB; + void* pPassword = pass.empty() ? (void*)nullptr : (void*)pass.c_str(); if (readFunc(pFile, &pKey, pCB, pPassword)) { - fclose(pFile); pFile = 0; + fclose(pFile); pFile = nullptr; if(getFunc) { *ppKey = (K*)getFunc(pKey); @@ -286,7 +286,7 @@ class Crypto_API EVPPKey poco_check_ptr(ppKey); poco_assert_dbg(!*ppKey); - BIO* pBIO = 0; + BIO* pBIO = nullptr; if (pIstr) { std::ostringstream ostr; @@ -299,11 +299,11 @@ class Crypto_API EVPPKey EVP_PKEY* pKey = getFunc ? EVP_PKEY_new() : (EVP_PKEY*)*ppKey; if (pKey) { - pem_password_cb* pCB = pass.empty() ? (pem_password_cb*)0 : &passCB; - void* pPassword = pass.empty() ? (void*)0 : (void*)pass.c_str(); + pem_password_cb* pCB = pass.empty() ? (pem_password_cb*)nullptr : &passCB; + void* pPassword = pass.empty() ? (void*)nullptr : (void*)pass.c_str(); if (readFunc(pBIO, &pKey, pCB, pPassword)) { - BIO_free(pBIO); pBIO = 0; + BIO_free(pBIO); pBIO = nullptr; if (getFunc) { *ppKey = (K*)getFunc(pKey); @@ -333,7 +333,7 @@ class Crypto_API EVPPKey throw OpenSSLException(msg); } - EVP_PKEY* _pEVPPKey = 0; + EVP_PKEY* _pEVPPKey = nullptr; static const std::map KNOWN_TYPES; //@deprecated diff --git a/Crypto/include/Poco/Crypto/KeyPair.h b/Crypto/include/Poco/Crypto/KeyPair.h index 6f14a5f8e5..c00fc96435 100644 --- a/Crypto/include/Poco/Crypto/KeyPair.h +++ b/Crypto/include/Poco/Crypto/KeyPair.h @@ -44,7 +44,7 @@ class Crypto_API KeyPair KT_EC = KeyPairImpl::KT_EC_IMPL }; - explicit KeyPair(KeyPairImpl::Ptr pKeyPairImpl = 0); + explicit KeyPair(KeyPairImpl::Ptr pKeyPairImpl = nullptr); /// Extracts the RSA public key from the given certificate. KeyPair(const KeyPair& other); @@ -65,17 +65,17 @@ class Crypto_API KeyPair virtual int size() const; /// Returns the RSA modulus size. - virtual void save(const std::string& publicKeyPairFile, - const std::string& privateKeyPairFile = "", - const std::string& privateKeyPairPassphrase = "") const; + virtual void save(const std::string& publicKeyFile, + const std::string& privateKeyFile = "", + const std::string& privateKeyPassphrase = "") const; /// Exports the public and private keys to the given files. /// /// If an empty filename is specified, the corresponding key /// is not exported. - virtual void save(std::ostream* pPublicKeyPairStream, - std::ostream* pPrivateKeyPairStream = 0, - const std::string& privateKeyPairPassphrase = "") const; + virtual void save(std::ostream* pPublicKeyStream, + std::ostream* pPrivateKeyStream = nullptr, + const std::string& privateKeyPassphrase = "") const; /// Exports the public and private key to the given streams. /// /// If a null pointer is passed for a stream, the corresponding diff --git a/Crypto/include/Poco/Crypto/KeyPairImpl.h b/Crypto/include/Poco/Crypto/KeyPairImpl.h index 50718ce374..486703e3ec 100644 --- a/Crypto/include/Poco/Crypto/KeyPairImpl.h +++ b/Crypto/include/Poco/Crypto/KeyPairImpl.h @@ -44,10 +44,10 @@ class KeyPairImpl: public Poco::RefCountedObject using Ptr = Poco::AutoPtr; using ByteVec = std::vector; - KeyPairImpl(const std::string& name, Type type); + KeyPairImpl(std::string name, Type type); /// Create KeyPairImpl with specified type and name. - virtual ~KeyPairImpl(); + ~KeyPairImpl() override; /// Destroys the KeyPairImpl. virtual int size() const = 0; @@ -62,7 +62,7 @@ class KeyPairImpl: public Poco::RefCountedObject /// is not exported. virtual void save(std::ostream* pPublicKeyStream, - std::ostream* pPrivateKeyStream = 0, + std::ostream* pPrivateKeyStream = nullptr, const std::string& privateKeyPassphrase = "") const = 0; /// Exports the public and private key to the given streams. /// diff --git a/Crypto/include/Poco/Crypto/PKCS12Container.h b/Crypto/include/Poco/Crypto/PKCS12Container.h index 9fbef7fdb9..7166356af8 100644 --- a/Crypto/include/Poco/Crypto/PKCS12Container.h +++ b/Crypto/include/Poco/Crypto/PKCS12Container.h @@ -45,16 +45,16 @@ class Crypto_API PKCS12Container explicit PKCS12Container(const std::string& path, const std::string& password = ""); /// Creates the PKCS12Container object from a file. - PKCS12Container(const PKCS12Container& cont); + PKCS12Container(const PKCS12Container& other); /// Copy constructor. - PKCS12Container(PKCS12Container&& cont) noexcept; + PKCS12Container(PKCS12Container&& other) noexcept; /// Move constructor. - PKCS12Container& operator = (const PKCS12Container& cont); + PKCS12Container& operator = (const PKCS12Container& other); /// Assignment operator. - PKCS12Container& operator = (PKCS12Container&& cont) noexcept; + PKCS12Container& operator = (PKCS12Container&& other) noexcept; /// Move assignment operator. ~PKCS12Container(); @@ -103,7 +103,7 @@ class Crypto_API PKCS12Container inline bool PKCS12Container::hasX509Certificate() const { - return _pX509Cert.get() != 0; + return _pX509Cert.get() != nullptr; } @@ -135,7 +135,7 @@ inline const PKCS12Container::CANameList& PKCS12Container::getFriendlyNamesCA() inline bool PKCS12Container::hasKey() const { - return _pKey != 0; + return _pKey != nullptr; } diff --git a/Crypto/include/Poco/Crypto/RSACipherImpl.h b/Crypto/include/Poco/Crypto/RSACipherImpl.h index e71c8fad02..a6484dbf56 100644 --- a/Crypto/include/Poco/Crypto/RSACipherImpl.h +++ b/Crypto/include/Poco/Crypto/RSACipherImpl.h @@ -39,20 +39,20 @@ class RSACipherImpl: public Cipher /// requires the private key. { public: - RSACipherImpl(const RSAKey& key, RSAPaddingMode paddingMode); + RSACipherImpl(RSAKey key, RSAPaddingMode paddingMode); /// Creates a new RSACipherImpl object for the given RSAKey /// and using the given padding mode. - virtual ~RSACipherImpl(); + ~RSACipherImpl() override; /// Destroys the RSACipherImpl. - const std::string& name() const; + const std::string& name() const override; /// Returns the name of the Cipher. - CryptoTransform::Ptr createEncryptor(); + CryptoTransform::Ptr createEncryptor() override; /// Creates an encryptor object. - CryptoTransform::Ptr createDecryptor(); + CryptoTransform::Ptr createDecryptor() override; /// Creates a decryptor object. private: diff --git a/Crypto/include/Poco/Crypto/RSADigestEngine.h b/Crypto/include/Poco/Crypto/RSADigestEngine.h index e0c451d24b..bab1d4d282 100644 --- a/Crypto/include/Poco/Crypto/RSADigestEngine.h +++ b/Crypto/include/Poco/Crypto/RSADigestEngine.h @@ -52,12 +52,12 @@ class Crypto_API RSADigestEngine: public Poco::DigestEngine }; //@ deprecated - RSADigestEngine(const RSAKey& key, DigestType digestType = DIGEST_SHA1); + RSADigestEngine(RSAKey key, DigestType digestType = DIGEST_SHA1); /// Creates the RSADigestEngine with the given RSA key, /// using the MD5 or SHA-1 hash algorithm. /// Kept for backward compatibility - RSADigestEngine(const RSAKey& key, const std::string &name); + RSADigestEngine(RSAKey key, const std::string &name); /// Creates the RSADigestEngine with the given RSA key, /// using the hash algorithm with the given name /// (e.g., "MD5", "SHA1", "SHA256", "SHA512", etc.). @@ -65,17 +65,17 @@ class Crypto_API RSADigestEngine: public Poco::DigestEngine /// /// Throws a Poco::NotFoundException if no algorithm with the given name exists. - ~RSADigestEngine(); + ~RSADigestEngine() override; /// Destroys the RSADigestEngine. - std::size_t digestLength() const; + std::size_t digestLength() const override; /// Returns the length of the digest in bytes. - void reset(); + void reset() override; /// Resets the engine so that a new /// digest can be computed. - const DigestEngine::Digest& digest(); + const DigestEngine::Digest& digest() override; /// Finishes the computation of the digest /// (the first time it's called) and /// returns the message digest. @@ -95,7 +95,7 @@ class Crypto_API RSADigestEngine: public Poco::DigestEngine /// Returns true if the signature can be verified, false otherwise. protected: - void updateImpl(const void* data, std::size_t length); + void updateImpl(const void* data, std::size_t length) override; private: RSAKey _key; diff --git a/Crypto/include/Poco/Crypto/RSAKey.h b/Crypto/include/Poco/Crypto/RSAKey.h index 767d5cd3dc..31e9967582 100644 --- a/Crypto/include/Poco/Crypto/RSAKey.h +++ b/Crypto/include/Poco/Crypto/RSAKey.h @@ -81,7 +81,7 @@ class Crypto_API RSAKey: public KeyPair /// OpenSSL will auto-create the public key from the private key. RSAKey(std::istream* pPublicKeyStream, - std::istream* pPrivateKeyStream = 0, + std::istream* pPrivateKeyStream = nullptr, const std::string& privateKeyPassphrase = ""); /// Creates the RSAKey, by reading public and private key from the given streams and /// using the given passphrase for the private key. @@ -97,7 +97,7 @@ class Crypto_API RSAKey: public KeyPair RSAKey(RSAKey&& other) noexcept; /// Move constructor. - ~RSAKey(); + ~RSAKey() override; /// Destroys the RSAKey. RSAKey& operator = (const RSAKey& other); diff --git a/Crypto/include/Poco/Crypto/RSAKeyImpl.h b/Crypto/include/Poco/Crypto/RSAKeyImpl.h index f0397381ce..54f73fb44b 100644 --- a/Crypto/include/Poco/Crypto/RSAKeyImpl.h +++ b/Crypto/include/Poco/Crypto/RSAKeyImpl.h @@ -56,7 +56,7 @@ class RSAKeyImpl: public KeyPairImpl RSAKeyImpl(const X509Certificate& cert); /// Extracts the RSA public key from the given certificate. - RSAKeyImpl(const PKCS12Container& cert); + RSAKeyImpl(const PKCS12Container& cont); /// Extracts the RSA private key from the given certificate. RSAKeyImpl(int keyLength, unsigned long exponent); @@ -73,7 +73,7 @@ class RSAKeyImpl: public KeyPairImpl /// is not null. If a private key file is specified, you don't need to /// specify a public key file. OpenSSL will auto-create it from the private key. - ~RSAKeyImpl(); + ~RSAKeyImpl() override; /// Destroys the RSAKeyImpl. RSA* getRSA(); @@ -82,7 +82,7 @@ class RSAKeyImpl: public KeyPairImpl const RSA* getRSA() const; /// Returns the OpenSSL RSA object. - int size() const; + int size() const override; /// Returns the RSA modulus size. ByteVec modulus() const; @@ -96,15 +96,15 @@ class RSAKeyImpl: public KeyPairImpl void save(const std::string& publicKeyFile, const std::string& privateKeyFile = "", - const std::string& privateKeyPassphrase = "") const; + const std::string& privateKeyPassphrase = "") const override; /// Exports the public and private keys to the given files. /// /// If an empty filename is specified, the corresponding key /// is not exported. void save(std::ostream* pPublicKeyStream, - std::ostream* pPrivateKeyStream = 0, - const std::string& privateKeyPassphrase = "") const; + std::ostream* pPrivateKeyStream = nullptr, + const std::string& privateKeyPassphrase = "") const override; /// Exports the public and private key to the given streams. /// /// If a null pointer is passed for a stream, the corresponding diff --git a/Crypto/src/Cipher.cpp b/Crypto/src/Cipher.cpp index 2e9326f44d..b678b457f0 100644 --- a/Crypto/src/Cipher.cpp +++ b/Crypto/src/Cipher.cpp @@ -30,13 +30,11 @@ namespace Crypto { Cipher::Cipher() -{ -} += default; Cipher::~Cipher() -{ -} += default; std::string Cipher::encryptString(const std::string& str, Encoding encoding, bool padding) diff --git a/Crypto/src/CipherFactory.cpp b/Crypto/src/CipherFactory.cpp index 9e59dc267f..3ebd5fc3c2 100644 --- a/Crypto/src/CipherFactory.cpp +++ b/Crypto/src/CipherFactory.cpp @@ -35,15 +35,14 @@ namespace Crypto { CipherFactory::CipherFactory() { #if OPENSSL_VERSION_NUMBER >= 0x30000000L - OSSL_PROVIDER_load(NULL, "default"); - OSSL_PROVIDER_load(NULL, "legacy"); + OSSL_PROVIDER_load(nullptr, "default"); + OSSL_PROVIDER_load(nullptr, "legacy"); #endif } CipherFactory::~CipherFactory() -{ -} += default; namespace diff --git a/Crypto/src/CipherImpl.cpp b/Crypto/src/CipherImpl.cpp index b3d77b8836..528d12806e 100644 --- a/Crypto/src/CipherImpl.cpp +++ b/Crypto/src/CipherImpl.cpp @@ -18,6 +18,8 @@ #include "Poco/Buffer.h" #include +#include + namespace Poco { namespace Crypto { @@ -34,7 +36,7 @@ namespace { if (!msg.empty()) msg.append("; "); - msg.append(ERR_error_string(err, 0)); + msg.append(ERR_error_string(err, nullptr)); } throw Poco::IOException(msg); @@ -54,26 +56,26 @@ namespace CryptoTransformImpl( const EVP_CIPHER* pCipher, - const ByteVec& key, - const ByteVec& iv, + ByteVec key, + ByteVec iv, Direction dir); - ~CryptoTransformImpl(); + ~CryptoTransformImpl() override; - std::size_t blockSize() const; - int setPadding(int padding); - std::string getTag(std::size_t tagSize); - void setTag(const std::string& tag); + std::size_t blockSize() const override; + int setPadding(int padding) override; + std::string getTag(std::size_t tagSize) override; + void setTag(const std::string& tag) override; std::streamsize transform( const unsigned char* input, std::streamsize inputLength, unsigned char* output, - std::streamsize outputLength); + std::streamsize outputLength) override; std::streamsize finalize( unsigned char* output, - std::streamsize length); + std::streamsize length) override; private: const EVP_CIPHER* _pCipher; @@ -89,12 +91,12 @@ namespace CryptoTransformImpl::CryptoTransformImpl( const EVP_CIPHER* pCipher, - const ByteVec& key, - const ByteVec& iv, + ByteVec key, + ByteVec iv, Direction dir): _pCipher(pCipher), - _key(key), - _iv(iv) + _key(std::move(key)), + _iv(std::move(iv)) { #if OPENSSL_VERSION_NUMBER >= 0x10100000L _pContext = EVP_CIPHER_CTX_new(); @@ -103,7 +105,7 @@ namespace _pContext, _pCipher, &_key[0], - _iv.empty() ? 0 : &_iv[0], + _iv.empty() ? nullptr : &_iv[0], (dir == DIR_ENCRYPT) ? 1 : 0); #else int rc = EVP_CipherInit( @@ -119,7 +121,7 @@ namespace if (_iv.size() != EVP_CIPHER_iv_length(_pCipher) && EVP_CIPHER_mode(_pCipher) == EVP_CIPH_GCM_MODE) { #if OPENSSL_VERSION_NUMBER >= 0x10100000L - int rc = EVP_CIPHER_CTX_ctrl(_pContext, EVP_CTRL_GCM_SET_IVLEN, static_cast(_iv.size()), NULL); + int rc = EVP_CIPHER_CTX_ctrl(_pContext, EVP_CTRL_GCM_SET_IVLEN, static_cast(_iv.size()), nullptr); #else int rc = EVP_CIPHER_CTX_ctrl(&_context, EVP_CTRL_GCM_SET_IVLEN, static_cast(_iv.size()), NULL); #endif @@ -246,15 +248,14 @@ namespace } -CipherImpl::CipherImpl(const CipherKey& key): - _key(key) +CipherImpl::CipherImpl(CipherKey key): + _key(std::move(key)) { } CipherImpl::~CipherImpl() -{ -} += default; CryptoTransform::Ptr CipherImpl::createEncryptor() diff --git a/Crypto/src/CipherKey.cpp b/Crypto/src/CipherKey.cpp index 41217422bf..dc8c22eeb8 100644 --- a/Crypto/src/CipherKey.cpp +++ b/Crypto/src/CipherKey.cpp @@ -41,10 +41,9 @@ CipherKey::CipherKey(const std::string& name): } -CipherKey::CipherKey(const CipherKey& other): - _pImpl(other._pImpl) -{ -} +CipherKey::CipherKey(const CipherKey& other) + += default; CipherKey::CipherKey(CipherKey&& other) noexcept: @@ -54,8 +53,7 @@ CipherKey::CipherKey(CipherKey&& other) noexcept: CipherKey::~CipherKey() -{ -} += default; CipherKey& CipherKey::operator = (const CipherKey& other) diff --git a/Crypto/src/CipherKeyImpl.cpp b/Crypto/src/CipherKeyImpl.cpp index fbe7423043..fad98e2259 100644 --- a/Crypto/src/CipherKeyImpl.cpp +++ b/Crypto/src/CipherKeyImpl.cpp @@ -20,6 +20,8 @@ #include #include +#include + namespace { @@ -32,7 +34,7 @@ namespace { if (!msg.empty()) msg.append("; "); - msg.append(ERR_error_string(err, 0)); + msg.append(ERR_error_string(err, nullptr)); } throw Poco::IOException(msg); @@ -49,8 +51,8 @@ CipherKeyImpl::CipherKeyImpl(const std::string& name, const std::string& salt, int iterationCount, const std::string& digest): - _pCipher(0), - _pDigest(0), + _pCipher(nullptr), + _pDigest(nullptr), _name(name), _key(), _iv() @@ -74,13 +76,13 @@ CipherKeyImpl::CipherKeyImpl(const std::string& name, CipherKeyImpl::CipherKeyImpl(const std::string& name, - const ByteVec& key, - const ByteVec& iv): - _pCipher(0), - _pDigest(0), + ByteVec key, + ByteVec iv): + _pCipher(nullptr), + _pDigest(nullptr), _name(name), - _key(key), - _iv(iv) + _key(std::move(key)), + _iv(std::move(iv)) { // dummy access to Cipherfactory so that the EVP lib is initialized CipherFactory::defaultFactory(); @@ -92,8 +94,8 @@ CipherKeyImpl::CipherKeyImpl(const std::string& name, CipherKeyImpl::CipherKeyImpl(const std::string& name): - _pCipher(0), - _pDigest(0), + _pCipher(nullptr), + _pDigest(nullptr), _name(name), _key(), _iv() @@ -111,8 +113,7 @@ CipherKeyImpl::CipherKeyImpl(const std::string& name): CipherKeyImpl::~CipherKeyImpl() -{ -} += default; CipherKeyImpl::Mode CipherKeyImpl::mode() const @@ -198,7 +199,7 @@ void CipherKeyImpl::generateKey( int keySize = EVP_BytesToKey( _pCipher, _pDigest ? _pDigest : EVP_md5(), - (salt.empty() ? 0 : saltBytes), + (salt.empty() ? nullptr : saltBytes), reinterpret_cast(password.data()), static_cast(password.size()), iterationCount, diff --git a/Crypto/src/CryptoException.cpp b/Crypto/src/CryptoException.cpp index e30940d229..5763e27130 100644 --- a/Crypto/src/CryptoException.cpp +++ b/Crypto/src/CryptoException.cpp @@ -57,15 +57,11 @@ OpenSSLException::OpenSSLException(const OpenSSLException& exc): CryptoException OpenSSLException::~OpenSSLException() noexcept -{ -} += default; OpenSSLException& OpenSSLException::operator = (const OpenSSLException& exc) -{ - CryptoException::operator = (exc); - return *this; -} += default; const char* OpenSSLException::name() const noexcept diff --git a/Crypto/src/CryptoStream.cpp b/Crypto/src/CryptoStream.cpp index 6892c54106..49966dfa22 100644 --- a/Crypto/src/CryptoStream.cpp +++ b/Crypto/src/CryptoStream.cpp @@ -36,7 +36,7 @@ CryptoStreamBuf::CryptoStreamBuf(std::istream& istr, CryptoTransform::Ptr pTrans Poco::BufferedStreamBuf(bufferSize, std::ios::in), _pTransform(pTransform), _pIstr(&istr), - _pOstr(0), + _pOstr(nullptr), _eof(false), _buffer(static_cast(bufferSize)) { @@ -48,7 +48,7 @@ CryptoStreamBuf::CryptoStreamBuf(std::istream& istr, CryptoTransform::Ptr pTrans CryptoStreamBuf::CryptoStreamBuf(std::ostream& ostr, CryptoTransform::Ptr pTransform, std::streamsize bufferSize): Poco::BufferedStreamBuf(bufferSize, std::ios::out), _pTransform(pTransform), - _pIstr(0), + _pIstr(nullptr), _pOstr(&ostr), _eof(false), _buffer(static_cast(bufferSize)) @@ -76,7 +76,7 @@ void CryptoStreamBuf::close() if (_pIstr) { - _pIstr = 0; + _pIstr = nullptr; } else if (_pOstr) { @@ -84,7 +84,7 @@ void CryptoStreamBuf::close() // sure that we call finalize() only once, even if an exception is // thrown. std::ostream* pOstr = _pOstr; - _pOstr = 0; + _pOstr = nullptr; // Finalize transformation. std::streamsize n = _pTransform->finalize(_buffer.begin(), static_cast(_buffer.size())); @@ -207,8 +207,7 @@ CryptoIOS::CryptoIOS(std::ostream& ostr, CryptoTransform::Ptr pTransform, std::s CryptoIOS::~CryptoIOS() -{ -} += default; CryptoStreamBuf* CryptoIOS::rdbuf() @@ -237,8 +236,7 @@ CryptoInputStream::CryptoInputStream(std::istream& istr, Cipher& cipher, std::st CryptoInputStream::~CryptoInputStream() -{ -} += default; // @@ -261,8 +259,7 @@ CryptoOutputStream::CryptoOutputStream(std::ostream& ostr, Cipher& cipher, std:: CryptoOutputStream::~CryptoOutputStream() -{ -} += default; void CryptoOutputStream::close() @@ -284,8 +281,7 @@ EncryptingInputStream::EncryptingInputStream(std::istream& istr, Cipher& cipher, EncryptingInputStream::~EncryptingInputStream() -{ -} += default; // @@ -301,8 +297,7 @@ EncryptingOutputStream::EncryptingOutputStream(std::ostream& ostr, Cipher& ciphe EncryptingOutputStream::~EncryptingOutputStream() -{ -} += default; void EncryptingOutputStream::close() @@ -324,8 +319,7 @@ DecryptingInputStream::DecryptingInputStream(std::istream& istr, Cipher& cipher, DecryptingInputStream::~DecryptingInputStream() -{ -} += default; // @@ -341,8 +335,7 @@ DecryptingOutputStream::DecryptingOutputStream(std::ostream& ostr, Cipher& ciphe DecryptingOutputStream::~DecryptingOutputStream() -{ -} += default; void DecryptingOutputStream::close() diff --git a/Crypto/src/CryptoTransform.cpp b/Crypto/src/CryptoTransform.cpp index 6ecba2ec8a..ead6447366 100644 --- a/Crypto/src/CryptoTransform.cpp +++ b/Crypto/src/CryptoTransform.cpp @@ -20,13 +20,11 @@ namespace Crypto { CryptoTransform::CryptoTransform() -{ -} += default; CryptoTransform::~CryptoTransform() -{ -} += default; int CryptoTransform::setPadding(int padding) diff --git a/Crypto/src/DigestEngine.cpp b/Crypto/src/DigestEngine.cpp index db5cf6069b..8d56d6e008 100644 --- a/Crypto/src/DigestEngine.cpp +++ b/Crypto/src/DigestEngine.cpp @@ -12,6 +12,8 @@ // +#include + #include "Poco/Crypto/DigestEngine.h" #include "Poco/Exception.h" @@ -20,13 +22,13 @@ namespace Poco { namespace Crypto { -DigestEngine::DigestEngine(const std::string& name): - _name(name), +DigestEngine::DigestEngine(std::string name): + _name(std::move(name)), _pContext(EVP_MD_CTX_create()) { const EVP_MD* md = EVP_get_digestbyname(_name.c_str()); if (!md) throw Poco::NotFoundException(_name); - EVP_DigestInit_ex(_pContext, md, NULL); + EVP_DigestInit_ex(_pContext, md, nullptr); } @@ -60,7 +62,7 @@ void DigestEngine::reset() #endif const EVP_MD* md = EVP_get_digestbyname(_name.c_str()); if (!md) throw Poco::NotFoundException(_name); - EVP_DigestInit_ex(_pContext, md, NULL); + EVP_DigestInit_ex(_pContext, md, nullptr); } diff --git a/Crypto/src/ECDSADigestEngine.cpp b/Crypto/src/ECDSADigestEngine.cpp index ac85a9b75a..81b29f4d06 100644 --- a/Crypto/src/ECDSADigestEngine.cpp +++ b/Crypto/src/ECDSADigestEngine.cpp @@ -18,6 +18,8 @@ #include #include +#include + namespace Poco { namespace Crypto { @@ -28,16 +30,15 @@ namespace Crypto { // -ECDSADigestEngine::ECDSADigestEngine(const ECKey& key, const std::string &name): - _key(key), +ECDSADigestEngine::ECDSADigestEngine(ECKey key, const std::string &name): + _key(std::move(key)), _engine(name) { } ECDSADigestEngine::~ECDSADigestEngine() -{ -} += default; std::size_t ECDSADigestEngine::digestLength() const @@ -114,7 +115,7 @@ ECDSASignature::ECDSASignature(const ByteVec& derSignature) poco_assert (!derSignature.empty()); const unsigned char* p = &derSignature[0]; - _pSig = d2i_ECDSA_SIG(0, &p, static_cast(derSignature.size())); + _pSig = d2i_ECDSA_SIG(nullptr, &p, static_cast(derSignature.size())); if (!_pSig) throw OpenSSLException(); } @@ -131,12 +132,12 @@ ECDSASignature::ECDSASignature(const ByteVec& rawR, const ByteVec& rawS): { #if OPENSSL_VERSION_NUMBER >= 0x10100000L ECDSA_SIG_set0(_pSig, - BN_bin2bn(&rawR[0], static_cast(rawR.size()), 0), - BN_bin2bn(&rawS[0], static_cast(rawS.size()), 0)); - const BIGNUM* pR = 0; - const BIGNUM* pS = 0; + BN_bin2bn(&rawR[0], static_cast(rawR.size()), nullptr), + BN_bin2bn(&rawS[0], static_cast(rawS.size()), nullptr)); + const BIGNUM* pR = nullptr; + const BIGNUM* pS = nullptr; ECDSA_SIG_get0(_pSig, &pR, &pS); - if (pR == 0 || pS == 0) + if (pR == nullptr || pS == nullptr) throw Poco::Crypto::CryptoException("failed to decode R and S values"); #else if (!BN_bin2bn(&rawR[0], rawR.size(), _pSig->r)) @@ -161,7 +162,7 @@ ECDSASignature::~ECDSASignature() ECDSASignature::ByteVec ECDSASignature::toDER() const { - int size = i2d_ECDSA_SIG(_pSig, 0); + int size = i2d_ECDSA_SIG(_pSig, nullptr); if (size > 0) { ByteVec buffer(size); diff --git a/Crypto/src/ECKey.cpp b/Crypto/src/ECKey.cpp index 105a7d3c3d..7d313305b0 100644 --- a/Crypto/src/ECKey.cpp +++ b/Crypto/src/ECKey.cpp @@ -57,10 +57,9 @@ ECKey::ECKey(std::istream* pPublicKeyStream, std::istream* pPrivateKeyStream, co } -ECKey::ECKey(const ECKey& other): - KeyPair(other) -{ -} +ECKey::ECKey(const ECKey& other) + += default; ECKey::ECKey(ECKey&& other) noexcept: @@ -70,15 +69,11 @@ ECKey::ECKey(ECKey&& other) noexcept: ECKey::~ECKey() -{ -} += default; ECKey& ECKey::operator = (const ECKey& other) -{ - KeyPair::operator = (other); - return *this; -} += default; ECKey& ECKey::operator = (ECKey&& other) noexcept diff --git a/Crypto/src/ECKeyImpl.cpp b/Crypto/src/ECKeyImpl.cpp index e11b134ca3..2a89d3694e 100644 --- a/Crypto/src/ECKeyImpl.cpp +++ b/Crypto/src/ECKeyImpl.cpp @@ -38,7 +38,7 @@ ECKeyImpl::ECKeyImpl(const EVPPKey& key): ECKeyImpl::ECKeyImpl(const X509Certificate& cert): KeyPairImpl("ec", KT_EC_IMPL), - _pEC(0) + _pEC(nullptr) { const X509* pCert = cert.certificate(); if (pCert) @@ -78,7 +78,7 @@ ECKeyImpl::ECKeyImpl(int curve): ECKeyImpl::ECKeyImpl(const std::string& publicKeyFile, const std::string& privateKeyFile, - const std::string& privateKeyPassphrase): KeyPairImpl("ec", KT_EC_IMPL), _pEC(0) + const std::string& privateKeyPassphrase): KeyPairImpl("ec", KT_EC_IMPL), _pEC(nullptr) { if (EVPPKey::loadKey(&_pEC, PEM_read_PrivateKey, EVP_PKEY_get1_EC_KEY, privateKeyFile, privateKeyPassphrase)) { @@ -101,7 +101,7 @@ ECKeyImpl::ECKeyImpl(const std::string& publicKeyFile, ECKeyImpl::ECKeyImpl(std::istream* pPublicKeyStream, std::istream* pPrivateKeyStream, - const std::string& privateKeyPassphrase): KeyPairImpl("ec", KT_EC_IMPL), _pEC(0) + const std::string& privateKeyPassphrase): KeyPairImpl("ec", KT_EC_IMPL), _pEC(nullptr) { if (EVPPKey::loadKey(&_pEC, PEM_read_bio_PrivateKey, EVP_PKEY_get1_EC_KEY, pPrivateKeyStream, privateKeyPassphrase)) { @@ -141,7 +141,7 @@ void ECKeyImpl::freeEC() if (_pEC) { EC_KEY_free(_pEC); - _pEC = 0; + _pEC = nullptr; } } @@ -181,7 +181,7 @@ int ECKeyImpl::groupId() const std::string ECKeyImpl::getCurveName(int nid) { std::string curveName; - size_t len = EC_get_builtin_curves(NULL, 0); + size_t len = EC_get_builtin_curves(nullptr, 0); EC_builtin_curve* pCurves = (EC_builtin_curve*) OPENSSL_malloc(sizeof(EC_builtin_curve) * len); if (!pCurves) return curveName; @@ -206,7 +206,7 @@ std::string ECKeyImpl::getCurveName(int nid) int ECKeyImpl::getCurveNID(std::string& name) { std::string curveName; - size_t len = EC_get_builtin_curves(NULL, 0); + size_t len = EC_get_builtin_curves(nullptr, 0); EC_builtin_curve* pCurves = (EC_builtin_curve*)OPENSSL_malloc(static_cast(sizeof(EC_builtin_curve) * len)); if (!pCurves) return -1; diff --git a/Crypto/src/EVPCipherImpl.cpp b/Crypto/src/EVPCipherImpl.cpp index 76385c53a2..c50cc687d1 100644 --- a/Crypto/src/EVPCipherImpl.cpp +++ b/Crypto/src/EVPCipherImpl.cpp @@ -16,9 +16,10 @@ #include "Poco/Crypto/CryptoTransform.h" #include "Poco/Exception.h" #include "Poco/Logger.h" +#include #include #include -#include +#include namespace Poco { @@ -33,7 +34,7 @@ namespace while ((err = ERR_get_error())) { if (!msg.empty()) msg.append("; "); - msg.append(ERR_error_string(err, 0)); + msg.append(ERR_error_string(err, nullptr)); } throw Poco::IOException(msg); @@ -43,7 +44,7 @@ namespace { public: EVPPKeyContext() = delete; - EVPPKeyContext(const EVP_PKEY* pEVP) : _pCtx(EVP_PKEY_CTX_new(const_cast(pEVP), NULL)) + EVPPKeyContext(const EVP_PKEY* pEVP) : _pCtx(EVP_PKEY_CTX_new(const_cast(pEVP), nullptr)) { if (!_pCtx) { @@ -73,7 +74,7 @@ namespace _pEVP(pEVP), _pCtx(_pEVP), _pos(0), - _pBuf(0) + _pBuf(nullptr) { std::string fmt = "EVPEncryptImpl():%s()"; poco_check_ptr(_pEVP); @@ -90,27 +91,27 @@ namespace _pBuf = new unsigned char[_blockSize]; } - ~EVPEncryptImpl() + ~EVPEncryptImpl() override { delete [] _pBuf; } - std::size_t blockSize() const + std::size_t blockSize() const override { return _blockSize; } - std::string getTag(std::size_t) + std::string getTag(std::size_t) override { return ""; } - void setTag(const std::string&) + void setTag(const std::string&) override { } std::streamsize transform(const unsigned char* input, std::streamsize inputLength, - unsigned char* output, std::streamsize outputLength) + unsigned char* output, std::streamsize outputLength) override { std::string fmt = "EVPEncryptImpl::transform():%s()"; std::streamsize maxSize = static_cast(maxDataSize(input, inputLength)); @@ -126,7 +127,7 @@ namespace { poco_assert (outputLength >= evpSize); std::size_t outLen; - if (EVP_PKEY_encrypt(_pCtx, NULL, &outLen, _pBuf, static_cast(maxSize)) <= 0) + if (EVP_PKEY_encrypt(_pCtx, nullptr, &outLen, _pBuf, static_cast(maxSize)) <= 0) throwError(Poco::format(fmt, std::string("EVP_PKEY_encrypt(NULL)"))); if (EVP_PKEY_encrypt(_pCtx, output, &outLen, _pBuf, static_cast(maxSize)) <= 0) throwError(Poco::format(fmt, std::string("EVP_PKEY_encrypt"))); @@ -148,7 +149,7 @@ namespace return rc; } - std::streamsize finalize(unsigned char* output, std::streamsize length) + std::streamsize finalize(unsigned char* output, std::streamsize length) override { poco_assert (length >= blockSize()); poco_assert (_pos <= maxDataSize(output, length)); @@ -156,7 +157,7 @@ namespace std::size_t outLen = 0; if (_pos > 0) { - if (EVP_PKEY_encrypt(_pCtx, NULL, &outLen, _pBuf, static_cast(_pos)) <= 0) + if (EVP_PKEY_encrypt(_pCtx, nullptr, &outLen, _pBuf, static_cast(_pos)) <= 0) throwError(Poco::format(fmt, std::string("EVP_PKEY_encrypt"))); if (EVP_PKEY_encrypt(_pCtx, output, &outLen, _pBuf, static_cast(_pos)) <= 0) throwError(Poco::format(fmt, std::string("EVP_PKEY_encrypt"))); @@ -169,7 +170,7 @@ namespace { std::string fmt = "EVPEncryptImpl::maxDataSize():%s()"; std::size_t outLength = 0; - if (EVP_PKEY_encrypt(_pCtx, NULL, &outLength, pIO, length) <= 0) + if (EVP_PKEY_encrypt(_pCtx, nullptr, &outLength, pIO, length) <= 0) throwError(Poco::format(fmt, std::string("EVP_PKEY_encrypt"))); return outLength; } @@ -189,7 +190,7 @@ namespace _pEVP(pEVP), _pCtx(_pEVP), _pos(0), - _pBuf(0) + _pBuf(nullptr) { std::string fmt = "EVPDecryptImpl():%s()"; poco_check_ptr(_pEVP); @@ -203,27 +204,27 @@ namespace _pBuf = new unsigned char[_blockSize]; } - ~EVPDecryptImpl() + ~EVPDecryptImpl() override { delete [] _pBuf; } - std::size_t blockSize() const + std::size_t blockSize() const override { return _blockSize; } - std::string getTag(std::size_t) + std::string getTag(std::size_t) override { return ""; } - void setTag(const std::string&) + void setTag(const std::string&) override { } std::streamsize transform(const unsigned char* input, std::streamsize inputLength, - unsigned char* output, std::streamsize outputLength) + unsigned char* output, std::streamsize outputLength) override { std::string fmt = "EVPDecryptImpl::transform():%s()"; std::streamsize evpSize = static_cast(_blockSize); @@ -237,7 +238,7 @@ namespace if (missing == 0) { std::size_t outLen = 0; - if (EVP_PKEY_decrypt(_pCtx, NULL, &outLen, _pBuf, static_cast(_pos)) <= 0) + if (EVP_PKEY_decrypt(_pCtx, nullptr, &outLen, _pBuf, static_cast(_pos)) <= 0) throwError(Poco::format(fmt, std::string("EVP_PKEY_decrypt(NULL)"))); if (EVP_PKEY_decrypt(_pCtx, output, &outLen, _pBuf, static_cast(_pos)) <= 0) throwError(Poco::format(fmt, std::string("EVP_PKEY_decrypt"))); @@ -258,12 +259,12 @@ namespace return rc; } - std::streamsize finalize(unsigned char* output, std::streamsize length) + std::streamsize finalize(unsigned char* output, std::streamsize length) override { poco_assert (length >= _blockSize); std::string fmt = "EVPDecryptImpl::finalize():%s()"; std::size_t outLen = 0; - if (EVP_PKEY_decrypt(_pCtx, NULL, &outLen, _pBuf, static_cast(_pos)) <= 0) + if (EVP_PKEY_decrypt(_pCtx, nullptr, &outLen, _pBuf, static_cast(_pos)) <= 0) throwError(Poco::format(fmt, std::string("EVP_PKEY_decrypt(NULL)"))); poco_assert (length >= outLen); if (_pos > 0) @@ -284,15 +285,14 @@ namespace } -EVPCipherImpl::EVPCipherImpl(const EVPPKey& key): - _key(key) +EVPCipherImpl::EVPCipherImpl(EVPPKey key): + _key(std::move(key)) { } EVPCipherImpl::~EVPCipherImpl() -{ -} += default; CryptoTransform::Ptr EVPCipherImpl::createEncryptor() diff --git a/Crypto/src/EVPPKey.cpp b/Crypto/src/EVPPKey.cpp index f4fb3a2ec5..6a36d1b8ad 100644 --- a/Crypto/src/EVPPKey.cpp +++ b/Crypto/src/EVPPKey.cpp @@ -39,7 +39,7 @@ const std::map EVPPKey::KNOWN_TYPES = }; -EVPPKey::EVPPKey(const std::string& ecCurveName): _pEVPPKey(0) +EVPPKey::EVPPKey(const std::string& ecCurveName): _pEVPPKey(nullptr) { newECKey(ecCurveName.c_str()); poco_check_ptr(_pEVPPKey); @@ -47,7 +47,7 @@ EVPPKey::EVPPKey(const std::string& ecCurveName): _pEVPPKey(0) } -EVPPKey::EVPPKey(const char* ecCurveName): _pEVPPKey(0) +EVPPKey::EVPPKey(const char* ecCurveName): _pEVPPKey(nullptr) { newECKey(ecCurveName); poco_check_ptr(_pEVPPKey); @@ -138,7 +138,7 @@ void EVPPKey::setKeyFromParameters(OSSL_PARAM* parameters) throw OpenSSLException("EVPPKey cannot init create key"); } - if (_pEVPPKey != 0) EVP_PKEY_free(_pEVPPKey); + if (_pEVPPKey != nullptr) EVP_PKEY_free(_pEVPPKey); if (EVP_PKEY_fromdata(ctx, &_pEVPPKey, EVP_PKEY_KEYPAIR, parameters) <= 0) { OSSL_PARAM_free(parameters); @@ -150,7 +150,7 @@ void EVPPKey::setKeyFromParameters(OSSL_PARAM* parameters) } -EVPPKey::EVPPKey(const std::vector* public_key, const std::vector* private_key, unsigned long exponent, int type) : _pEVPPKey(0) +EVPPKey::EVPPKey(const std::vector* public_key, const std::vector* private_key, unsigned long exponent, int type) : _pEVPPKey(nullptr) { if ((EVP_PKEY_RSA != type) || (RSA_F4 != exponent)) { @@ -175,10 +175,10 @@ EVPPKey::EVPPKey(const std::vector* public_key, const std::vector #if OPENSSL_VERSION_NUMBER >= 0x10000000L -EVPPKey::EVPPKey(int type, int param): _pEVPPKey(0) +EVPPKey::EVPPKey(int type, int param): _pEVPPKey(nullptr) { - EVP_PKEY_CTX *pCtx = EVP_PKEY_CTX_new_id(type, NULL); - if (NULL == pCtx) + EVP_PKEY_CTX *pCtx = EVP_PKEY_CTX_new_id(type, nullptr); + if (nullptr == pCtx) { std::string msg = Poco::format( "EVPPKey(%d, %d):EVP_PKEY_CTX_new_id()\n", type, param); @@ -236,7 +236,7 @@ EVPPKey::EVPPKey(int type, int param): _pEVPPKey(0) #endif // OPENSSL_VERSION_NUMBER >= 0x10000000L -EVPPKey::EVPPKey(EVP_PKEY* pEVPPKey): _pEVPPKey(0) +EVPPKey::EVPPKey(EVP_PKEY* pEVPPKey): _pEVPPKey(nullptr) { duplicate(pEVPPKey, &_pEVPPKey); poco_check_ptr(_pEVPPKey); @@ -246,16 +246,16 @@ EVPPKey::EVPPKey(EVP_PKEY* pEVPPKey): _pEVPPKey(0) EVPPKey::EVPPKey(const std::string& publicKeyFile, const std::string& privateKeyFile, - const std::string& privateKeyPassphrase): _pEVPPKey(0) + const std::string& privateKeyPassphrase): _pEVPPKey(nullptr) { - if (loadKey(&_pEVPPKey, PEM_read_PrivateKey, (EVP_PKEY_get_Key_fn)0, privateKeyFile, privateKeyPassphrase)) + if (loadKey(&_pEVPPKey, PEM_read_PrivateKey, (EVP_PKEY_get_Key_fn)nullptr, privateKeyFile, privateKeyPassphrase)) { poco_check_ptr(_pEVPPKey); return; // private key is enough } // no private key, this must be public key only, otherwise throw - if (!loadKey(&_pEVPPKey, PEM_read_PUBKEY, (EVP_PKEY_get_Key_fn)0, publicKeyFile)) + if (!loadKey(&_pEVPPKey, PEM_read_PUBKEY, (EVP_PKEY_get_Key_fn)nullptr, publicKeyFile)) { std::string msg = "EVPPKey(const string&, const string&, const string&)\n"; throw OpenSSLException(getError(msg)); @@ -267,16 +267,16 @@ EVPPKey::EVPPKey(const std::string& publicKeyFile, EVPPKey::EVPPKey(std::istream* pPublicKeyStream, std::istream* pPrivateKeyStream, - const std::string& privateKeyPassphrase): _pEVPPKey(0) + const std::string& privateKeyPassphrase): _pEVPPKey(nullptr) { - if (loadKey(&_pEVPPKey, PEM_read_bio_PrivateKey, (EVP_PKEY_get_Key_fn)0, pPrivateKeyStream, privateKeyPassphrase)) + if (loadKey(&_pEVPPKey, PEM_read_bio_PrivateKey, (EVP_PKEY_get_Key_fn)nullptr, pPrivateKeyStream, privateKeyPassphrase)) { poco_check_ptr(_pEVPPKey); return; // private key is enough } // no private key, this must be public key only, otherwise throw - if (!loadKey(&_pEVPPKey, PEM_read_bio_PUBKEY, (EVP_PKEY_get_Key_fn)0, pPublicKeyStream)) + if (!loadKey(&_pEVPPKey, PEM_read_bio_PUBKEY, (EVP_PKEY_get_Key_fn)nullptr, pPublicKeyStream)) { std::string msg = "EVPPKey(istream* ,istream* const string&)\n"; throw OpenSSLException(getError(msg)); @@ -416,13 +416,13 @@ void EVPPKey::save(const std::string& publicKeyFile, const std::string& privateK int rc = 0; if (privateKeyPassphrase.empty()) { - rc = PEM_write_bio_PrivateKey(bio, _pEVPPKey, 0, 0, 0, 0, 0); + rc = PEM_write_bio_PrivateKey(bio, _pEVPPKey, nullptr, nullptr, 0, nullptr, nullptr); } else { rc = PEM_write_bio_PrivateKey(bio, _pEVPPKey, EVP_des_ede3_cbc(), reinterpret_cast(const_cast(privateKeyPassphrase.c_str())), - static_cast(privateKeyPassphrase.length()), 0, 0); + static_cast(privateKeyPassphrase.length()), nullptr, nullptr); } if (!rc) { @@ -483,11 +483,11 @@ void EVPPKey::save(std::ostream* pPublicKeyStream, std::ostream* pPrivateKeyStre } int rc = 0; if (privateKeyPassphrase.empty()) - rc = PEM_write_bio_PrivateKey(bio, _pEVPPKey, 0, 0, 0, 0, 0); + rc = PEM_write_bio_PrivateKey(bio, _pEVPPKey, nullptr, nullptr, 0, nullptr, nullptr); else rc = PEM_write_bio_PrivateKey(bio, _pEVPPKey, EVP_des_ede3_cbc(), reinterpret_cast(const_cast(privateKeyPassphrase.c_str())), - static_cast(privateKeyPassphrase.length()), 0, 0); + static_cast(privateKeyPassphrase.length()), nullptr, nullptr); if (!rc) { std::string msg = "EVPPKey::save(ostream*, ostream*, const string&)\n"; diff --git a/Crypto/src/Envelope.cpp b/Crypto/src/Envelope.cpp index c74fc25da8..6afe77708b 100644 --- a/Crypto/src/Envelope.cpp +++ b/Crypto/src/Envelope.cpp @@ -71,7 +71,7 @@ void Envelope::addKey(const EVPPKey& key) const Envelope::ByteVec& Envelope::seal(const ByteVec& plainData) { - std::vector pEncKeys(_encKeys.size(), 0); + std::vector pEncKeys(_encKeys.size(), nullptr); std::vector encKeysSizes(_encKeys.size(), 0); int i = 0; for (const auto& k : _encKeys) @@ -123,7 +123,7 @@ const Envelope::ByteVec& Envelope::seal(const std::string& plainText) Envelope::ByteVec Envelope::open(const EVPPKey& privKey, const ByteVec& encKey, const ByteVec& iv) { - if (iv.size() > 0) _iv = iv; + if (!iv.empty()) _iv = iv; int encContentLen = static_cast(_encContent.size()); int blockSz = blockSize(); int mod = encContentLen % blockSz; @@ -159,7 +159,7 @@ void Envelope::handleErrors(std::string&& msg) while ((err = ERR_get_error())) { if (!msg.empty()) msg.append("\n"); - msg.append(ERR_error_string(err, 0)); + msg.append(ERR_error_string(err, nullptr)); } throw CryptoException(msg); } diff --git a/Crypto/src/KeyPair.cpp b/Crypto/src/KeyPair.cpp index 25dc4f9279..ec26df7eb2 100644 --- a/Crypto/src/KeyPair.cpp +++ b/Crypto/src/KeyPair.cpp @@ -15,21 +15,22 @@ #include "Poco/Crypto/KeyPair.h" #include +#include + namespace Poco { namespace Crypto { KeyPair::KeyPair(KeyPairImpl::Ptr pKeyPairImpl): - _pImpl(pKeyPairImpl) + _pImpl(std::move(pKeyPairImpl)) { } -KeyPair::KeyPair(const KeyPair& other): - _pImpl(other._pImpl) -{ -} +KeyPair::KeyPair(const KeyPair& other) + += default; KeyPair::KeyPair(KeyPair&& other) noexcept: @@ -39,8 +40,7 @@ KeyPair::KeyPair(KeyPair&& other) noexcept: KeyPair::~KeyPair() -{ -} += default; KeyPair& KeyPair::operator = (const KeyPair& other) diff --git a/Crypto/src/KeyPairImpl.cpp b/Crypto/src/KeyPairImpl.cpp index c782f04270..f24311ecbf 100644 --- a/Crypto/src/KeyPairImpl.cpp +++ b/Crypto/src/KeyPairImpl.cpp @@ -13,6 +13,8 @@ // +#include + #include "Poco/Crypto/KeyPairImpl.h" @@ -20,16 +22,15 @@ namespace Poco { namespace Crypto { -KeyPairImpl::KeyPairImpl(const std::string& name, Type type): - _name(name), +KeyPairImpl::KeyPairImpl(std::string name, Type type): + _name(std::move(name)), _type(type) { } KeyPairImpl::~KeyPairImpl() -{ -} += default; } } // namespace Poco::Crypto diff --git a/Crypto/src/OpenSSLInitializer.cpp b/Crypto/src/OpenSSLInitializer.cpp index 0c52a0a3d4..8a0d173f94 100644 --- a/Crypto/src/OpenSSLInitializer.cpp +++ b/Crypto/src/OpenSSLInitializer.cpp @@ -66,8 +66,8 @@ Poco::FastMutex* OpenSSLInitializer::_mutexes(0); #endif #if OPENSSL_VERSION_NUMBER >= 0x30000000L -OSSL_PROVIDER* OpenSSLInitializer::_defaultProvider(0); -OSSL_PROVIDER* OpenSSLInitializer::_legacyProvider(0); +OSSL_PROVIDER* OpenSSLInitializer::_defaultProvider(nullptr); +OSSL_PROVIDER* OpenSSLInitializer::_legacyProvider(nullptr); #endif @@ -95,7 +95,7 @@ void OpenSSLInitializer::initialize() if (++_rc == 1) { #if OPENSSL_VERSION_NUMBER >= 0x10100000L - CONF_modules_load(NULL, NULL, 0); + CONF_modules_load(nullptr, nullptr, 0); #else OPENSSL_config(NULL); #endif @@ -131,12 +131,12 @@ void OpenSSLInitializer::initialize() #if OPENSSL_VERSION_NUMBER >= 0x30000000L if (!_defaultProvider) { - _defaultProvider = OSSL_PROVIDER_load(NULL, "default"); + _defaultProvider = OSSL_PROVIDER_load(nullptr, "default"); if (!_defaultProvider) throw CryptoException("Failed to load OpenSSL default provider"); } if (!_legacyProvider) { - _legacyProvider = OSSL_PROVIDER_load(NULL, "legacy"); + _legacyProvider = OSSL_PROVIDER_load(nullptr, "legacy"); // Note: use haveLegacyProvider() to check if legacy provider has been loaded } #endif diff --git a/Crypto/src/PKCS12Container.cpp b/Crypto/src/PKCS12Container.cpp index da961550cf..322dc98c10 100644 --- a/Crypto/src/PKCS12Container.cpp +++ b/Crypto/src/PKCS12Container.cpp @@ -21,15 +21,16 @@ #include "Poco/Crypto/PKCS12Container.h" #include "Poco/NumberFormatter.h" #include "Poco/StreamCopier.h" -#include +#include #include +#include namespace Poco { namespace Crypto { -PKCS12Container::PKCS12Container(std::istream& istr, const std::string& password): _pKey(0) +PKCS12Container::PKCS12Container(std::istream& istr, const std::string& password): _pKey(nullptr) { std::ostringstream ostr; Poco::StreamCopier::copyStream(istr, ostr); @@ -38,7 +39,7 @@ PKCS12Container::PKCS12Container(std::istream& istr, const std::string& password BIO *pBIO = BIO_new_mem_buf(const_cast(cont.data()), static_cast(cont.size())); if (pBIO) { - PKCS12* pPKCS12 = 0; + PKCS12* pPKCS12 = nullptr; d2i_PKCS12_bio(pBIO, &pPKCS12); BIO_free(pBIO); if (!pPKCS12) throw OpenSSLException("PKCS12Container(istream&, const string&)"); @@ -51,12 +52,12 @@ PKCS12Container::PKCS12Container(std::istream& istr, const std::string& password } -PKCS12Container::PKCS12Container(const std::string& path, const std::string& password): _pKey(0) +PKCS12Container::PKCS12Container(const std::string& path, const std::string& password): _pKey(nullptr) { FILE* pFile = fopen(path.c_str(), "rb"); if (pFile) { - PKCS12* pPKCS12 = d2i_PKCS12_fp(pFile, NULL); + PKCS12* pPKCS12 = d2i_PKCS12_fp(pFile, nullptr); fclose (pFile); if (!pPKCS12) throw OpenSSLException("PKCS12Container(const string&, const string&)"); load(pPKCS12, password); @@ -95,7 +96,7 @@ PKCS12Container& PKCS12Container::operator = (const PKCS12Container& other) { if (_pKey) EVP_PKEY_free(_pKey); _pKey = EVPPKey::duplicate(other._pKey, &_pKey); - _pX509Cert.reset(new X509Certificate(*other._pX509Cert)); + _pX509Cert = std::make_unique(*other._pX509Cert); _caCertList = other._caCertList; _caCertNames = other._caCertNames; _pkcsFriendlyName = other._pkcsFriendlyName; @@ -145,13 +146,13 @@ void PKCS12Container::load(PKCS12* pPKCS12, const std::string& password) { if (pPKCS12) { - X509* pCert = 0; - STACK_OF(X509)* pCA = 0; + X509* pCert = nullptr; + STACK_OF(X509)* pCA = nullptr; if (PKCS12_parse(pPKCS12, password.c_str(), &_pKey, &pCert, &pCA)) { if (pCert) { - _pX509Cert.reset(new X509Certificate(pCert, true)); + _pX509Cert = std::make_unique(pCert, true); _pkcsFriendlyName = extractFriendlyName(pCert); X509_free(pCert); } diff --git a/Crypto/src/RSACipherImpl.cpp b/Crypto/src/RSACipherImpl.cpp index f04e4a22b9..340c31b84a 100644 --- a/Crypto/src/RSACipherImpl.cpp +++ b/Crypto/src/RSACipherImpl.cpp @@ -15,9 +15,10 @@ #include "Poco/Crypto/RSACipherImpl.h" #include "Poco/Crypto/CryptoTransform.h" #include "Poco/Exception.h" +#include #include #include -#include +#include namespace Poco { @@ -35,7 +36,7 @@ namespace { if (!msg.empty()) msg.append("; "); - msg.append(ERR_error_string(err, 0)); + msg.append(ERR_error_string(err, nullptr)); } throw Poco::IOException(msg); @@ -63,20 +64,20 @@ namespace { public: RSAEncryptImpl(const RSA* pRSA, RSAPaddingMode paddingMode); - ~RSAEncryptImpl(); + ~RSAEncryptImpl() override; - std::size_t blockSize() const; + std::size_t blockSize() const override; std::size_t maxDataSize() const; - std::string getTag(std::size_t); - void setTag(const std::string&); + std::string getTag(std::size_t) override; + void setTag(const std::string&) override; std::streamsize transform( const unsigned char* input, std::streamsize inputLength, unsigned char* output, - std::streamsize outputLength); + std::streamsize outputLength) override; - std::streamsize finalize(unsigned char* output, std::streamsize length); + std::streamsize finalize(unsigned char* output, std::streamsize length) override; private: const RSA* _pRSA; @@ -90,7 +91,7 @@ namespace _pRSA(pRSA), _paddingMode(paddingMode), _pos(0), - _pBuf(0) + _pBuf(nullptr) { _pBuf = new unsigned char[blockSize()]; } @@ -199,21 +200,21 @@ namespace { public: RSADecryptImpl(const RSA* pRSA, RSAPaddingMode paddingMode); - ~RSADecryptImpl(); + ~RSADecryptImpl() override; - std::size_t blockSize() const; - std::string getTag(std::size_t); - void setTag(const std::string&); + std::size_t blockSize() const override; + std::string getTag(std::size_t) override; + void setTag(const std::string&) override; std::streamsize transform( const unsigned char* input, std::streamsize inputLength, unsigned char* output, - std::streamsize outputLength); + std::streamsize outputLength) override; std::streamsize finalize( unsigned char* output, - std::streamsize length); + std::streamsize length) override; private: const RSA* _pRSA; @@ -227,7 +228,7 @@ namespace _pRSA(pRSA), _paddingMode(paddingMode), _pos(0), - _pBuf(0) + _pBuf(nullptr) { _pBuf = new unsigned char[blockSize()]; } @@ -314,16 +315,15 @@ namespace } -RSACipherImpl::RSACipherImpl(const RSAKey& key, RSAPaddingMode paddingMode): - _key(key), +RSACipherImpl::RSACipherImpl(RSAKey key, RSAPaddingMode paddingMode): + _key(std::move(key)), _paddingMode(paddingMode) { } RSACipherImpl::~RSACipherImpl() -{ -} += default; CryptoTransform::Ptr RSACipherImpl::createEncryptor() diff --git a/Crypto/src/RSADigestEngine.cpp b/Crypto/src/RSADigestEngine.cpp index 9786eec3fb..67e15c4c40 100644 --- a/Crypto/src/RSADigestEngine.cpp +++ b/Crypto/src/RSADigestEngine.cpp @@ -15,27 +15,28 @@ #include "Poco/Crypto/RSADigestEngine.h" #include +#include + namespace Poco { namespace Crypto { -RSADigestEngine::RSADigestEngine(const RSAKey& key, DigestType digestType): - _key(key), +RSADigestEngine::RSADigestEngine(RSAKey key, DigestType digestType): + _key(std::move(key)), _engine(digestType == DIGEST_MD5 ? "MD5" : "SHA1") { } -RSADigestEngine::RSADigestEngine(const RSAKey& key, const std::string &name): - _key(key), +RSADigestEngine::RSADigestEngine(RSAKey key, const std::string &name): + _key(std::move(key)), _engine(name) { } RSADigestEngine::~RSADigestEngine() -{ -} += default; std::size_t RSADigestEngine::digestLength() const diff --git a/Crypto/src/RSAKey.cpp b/Crypto/src/RSAKey.cpp index ef53be9b23..6ab7f01156 100644 --- a/Crypto/src/RSAKey.cpp +++ b/Crypto/src/RSAKey.cpp @@ -56,10 +56,9 @@ RSAKey::RSAKey(std::istream* pPublicKeyStream, std::istream* pPrivateKeyStream, } -RSAKey::RSAKey(const RSAKey& other): - KeyPair(other) -{ -} +RSAKey::RSAKey(const RSAKey& other) + += default; RSAKey::RSAKey(RSAKey&& other) noexcept: @@ -69,15 +68,11 @@ RSAKey::RSAKey(RSAKey&& other) noexcept: RSAKey::~RSAKey() -{ -} += default; RSAKey& RSAKey::operator = (const RSAKey& other) -{ - KeyPair::operator = (other); - return *this; -} += default; RSAKey& RSAKey::operator = (RSAKey&& other) noexcept diff --git a/Crypto/src/RSAKeyImpl.cpp b/Crypto/src/RSAKeyImpl.cpp index 58396ccb44..785dd70511 100644 --- a/Crypto/src/RSAKeyImpl.cpp +++ b/Crypto/src/RSAKeyImpl.cpp @@ -38,7 +38,7 @@ RSAKeyImpl::RSAKeyImpl(const EVPPKey& key): RSAKeyImpl::RSAKeyImpl(const X509Certificate& cert): KeyPairImpl("rsa", KT_RSA_IMPL), - _pRSA(0) + _pRSA(nullptr) { const X509* pCert = cert.certificate(); EVP_PKEY* pKey = X509_get_pubkey(const_cast(pCert)); @@ -54,7 +54,7 @@ RSAKeyImpl::RSAKeyImpl(const X509Certificate& cert): RSAKeyImpl::RSAKeyImpl(const PKCS12Container& cont): KeyPairImpl("rsa", KT_RSA_IMPL), - _pRSA(0) + _pRSA(nullptr) { EVPPKey key = cont.getKey(); _pRSA = EVP_PKEY_get1_RSA(key); @@ -62,16 +62,16 @@ RSAKeyImpl::RSAKeyImpl(const PKCS12Container& cont): RSAKeyImpl::RSAKeyImpl(int keyLength, unsigned long exponent): KeyPairImpl("rsa", KT_RSA_IMPL), - _pRSA(0) + _pRSA(nullptr) { _pRSA = RSA_new(); int ret = 0; - BIGNUM* bn = 0; + BIGNUM* bn = nullptr; try { bn = BN_new(); BN_set_word(bn, exponent); - ret = RSA_generate_key_ex(_pRSA, keyLength, bn, 0); + ret = RSA_generate_key_ex(_pRSA, keyLength, bn, nullptr); BN_free(bn); } catch (...) @@ -86,9 +86,9 @@ RSAKeyImpl::RSAKeyImpl(int keyLength, unsigned long exponent): KeyPairImpl("rsa" RSAKeyImpl::RSAKeyImpl(const std::string& publicKeyFile, const std::string& privateKeyFile, const std::string& privateKeyPassphrase): KeyPairImpl("rsa", KT_RSA_IMPL), - _pRSA(0) + _pRSA(nullptr) { - poco_assert_dbg(_pRSA == 0); + poco_assert_dbg(_pRSA == nullptr); _pRSA = RSA_new(); if (!publicKeyFile.empty()) @@ -98,14 +98,14 @@ RSAKeyImpl::RSAKeyImpl(const std::string& publicKeyFile, int rc = BIO_read_filename(bio, publicKeyFile.c_str()); if (rc) { - RSA* pubKey = PEM_read_bio_RSAPublicKey(bio, &_pRSA, 0, 0); + RSA* pubKey = PEM_read_bio_RSAPublicKey(bio, &_pRSA, nullptr, nullptr); if (!pubKey) { int rc = BIO_reset(bio); // BIO_reset() normally returns 1 for success and 0 or -1 for failure. // File BIOs are an exception, they return 0 for success and -1 for failure. if (rc != 0) throw Poco::FileException("Failed to load public key", publicKeyFile); - pubKey = PEM_read_bio_RSA_PUBKEY(bio, &_pRSA, 0, 0); + pubKey = PEM_read_bio_RSA_PUBKEY(bio, &_pRSA, nullptr, nullptr); } BIO_free(bio); if (!pubKey) @@ -128,11 +128,11 @@ RSAKeyImpl::RSAKeyImpl(const std::string& publicKeyFile, int rc = BIO_read_filename(bio, privateKeyFile.c_str()); if (rc) { - RSA* privKey = 0; + RSA* privKey = nullptr; if (privateKeyPassphrase.empty()) - privKey = PEM_read_bio_RSAPrivateKey(bio, &_pRSA, 0, 0); + privKey = PEM_read_bio_RSAPrivateKey(bio, &_pRSA, nullptr, nullptr); else - privKey = PEM_read_bio_RSAPrivateKey(bio, &_pRSA, 0, const_cast(privateKeyPassphrase.c_str())); + privKey = PEM_read_bio_RSAPrivateKey(bio, &_pRSA, nullptr, const_cast(privateKeyPassphrase.c_str())); BIO_free(bio); if (!privKey) { @@ -152,9 +152,9 @@ RSAKeyImpl::RSAKeyImpl(const std::string& publicKeyFile, RSAKeyImpl::RSAKeyImpl(std::istream* pPublicKeyStream, std::istream* pPrivateKeyStream, const std::string& privateKeyPassphrase): KeyPairImpl("rsa", KT_RSA_IMPL), - _pRSA(0) + _pRSA(nullptr) { - poco_assert_dbg(_pRSA == 0); + poco_assert_dbg(_pRSA == nullptr); _pRSA = RSA_new(); if (pPublicKeyStream) @@ -163,14 +163,14 @@ RSAKeyImpl::RSAKeyImpl(std::istream* pPublicKeyStream, Poco::StreamCopier::copyToString(*pPublicKeyStream, publicKeyData); BIO* bio = BIO_new_mem_buf(const_cast(publicKeyData.data()), static_cast(publicKeyData.size())); if (!bio) throw Poco::IOException("Cannot create BIO for reading public key"); - RSA* publicKey = PEM_read_bio_RSAPublicKey(bio, &_pRSA, 0, 0); + RSA* publicKey = PEM_read_bio_RSAPublicKey(bio, &_pRSA, nullptr, nullptr); if (!publicKey) { int rc = BIO_reset(bio); // BIO_reset() normally returns 1 for success and 0 or -1 for failure. // File BIOs are an exception, they return 0 for success and -1 for failure. if (rc != 1) throw Poco::FileException("Failed to load public key"); - publicKey = PEM_read_bio_RSA_PUBKEY(bio, &_pRSA, 0, 0); + publicKey = PEM_read_bio_RSA_PUBKEY(bio, &_pRSA, nullptr, nullptr); } BIO_free(bio); if (!publicKey) @@ -186,11 +186,11 @@ RSAKeyImpl::RSAKeyImpl(std::istream* pPublicKeyStream, Poco::StreamCopier::copyToString(*pPrivateKeyStream, privateKeyData); BIO* bio = BIO_new_mem_buf(const_cast(privateKeyData.data()), static_cast(privateKeyData.size())); if (!bio) throw Poco::IOException("Cannot create BIO for reading private key"); - RSA* privateKey = 0; + RSA* privateKey = nullptr; if (privateKeyPassphrase.empty()) - privateKey = PEM_read_bio_RSAPrivateKey(bio, &_pRSA, 0, 0); + privateKey = PEM_read_bio_RSAPrivateKey(bio, &_pRSA, nullptr, nullptr); else - privateKey = PEM_read_bio_RSAPrivateKey(bio, &_pRSA, 0, const_cast(privateKeyPassphrase.c_str())); + privateKey = PEM_read_bio_RSAPrivateKey(bio, &_pRSA, nullptr, const_cast(privateKeyPassphrase.c_str())); BIO_free(bio); if (!privateKey) { @@ -210,7 +210,7 @@ RSAKeyImpl::~RSAKeyImpl() void RSAKeyImpl::freeRSA() { if (_pRSA) RSA_free(_pRSA); - _pRSA = 0; + _pRSA = nullptr; } @@ -223,9 +223,9 @@ int RSAKeyImpl::size() const RSAKeyImpl::ByteVec RSAKeyImpl::modulus() const { #if OPENSSL_VERSION_NUMBER >= 0x10100000L - const BIGNUM* n = 0; - const BIGNUM* e = 0; - const BIGNUM* d = 0; + const BIGNUM* n = nullptr; + const BIGNUM* e = nullptr; + const BIGNUM* d = nullptr; RSA_get0_key(_pRSA, &n, &e, &d); return convertToByteVec(n); #else @@ -237,9 +237,9 @@ RSAKeyImpl::ByteVec RSAKeyImpl::modulus() const RSAKeyImpl::ByteVec RSAKeyImpl::encryptionExponent() const { #if OPENSSL_VERSION_NUMBER >= 0x10100000L - const BIGNUM* n = 0; - const BIGNUM* e = 0; - const BIGNUM* d = 0; + const BIGNUM* n = nullptr; + const BIGNUM* e = nullptr; + const BIGNUM* d = nullptr; RSA_get0_key(_pRSA, &n, &e, &d); return convertToByteVec(e); #else @@ -251,9 +251,9 @@ RSAKeyImpl::ByteVec RSAKeyImpl::encryptionExponent() const RSAKeyImpl::ByteVec RSAKeyImpl::decryptionExponent() const { #if OPENSSL_VERSION_NUMBER >= 0x10100000L - const BIGNUM* n = 0; - const BIGNUM* e = 0; - const BIGNUM* d = 0; + const BIGNUM* n = nullptr; + const BIGNUM* e = nullptr; + const BIGNUM* d = nullptr; RSA_get0_key(_pRSA, &n, &e, &d); return convertToByteVec(d); #else @@ -297,11 +297,11 @@ void RSAKeyImpl::save(const std::string& publicKeyFile, { int rc = 0; if (privateKeyPassphrase.empty()) - rc = PEM_write_bio_RSAPrivateKey(bio, _pRSA, 0, 0, 0, 0, 0); + rc = PEM_write_bio_RSAPrivateKey(bio, _pRSA, nullptr, nullptr, 0, nullptr, nullptr); else rc = PEM_write_bio_RSAPrivateKey(bio, _pRSA, EVP_des_ede3_cbc(), reinterpret_cast(const_cast(privateKeyPassphrase.c_str())), - static_cast(privateKeyPassphrase.length()), 0, 0); + static_cast(privateKeyPassphrase.length()), nullptr, nullptr); if (!rc) throw Poco::FileException("Failed to write private key to file", privateKeyFile); } else throw Poco::CreateFileException("Cannot create private key file", privateKeyFile); @@ -341,11 +341,11 @@ void RSAKeyImpl::save(std::ostream* pPublicKeyStream, if (!bio) throw Poco::IOException("Cannot create BIO for writing public key"); int rc = 0; if (privateKeyPassphrase.empty()) - rc = PEM_write_bio_RSAPrivateKey(bio, _pRSA, 0, 0, 0, 0, 0); + rc = PEM_write_bio_RSAPrivateKey(bio, _pRSA, nullptr, nullptr, 0, nullptr, nullptr); else rc = PEM_write_bio_RSAPrivateKey(bio, _pRSA, EVP_des_ede3_cbc(), reinterpret_cast(const_cast(privateKeyPassphrase.c_str())), - static_cast(privateKeyPassphrase.length()), 0, 0); + static_cast(privateKeyPassphrase.length()), nullptr, nullptr); if (!rc) { BIO_free(bio); diff --git a/Crypto/src/X509Certificate.cpp b/Crypto/src/X509Certificate.cpp index d3f3e53770..219b59feb6 100644 --- a/Crypto/src/X509Certificate.cpp +++ b/Crypto/src/X509Certificate.cpp @@ -42,14 +42,14 @@ namespace Crypto { X509Certificate::X509Certificate(std::istream& istr): - _pCert(0) + _pCert(nullptr) { load(istr); } X509Certificate::X509Certificate(const std::string& path): - _pCert(0) + _pCert(nullptr) { load(path); } @@ -147,7 +147,7 @@ void X509Certificate::load(std::istream& istr) BIO *pBIO = BIO_new_mem_buf(const_cast(cert.data()), static_cast(cert.size())); if (!pBIO) throw Poco::IOException("Cannot create BIO for reading certificate"); - _pCert = PEM_read_bio_X509(pBIO, 0, 0, 0); + _pCert = PEM_read_bio_X509(pBIO, nullptr, nullptr, nullptr); BIO_free(pBIO); if (!_pCert) throw Poco::IOException("Failed to load certificate from stream"); @@ -168,7 +168,7 @@ void X509Certificate::load(const std::string& path) throw Poco::OpenFileException("Cannot open certificate file for reading", path); } - _pCert = PEM_read_bio_X509(pBIO, 0, 0, 0); + _pCert = PEM_read_bio_X509(pBIO, nullptr, nullptr, nullptr); BIO_free(pBIO); if (!_pCert) throw Poco::ReadFileException("Faild to load certificate from", path); @@ -239,7 +239,7 @@ void X509Certificate::init() { _issuerName = _X509_NAME_oneline_utf8(X509_get_issuer_name(_pCert)); _subjectName = _X509_NAME_oneline_utf8(X509_get_subject_name(_pCert)); - BIGNUM* pBN = ASN1_INTEGER_to_BN(X509_get_serialNumber(const_cast(_pCert)), 0); + BIGNUM* pBN = ASN1_INTEGER_to_BN(X509_get_serialNumber(const_cast(_pCert)), nullptr); if (pBN) { char* pSN = BN_bn2hex(pBN); @@ -286,7 +286,7 @@ std::string X509Certificate::subjectName(NID nid) const void X509Certificate::extractNames(std::string& cmnName, std::set& domainNames) const { domainNames.clear(); - if (STACK_OF(GENERAL_NAME)* names = static_cast(X509_get_ext_d2i(_pCert, NID_subject_alt_name, 0, 0))) + if (STACK_OF(GENERAL_NAME)* names = static_cast(X509_get_ext_d2i(_pCert, NID_subject_alt_name, nullptr, nullptr))) { for (int i = 0; i < sk_GENERAL_NAME_num(names); ++i) { @@ -416,8 +416,8 @@ X509Certificate::List X509Certificate::readPEM(const std::string& pemFileName) { List caCertList; BIO* pBIO = BIO_new_file(pemFileName.c_str(), "r"); - if (pBIO == NULL) throw OpenFileException(Poco::format("X509Certificate::readPEM(%s)", pemFileName)); - X509* x = PEM_read_bio_X509(pBIO, NULL, 0, NULL); + if (pBIO == nullptr) throw OpenFileException(Poco::format("X509Certificate::readPEM(%s)", pemFileName)); + X509* x = PEM_read_bio_X509(pBIO, nullptr, nullptr, nullptr); if (!x) { BIO_free(pBIO); @@ -426,7 +426,7 @@ X509Certificate::List X509Certificate::readPEM(const std::string& pemFileName) while (x) { caCertList.push_back(X509Certificate(x)); - x = PEM_read_bio_X509(pBIO, NULL, 0, NULL); + x = PEM_read_bio_X509(pBIO, nullptr, nullptr, nullptr); } BIO_free(pBIO); return caCertList; @@ -436,7 +436,7 @@ X509Certificate::List X509Certificate::readPEM(const std::string& pemFileName) void X509Certificate::writePEM(const std::string& pemFileName, const List& list) { BIO* pBIO = BIO_new_file(pemFileName.c_str(), "a"); - if (pBIO == NULL) throw OpenFileException(Poco::format("X509Certificate::writePEM(%s)", pemFileName)); + if (pBIO == nullptr) throw OpenFileException(Poco::format("X509Certificate::writePEM(%s)", pemFileName)); List::const_iterator it = list.begin(); List::const_iterator end = list.end(); for (; it != end; ++it) diff --git a/Data/MySQL/include/Poco/Data/MySQL/Binder.h b/Data/MySQL/include/Poco/Data/MySQL/Binder.h index 82fa617abf..a0c3ae0f31 100644 --- a/Data/MySQL/include/Poco/Data/MySQL/Binder.h +++ b/Data/MySQL/include/Poco/Data/MySQL/Binder.h @@ -39,31 +39,31 @@ class MySQL_API Binder: public Poco::Data::AbstractBinder Binder(); /// Creates the Binder. - virtual ~Binder(); + ~Binder() override; /// Destroys the Binder. - virtual void bind(std::size_t pos, const Poco::Int8& val, Direction dir); + void bind(std::size_t pos, const Poco::Int8& val, Direction dir) override; /// Binds an Int8. - virtual void bind(std::size_t pos, const Poco::UInt8& val, Direction dir); + void bind(std::size_t pos, const Poco::UInt8& val, Direction dir) override; /// Binds an UInt8. - virtual void bind(std::size_t pos, const Poco::Int16& val, Direction dir); + void bind(std::size_t pos, const Poco::Int16& val, Direction dir) override; /// Binds an Int16. - virtual void bind(std::size_t pos, const Poco::UInt16& val, Direction dir); + void bind(std::size_t pos, const Poco::UInt16& val, Direction dir) override; /// Binds an UInt16. - virtual void bind(std::size_t pos, const Poco::Int32& val, Direction dir); + void bind(std::size_t pos, const Poco::Int32& val, Direction dir) override; /// Binds an Int32. - virtual void bind(std::size_t pos, const Poco::UInt32& val, Direction dir); + void bind(std::size_t pos, const Poco::UInt32& val, Direction dir) override; /// Binds an UInt32. - virtual void bind(std::size_t pos, const Poco::Int64& val, Direction dir); + void bind(std::size_t pos, const Poco::Int64& val, Direction dir) override; /// Binds an Int64. - virtual void bind(std::size_t pos, const Poco::UInt64& val, Direction dir); + void bind(std::size_t pos, const Poco::UInt64& val, Direction dir) override; /// Binds an UInt64. #ifndef POCO_INT64_IS_LONG @@ -74,155 +74,155 @@ class MySQL_API Binder: public Poco::Data::AbstractBinder /// Binds an unsigned long. #endif - virtual void bind(std::size_t pos, const bool& val, Direction dir); + void bind(std::size_t pos, const bool& val, Direction dir) override; /// Binds a boolean. - virtual void bind(std::size_t pos, const float& val, Direction dir); + void bind(std::size_t pos, const float& val, Direction dir) override; /// Binds a float. - virtual void bind(std::size_t pos, const double& val, Direction dir); + void bind(std::size_t pos, const double& val, Direction dir) override; /// Binds a double. - virtual void bind(std::size_t pos, const char& val, Direction dir); + void bind(std::size_t pos, const char& val, Direction dir) override; /// Binds a single character. - virtual void bind(std::size_t pos, const std::string& val, Direction dir); + void bind(std::size_t pos, const std::string& val, Direction dir) override; /// Binds a string. - virtual void bind(std::size_t pos, const Poco::Data::BLOB& val, Direction dir); + void bind(std::size_t pos, const Poco::Data::BLOB& val, Direction dir) override; /// Binds a BLOB. - virtual void bind(std::size_t pos, const Poco::Data::CLOB& val, Direction dir); + void bind(std::size_t pos, const Poco::Data::CLOB& val, Direction dir) override; /// Binds a CLOB. - virtual void bind(std::size_t pos, const DateTime& val, Direction dir); + void bind(std::size_t pos, const DateTime& val, Direction dir) override; /// Binds a DateTime. - virtual void bind(std::size_t pos, const Date& val, Direction dir); + void bind(std::size_t pos, const Date& val, Direction dir) override; /// Binds a Date. - virtual void bind(std::size_t pos, const Time& val, Direction dir); + void bind(std::size_t pos, const Time& val, Direction dir) override; /// Binds a Time. - virtual void bind(std::size_t pos, const UUID& val, Direction dir); + void bind(std::size_t pos, const UUID& val, Direction dir) override; /// Binds a UUID. - virtual void bind(std::size_t pos, const NullData& val, Direction dir); + void bind(std::size_t pos, const NullData& val, Direction dir) override; /// Binds a null. - virtual void bind(std::size_t pos, const std::vector& val, Direction dir = PD_IN); + void bind(std::size_t pos, const std::vector& val, Direction dir = PD_IN) override; - virtual void bind(std::size_t pos, const std::deque& val, Direction dir = PD_IN); + void bind(std::size_t pos, const std::deque& val, Direction dir = PD_IN) override; - virtual void bind(std::size_t pos, const std::list& val, Direction dir = PD_IN); + void bind(std::size_t pos, const std::list& val, Direction dir = PD_IN) override; - virtual void bind(std::size_t pos, const std::vector& val, Direction dir = PD_IN); + void bind(std::size_t pos, const std::vector& val, Direction dir = PD_IN) override; - virtual void bind(std::size_t pos, const std::deque& val, Direction dir = PD_IN); + void bind(std::size_t pos, const std::deque& val, Direction dir = PD_IN) override; - virtual void bind(std::size_t pos, const std::list& val, Direction dir = PD_IN); + void bind(std::size_t pos, const std::list& val, Direction dir = PD_IN) override; - virtual void bind(std::size_t pos, const std::vector& val, Direction dir = PD_IN); + void bind(std::size_t pos, const std::vector& val, Direction dir = PD_IN) override; - virtual void bind(std::size_t pos, const std::deque& val, Direction dir = PD_IN); + void bind(std::size_t pos, const std::deque& val, Direction dir = PD_IN) override; - virtual void bind(std::size_t pos, const std::list& val, Direction dir = PD_IN); + void bind(std::size_t pos, const std::list& val, Direction dir = PD_IN) override; - virtual void bind(std::size_t pos, const std::vector& val, Direction dir = PD_IN); + void bind(std::size_t pos, const std::vector& val, Direction dir = PD_IN) override; - virtual void bind(std::size_t pos, const std::deque& val, Direction dir = PD_IN); + void bind(std::size_t pos, const std::deque& val, Direction dir = PD_IN) override; - virtual void bind(std::size_t pos, const std::list& val, Direction dir = PD_IN); + void bind(std::size_t pos, const std::list& val, Direction dir = PD_IN) override; - virtual void bind(std::size_t pos, const std::vector& val, Direction dir = PD_IN); + void bind(std::size_t pos, const std::vector& val, Direction dir = PD_IN) override; - virtual void bind(std::size_t pos, const std::deque& val, Direction dir = PD_IN); + void bind(std::size_t pos, const std::deque& val, Direction dir = PD_IN) override; - virtual void bind(std::size_t pos, const std::list& val, Direction dir = PD_IN); + void bind(std::size_t pos, const std::list& val, Direction dir = PD_IN) override; - virtual void bind(std::size_t pos, const std::vector& val, Direction dir = PD_IN); + void bind(std::size_t pos, const std::vector& val, Direction dir = PD_IN) override; - virtual void bind(std::size_t pos, const std::deque& val, Direction dir = PD_IN); + void bind(std::size_t pos, const std::deque& val, Direction dir = PD_IN) override; - virtual void bind(std::size_t pos, const std::list& val, Direction dir = PD_IN); + void bind(std::size_t pos, const std::list& val, Direction dir = PD_IN) override; - virtual void bind(std::size_t pos, const std::vector& val, Direction dir = PD_IN); + void bind(std::size_t pos, const std::vector& val, Direction dir = PD_IN) override; - virtual void bind(std::size_t pos, const std::deque& val, Direction dir = PD_IN); + void bind(std::size_t pos, const std::deque& val, Direction dir = PD_IN) override; - virtual void bind(std::size_t pos, const std::list& val, Direction dir = PD_IN); + void bind(std::size_t pos, const std::list& val, Direction dir = PD_IN) override; - virtual void bind(std::size_t pos, const std::vector& val, Direction dir = PD_IN); + void bind(std::size_t pos, const std::vector& val, Direction dir = PD_IN) override; - virtual void bind(std::size_t pos, const std::deque& val, Direction dir = PD_IN); + void bind(std::size_t pos, const std::deque& val, Direction dir = PD_IN) override; - virtual void bind(std::size_t pos, const std::list& val, Direction dir = PD_IN); + void bind(std::size_t pos, const std::list& val, Direction dir = PD_IN) override; - virtual void bind(std::size_t pos, const std::vector& val, Direction dir = PD_IN); + void bind(std::size_t pos, const std::vector& val, Direction dir = PD_IN) override; - virtual void bind(std::size_t pos, const std::deque& val, Direction dir = PD_IN); + void bind(std::size_t pos, const std::deque& val, Direction dir = PD_IN) override; - virtual void bind(std::size_t pos, const std::list& val, Direction dir = PD_IN); + void bind(std::size_t pos, const std::list& val, Direction dir = PD_IN) override; - virtual void bind(std::size_t pos, const std::vector& val, Direction dir = PD_IN); + void bind(std::size_t pos, const std::vector& val, Direction dir = PD_IN) override; - virtual void bind(std::size_t pos, const std::deque& val, Direction dir = PD_IN); + void bind(std::size_t pos, const std::deque& val, Direction dir = PD_IN) override; - virtual void bind(std::size_t pos, const std::list& val, Direction dir = PD_IN); + void bind(std::size_t pos, const std::list& val, Direction dir = PD_IN) override; - virtual void bind(std::size_t pos, const std::vector& val, Direction dir = PD_IN); + void bind(std::size_t pos, const std::vector& val, Direction dir = PD_IN) override; - virtual void bind(std::size_t pos, const std::deque& val, Direction dir = PD_IN); + void bind(std::size_t pos, const std::deque& val, Direction dir = PD_IN) override; - virtual void bind(std::size_t pos, const std::list& val, Direction dir = PD_IN); + void bind(std::size_t pos, const std::list& val, Direction dir = PD_IN) override; - virtual void bind(std::size_t pos, const std::vector& val, Direction dir = PD_IN); + void bind(std::size_t pos, const std::vector& val, Direction dir = PD_IN) override; - virtual void bind(std::size_t pos, const std::deque& val, Direction dir = PD_IN); + void bind(std::size_t pos, const std::deque& val, Direction dir = PD_IN) override; - virtual void bind(std::size_t pos, const std::list& val, Direction dir = PD_IN); + void bind(std::size_t pos, const std::list& val, Direction dir = PD_IN) override; - virtual void bind(std::size_t pos, const std::vector& val, Direction dir = PD_IN); + void bind(std::size_t pos, const std::vector& val, Direction dir = PD_IN) override; - virtual void bind(std::size_t pos, const std::deque& val, Direction dir = PD_IN); + void bind(std::size_t pos, const std::deque& val, Direction dir = PD_IN) override; - virtual void bind(std::size_t pos, const std::list& val, Direction dir = PD_IN); + void bind(std::size_t pos, const std::list& val, Direction dir = PD_IN) override; - virtual void bind(std::size_t pos, const std::vector& val, Direction dir = PD_IN); + void bind(std::size_t pos, const std::vector& val, Direction dir = PD_IN) override; - virtual void bind(std::size_t pos, const std::deque& val, Direction dir = PD_IN); + void bind(std::size_t pos, const std::deque& val, Direction dir = PD_IN) override; - virtual void bind(std::size_t pos, const std::list& val, Direction dir = PD_IN); + void bind(std::size_t pos, const std::list& val, Direction dir = PD_IN) override; - virtual void bind(std::size_t pos, const std::vector& val, Direction dir = PD_IN); + void bind(std::size_t pos, const std::vector& val, Direction dir = PD_IN) override; - virtual void bind(std::size_t pos, const std::deque& val, Direction dir = PD_IN); + void bind(std::size_t pos, const std::deque& val, Direction dir = PD_IN) override; - virtual void bind(std::size_t pos, const std::list& val, Direction dir = PD_IN); + void bind(std::size_t pos, const std::list& val, Direction dir = PD_IN) override; - virtual void bind(std::size_t pos, const std::vector& val, Direction dir = PD_IN); + void bind(std::size_t pos, const std::vector& val, Direction dir = PD_IN) override; - virtual void bind(std::size_t pos, const std::deque& val, Direction dir = PD_IN); + void bind(std::size_t pos, const std::deque& val, Direction dir = PD_IN) override; - virtual void bind(std::size_t pos, const std::list& val, Direction dir = PD_IN); + void bind(std::size_t pos, const std::list& val, Direction dir = PD_IN) override; - virtual void bind(std::size_t pos, const std::vector