make all save() functions const

This commit is contained in:
Alex Fabijanic 2017-09-26 12:00:46 -05:00
parent 01f90c7632
commit 06335ae2ae
7 changed files with 52 additions and 20 deletions

View File

@ -88,13 +88,17 @@ public:
std::string groupName() const; std::string groupName() const;
/// Returns the EC key group name. /// 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. /// Exports the public and private keys to the given files.
/// ///
/// If an empty filename is specified, the corresponding key /// If an empty filename is specified, the corresponding key
/// is not exported. /// 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. /// Exports the public and private key to the given streams.
/// ///
/// If a null pointer is passed for a stream, the corresponding /// 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, inline void ECKeyImpl::save(const std::string& publicKeyFile,
const std::string& privateKeyFile, const std::string& privateKeyFile,
const std::string& privateKeyPassphrase) const std::string& privateKeyPassphrase) const
{ {
EVPPKey(_pEC).save(publicKeyFile, privateKeyFile, privateKeyPassphrase); 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, inline void ECKeyImpl::save(std::ostream* pPublicKeyStream,
std::ostream* pPrivateKeyStream, std::ostream* pPrivateKeyStream,
const std::string& privateKeyPassphrase) const std::string& privateKeyPassphrase) const
{ {
EVPPKey(_pEC).save(pPublicKeyStream, pPrivateKeyStream, privateKeyPassphrase); EVPPKey(_pEC).save(pPublicKeyStream, pPrivateKeyStream, privateKeyPassphrase);
} }

View File

@ -70,12 +70,16 @@ public:
setKey(pKey); 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 /// 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 /// using the given passphrase for the private key. Can only by used for signing if
/// a private key is available. /// 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 /// 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 /// 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. /// specify a public key file. OpenSSL will auto-create it from the private key.
@ -95,13 +99,17 @@ public:
~EVPPKey(); ~EVPPKey();
/// Destroys the 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. /// Exports the public and/or private keys to the given files.
/// ///
/// If an empty filename is specified, the corresponding key /// If an empty filename is specified, the corresponding key
/// is not exported. /// 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. /// Exports the public and/or private key to the given streams.
/// ///
/// If a null pointer is passed for a stream, the corresponding /// If a null pointer is passed for a stream, the corresponding

View File

@ -54,13 +54,17 @@ public:
virtual int size() const; virtual int size() const;
/// Returns the RSA modulus size. /// 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. /// Exports the public and private keys to the given files.
/// ///
/// If an empty filename is specified, the corresponding key /// If an empty filename is specified, the corresponding key
/// is not exported. /// 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. /// Exports the public and private key to the given streams.
/// ///
/// If a null pointer is passed for a stream, the corresponding /// 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); _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); _pImpl->save(pPublicKeyStream, pPrivateKeyStream, privateKeyPassphrase);
} }

View File

@ -55,13 +55,17 @@ public:
virtual int size() const = 0; virtual int size() const = 0;
/// Returns the key size. /// 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. /// Exports the public and private keys to the given files.
/// ///
/// If an empty filename is specified, the corresponding key /// If an empty filename is specified, the corresponding key
/// is not exported. /// 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. /// Exports the public and private key to the given streams.
/// ///
/// If a null pointer is passed for a stream, the corresponding /// If a null pointer is passed for a stream, the corresponding

View File

@ -96,13 +96,17 @@ public:
ByteVec decryptionExponent() const; ByteVec decryptionExponent() const;
/// Returns the RSA decryption exponent. /// 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. /// Exports the public and private keys to the given files.
/// ///
/// If an empty filename is specified, the corresponding key /// If an empty filename is specified, the corresponding key
/// is not exported. /// 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. /// Exports the public and private key to the given streams.
/// ///
/// If a null pointer is passed for a stream, the corresponding /// If a null pointer is passed for a stream, the corresponding

View File

@ -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()) 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) if (pPublicKeyStream)
{ {

View File

@ -271,7 +271,7 @@ RSAKeyImpl::ByteVec RSAKeyImpl::decryptionExponent() const
void RSAKeyImpl::save(const std::string& publicKeyFile, void RSAKeyImpl::save(const std::string& publicKeyFile,
const std::string& privateKeyFile, const std::string& privateKeyFile,
const std::string& privateKeyPassphrase) const std::string& privateKeyPassphrase) const
{ {
if (!publicKeyFile.empty()) if (!publicKeyFile.empty())
{ {
@ -325,7 +325,7 @@ void RSAKeyImpl::save(const std::string& publicKeyFile,
void RSAKeyImpl::save(std::ostream* pPublicKeyStream, void RSAKeyImpl::save(std::ostream* pPublicKeyStream,
std::ostream* pPrivateKeyStream, std::ostream* pPrivateKeyStream,
const std::string& privateKeyPassphrase) const std::string& privateKeyPassphrase) const
{ {
if (pPublicKeyStream) if (pPublicKeyStream)
{ {