From 06335ae2ae179f1c63d29980c469305c9d532953 Mon Sep 17 00:00:00 2001 From: Alex Fabijanic Date: Tue, 26 Sep 2017 12:00:46 -0500 Subject: [PATCH] make all save() functions const --- Crypto/include/Poco/Crypto/ECKeyImpl.h | 12 ++++++++---- Crypto/include/Poco/Crypto/EVPPKey.h | 16 ++++++++++++---- Crypto/include/Poco/Crypto/KeyPair.h | 16 ++++++++++++---- Crypto/include/Poco/Crypto/KeyPairImpl.h | 8 ++++++-- Crypto/include/Poco/Crypto/RSAKeyImpl.h | 8 ++++++-- Crypto/src/EVPPKey.cpp | 8 ++++++-- Crypto/src/RSAKeyImpl.cpp | 4 ++-- 7 files changed, 52 insertions(+), 20 deletions(-) diff --git a/Crypto/include/Poco/Crypto/ECKeyImpl.h b/Crypto/include/Poco/Crypto/ECKeyImpl.h index 1adb50e31..380b3978e 100644 --- a/Crypto/include/Poco/Crypto/ECKeyImpl.h +++ b/Crypto/include/Poco/Crypto/ECKeyImpl.h @@ -88,13 +88,17 @@ public: std::string groupName() const; /// Returns the EC key group name. - void save(const std::string& publicKeyFile, const std::string& privateKeyFile = "", const std::string& privateKeyPassphrase = ""); + 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. - void save(std::ostream* pPublicKeyStream, std::ostream* pPrivateKeyStream = 0, const std::string& privateKeyPassphrase = ""); + void save(std::ostream* pPublicKeyStream, + std::ostream* pPrivateKeyStream = 0, + 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 @@ -130,7 +134,7 @@ inline std::string ECKeyImpl::groupName() const inline void ECKeyImpl::save(const std::string& publicKeyFile, const std::string& privateKeyFile, - const std::string& privateKeyPassphrase) + const std::string& privateKeyPassphrase) const { EVPPKey(_pEC).save(publicKeyFile, privateKeyFile, privateKeyPassphrase); } @@ -138,7 +142,7 @@ inline void ECKeyImpl::save(const std::string& publicKeyFile, inline void ECKeyImpl::save(std::ostream* pPublicKeyStream, std::ostream* pPrivateKeyStream, - const std::string& privateKeyPassphrase) + const std::string& privateKeyPassphrase) const { EVPPKey(_pEC).save(pPublicKeyStream, pPrivateKeyStream, privateKeyPassphrase); } diff --git a/Crypto/include/Poco/Crypto/EVPPKey.h b/Crypto/include/Poco/Crypto/EVPPKey.h index 6ad348fc8..ae6995a71 100644 --- a/Crypto/include/Poco/Crypto/EVPPKey.h +++ b/Crypto/include/Poco/Crypto/EVPPKey.h @@ -70,12 +70,16 @@ public: setKey(pKey); } - EVPPKey(const std::string& publicKeyFile, const std::string& privateKeyFile, const std::string& privateKeyPassphrase = ""); + EVPPKey(const std::string& publicKeyFile, + const std::string& privateKeyFile, + const std::string& privateKeyPassphrase = ""); /// Creates the EVPPKey, by reading public and private key from the given files and /// using the given passphrase for the private key. Can only by used for signing if /// a private key is available. - EVPPKey(std::istream* pPublicKeyStream, std::istream* pPrivateKeyStream, const std::string& privateKeyPassphrase = ""); + EVPPKey(std::istream* pPublicKeyStream, + std::istream* pPrivateKeyStream, + const std::string& privateKeyPassphrase = ""); /// Creates the EVPPKey. Can only by used for signing if pPrivKey /// 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. @@ -95,13 +99,17 @@ public: ~EVPPKey(); /// Destroys the EVPPKey. - void save(const std::string& publicKeyFile, const std::string& privateKeyFile = "", const std::string& privateKeyPassphrase = ""); + void save(const std::string& publicKeyFile, + const std::string& privateKeyFile = "", + const std::string& privateKeyPassphrase = "") const; /// Exports the public and/or 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 = ""); + void save(std::ostream* pPublicKeyStream, + std::ostream* pPrivateKeyStream = 0, + 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 diff --git a/Crypto/include/Poco/Crypto/KeyPair.h b/Crypto/include/Poco/Crypto/KeyPair.h index e8fed31c0..b9a705f8f 100644 --- a/Crypto/include/Poco/Crypto/KeyPair.h +++ b/Crypto/include/Poco/Crypto/KeyPair.h @@ -54,13 +54,17 @@ public: virtual int size() const; /// Returns the RSA modulus size. - virtual void save(const std::string& publicKeyPairFile, const std::string& privateKeyPairFile = "", const std::string& privateKeyPairPassphrase = ""); + virtual void save(const std::string& publicKeyPairFile, + const std::string& privateKeyPairFile = "", + const std::string& privateKeyPairPassphrase = "") 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 = ""); + virtual void save(std::ostream* pPublicKeyPairStream, + std::ostream* pPrivateKeyPairStream = 0, + const std::string& privateKeyPairPassphrase = "") const; /// Exports the public and private key to the given streams. /// /// If a null pointer is passed for a stream, the corresponding @@ -90,13 +94,17 @@ inline int KeyPair::size() const } -inline void KeyPair::save(const std::string& publicKeyFile, const std::string& privateKeyFile, const std::string& privateKeyPassphrase) +inline void KeyPair::save(const std::string& publicKeyFile, + const std::string& privateKeyFile, + const std::string& privateKeyPassphrase) const { _pImpl->save(publicKeyFile, privateKeyFile, privateKeyPassphrase); } -inline void KeyPair::save(std::ostream* pPublicKeyStream, std::ostream* pPrivateKeyStream, const std::string& privateKeyPassphrase) +inline void KeyPair::save(std::ostream* pPublicKeyStream, + std::ostream* pPrivateKeyStream, + const std::string& privateKeyPassphrase) const { _pImpl->save(pPublicKeyStream, pPrivateKeyStream, privateKeyPassphrase); } diff --git a/Crypto/include/Poco/Crypto/KeyPairImpl.h b/Crypto/include/Poco/Crypto/KeyPairImpl.h index 22b0b7b10..543beb83d 100644 --- a/Crypto/include/Poco/Crypto/KeyPairImpl.h +++ b/Crypto/include/Poco/Crypto/KeyPairImpl.h @@ -55,13 +55,17 @@ public: virtual int size() const = 0; /// Returns the key size. - virtual void save(const std::string& publicKeyFile, const std::string& privateKeyFile = "", const std::string& privateKeyPassphrase = "") = 0; + virtual void save(const std::string& publicKeyFile, + const std::string& privateKeyFile = "", + const std::string& privateKeyPassphrase = "") const = 0; /// 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* pPublicKeyStream, std::ostream* pPrivateKeyStream = 0, const std::string& privateKeyPassphrase = "") = 0; + virtual void save(std::ostream* pPublicKeyStream, + std::ostream* pPrivateKeyStream = 0, + const std::string& privateKeyPassphrase = "") const = 0; /// 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/RSAKeyImpl.h b/Crypto/include/Poco/Crypto/RSAKeyImpl.h index bfd627702..a897d515d 100644 --- a/Crypto/include/Poco/Crypto/RSAKeyImpl.h +++ b/Crypto/include/Poco/Crypto/RSAKeyImpl.h @@ -96,13 +96,17 @@ public: ByteVec decryptionExponent() const; /// Returns the RSA decryption exponent. - void save(const std::string& publicKeyFile, const std::string& privateKeyFile = "", const std::string& privateKeyPassphrase = ""); + 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. - void save(std::ostream* pPublicKeyStream, std::ostream* pPrivateKeyStream = 0, const std::string& privateKeyPassphrase = ""); + void save(std::ostream* pPublicKeyStream, + std::ostream* pPrivateKeyStream = 0, + 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/src/EVPPKey.cpp b/Crypto/src/EVPPKey.cpp index 7095a5998..7f121575b 100644 --- a/Crypto/src/EVPPKey.cpp +++ b/Crypto/src/EVPPKey.cpp @@ -104,7 +104,9 @@ EVPPKey::~EVPPKey() } -void EVPPKey::save(const std::string& publicKeyFile, const std::string& privateKeyFile, const std::string& privateKeyPassphrase) +void EVPPKey::save(const std::string& publicKeyFile, + const std::string& privateKeyFile, + const std::string& privateKeyPassphrase) const { if (!publicKeyFile.empty()) { @@ -163,7 +165,9 @@ void EVPPKey::save(const std::string& publicKeyFile, const std::string& privateK } -void EVPPKey::save(std::ostream* pPublicKeyStream, std::ostream* pPrivateKeyStream, const std::string& privateKeyPassphrase) +void EVPPKey::save(std::ostream* pPublicKeyStream, + std::ostream* pPrivateKeyStream, + const std::string& privateKeyPassphrase) const { if (pPublicKeyStream) { diff --git a/Crypto/src/RSAKeyImpl.cpp b/Crypto/src/RSAKeyImpl.cpp index 7b502ca06..77649e352 100644 --- a/Crypto/src/RSAKeyImpl.cpp +++ b/Crypto/src/RSAKeyImpl.cpp @@ -271,7 +271,7 @@ RSAKeyImpl::ByteVec RSAKeyImpl::decryptionExponent() const void RSAKeyImpl::save(const std::string& publicKeyFile, const std::string& privateKeyFile, - const std::string& privateKeyPassphrase) + const std::string& privateKeyPassphrase) const { if (!publicKeyFile.empty()) { @@ -325,7 +325,7 @@ void RSAKeyImpl::save(const std::string& publicKeyFile, void RSAKeyImpl::save(std::ostream* pPublicKeyStream, std::ostream* pPrivateKeyStream, - const std::string& privateKeyPassphrase) + const std::string& privateKeyPassphrase) const { if (pPublicKeyStream) {