Merge pull request #1108 from vmiklos/crypto-wshadow-fixes

GH #1050 Crypto: fix gcc -Wshadow warnings
This commit is contained in:
Aleksandar Fabijanic 2016-01-04 21:45:13 -06:00
commit 51ef1a57aa
3 changed files with 30 additions and 30 deletions

View File

@ -21,21 +21,21 @@ namespace Poco {
namespace Crypto { namespace Crypto {
CipherKey::CipherKey(const std::string& name, const std::string& passphrase, const std::string& salt, int iterationCount, CipherKey::CipherKey(const std::string& rName, const std::string& passphrase, const std::string& salt, int iterationCount,
const std::string &digest): const std::string & rDigest):
_pImpl(new CipherKeyImpl(name, passphrase, salt, iterationCount, digest)) _pImpl(new CipherKeyImpl(rName, passphrase, salt, iterationCount, rDigest))
{ {
} }
CipherKey::CipherKey(const std::string& name, const ByteVec& key, const ByteVec& iv): CipherKey::CipherKey(const std::string& rName, const ByteVec& key, const ByteVec& iv):
_pImpl(new CipherKeyImpl(name, key, iv)) _pImpl(new CipherKeyImpl(rName, key, iv))
{ {
} }
CipherKey::CipherKey(const std::string& name): CipherKey::CipherKey(const std::string& rName):
_pImpl(new CipherKeyImpl(name)) _pImpl(new CipherKeyImpl(rName))
{ {
} }

View File

@ -27,28 +27,28 @@ namespace Poco {
namespace Crypto { namespace Crypto {
CipherKeyImpl::CipherKeyImpl(const std::string& name, CipherKeyImpl::CipherKeyImpl(const std::string& rName,
const std::string& passphrase, const std::string& passphrase,
const std::string& salt, const std::string& salt,
int iterationCount, int iterationCount,
const std::string& digest): const std::string& rDigest):
_pCipher(0), _pCipher(0),
_pDigest(0), _pDigest(0),
_name(name), _name(rName),
_key(), _key(),
_iv() _iv()
{ {
// dummy access to Cipherfactory so that the EVP lib is initilaized // dummy access to Cipherfactory so that the EVP lib is initilaized
CipherFactory::defaultFactory(); CipherFactory::defaultFactory();
_pCipher = EVP_get_cipherbyname(name.c_str()); _pCipher = EVP_get_cipherbyname(rName.c_str());
if (!_pCipher) if (!_pCipher)
throw Poco::NotFoundException("Cipher " + name + " was not found"); throw Poco::NotFoundException("Cipher " + rName + " was not found");
_pDigest = EVP_get_digestbyname(digest.c_str()); _pDigest = EVP_get_digestbyname(rDigest.c_str());
if (!_pDigest) if (!_pDigest)
throw Poco::NotFoundException("Digest " + name + " was not found"); throw Poco::NotFoundException("Digest " + rName + " was not found");
_key = ByteVec(keySize()); _key = ByteVec(keySize());
@ -57,35 +57,35 @@ CipherKeyImpl::CipherKeyImpl(const std::string& name,
} }
CipherKeyImpl::CipherKeyImpl(const std::string& name, CipherKeyImpl::CipherKeyImpl(const std::string& rName,
const ByteVec& key, const ByteVec& key,
const ByteVec& iv): const ByteVec& iv):
_pCipher(0), _pCipher(0),
_name(name), _name(rName),
_key(key), _key(key),
_iv(iv) _iv(iv)
{ {
// dummy access to Cipherfactory so that the EVP lib is initilaized // dummy access to Cipherfactory so that the EVP lib is initilaized
CipherFactory::defaultFactory(); CipherFactory::defaultFactory();
_pCipher = EVP_get_cipherbyname(name.c_str()); _pCipher = EVP_get_cipherbyname(rName.c_str());
if (!_pCipher) if (!_pCipher)
throw Poco::NotFoundException("Cipher " + name + " was not found"); throw Poco::NotFoundException("Cipher " + rName + " was not found");
} }
CipherKeyImpl::CipherKeyImpl(const std::string& name): CipherKeyImpl::CipherKeyImpl(const std::string& rName):
_pCipher(0), _pCipher(0),
_name(name), _name(rName),
_key(), _key(),
_iv() _iv()
{ {
// dummy access to Cipherfactory so that the EVP lib is initilaized // dummy access to Cipherfactory so that the EVP lib is initilaized
CipherFactory::defaultFactory(); CipherFactory::defaultFactory();
_pCipher = EVP_get_cipherbyname(name.c_str()); _pCipher = EVP_get_cipherbyname(rName.c_str());
if (!_pCipher) if (!_pCipher)
throw Poco::NotFoundException("Cipher " + name + " was not found"); throw Poco::NotFoundException("Cipher " + rName + " was not found");
_key = ByteVec(keySize()); _key = ByteVec(keySize());
_iv = ByteVec(ivSize()); _iv = ByteVec(ivSize());
generateKey(); generateKey();
@ -165,7 +165,7 @@ void CipherKeyImpl::generateKey(
} }
// Now create the key and IV, using the digest set in the constructor. // Now create the key and IV, using the digest set in the constructor.
int keySize = EVP_BytesToKey( int cipherKeySize = EVP_BytesToKey(
_pCipher, _pCipher,
_pDigest, _pDigest,
(salt.empty() ? 0 : saltBytes), (salt.empty() ? 0 : saltBytes),
@ -176,7 +176,7 @@ void CipherKeyImpl::generateKey(
ivBytes); ivBytes);
// Copy the buffers to our member byte vectors. // Copy the buffers to our member byte vectors.
_key.assign(keyBytes, keyBytes + keySize); _key.assign(keyBytes, keyBytes + cipherKeySize);
if (ivSize() == 0) if (ivSize() == 0)
_iv.clear(); _iv.clear();

View File

@ -87,10 +87,10 @@ RSAKeyImpl::RSAKeyImpl(
RSA* pubKey = PEM_read_bio_RSAPublicKey(bio, &_pRSA, 0, 0); RSA* pubKey = PEM_read_bio_RSAPublicKey(bio, &_pRSA, 0, 0);
if (!pubKey) if (!pubKey)
{ {
int rc = BIO_reset(bio); int ret = BIO_reset(bio);
// BIO_reset() normally returns 1 for success and 0 or -1 for failure. // 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. // 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); if (ret != 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, 0, 0);
} }
BIO_free(bio); BIO_free(bio);
@ -287,8 +287,8 @@ void RSAKeyImpl::save(std::ostream* pPublicKeyStream, std::ostream* pPrivateKeyS
throw Poco::WriteFileException("Failed to write public key to stream"); throw Poco::WriteFileException("Failed to write public key to stream");
} }
char* pData; char* pData;
long size = BIO_get_mem_data(bio, &pData); long keySize = BIO_get_mem_data(bio, &pData);
pPublicKeyStream->write(pData, static_cast<std::streamsize>(size)); pPublicKeyStream->write(pData, static_cast<std::streamsize>(keySize));
BIO_free(bio); BIO_free(bio);
} }
@ -309,8 +309,8 @@ void RSAKeyImpl::save(std::ostream* pPublicKeyStream, std::ostream* pPrivateKeyS
throw Poco::FileException("Failed to write private key to stream"); throw Poco::FileException("Failed to write private key to stream");
} }
char* pData; char* pData;
long size = BIO_get_mem_data(bio, &pData); long keySize = BIO_get_mem_data(bio, &pData);
pPrivateKeyStream->write(pData, static_cast<std::streamsize>(size)); pPrivateKeyStream->write(pData, static_cast<std::streamsize>(keySize));
BIO_free(bio); BIO_free(bio);
} }
} }