Skip to content

Commit

Permalink
Merge branch 'poco-1.10.0' into devel
Browse files Browse the repository at this point in the history
  • Loading branch information
obiltschnig committed Jan 23, 2020
2 parents 303ddee + 0f49493 commit bccea84
Show file tree
Hide file tree
Showing 14 changed files with 101 additions and 86 deletions.
14 changes: 6 additions & 8 deletions Crypto/include/Poco/Crypto/Cipher.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@


#include "Poco/Crypto/Crypto.h"
#include "Poco/Crypto/CryptoTransform.h"
#include "Poco/RefCountedObject.h"
#include "Poco/AutoPtr.h"
#include <istream>
Expand All @@ -30,9 +31,6 @@ namespace Poco {
namespace Crypto {


class CryptoTransform;


class Crypto_API Cipher: public Poco::RefCountedObject
/// Represents the abstract base class from which all implementations of
/// symmetric/asymmetric encryption algorithms must inherit. Use the CipherFactory
Expand Down Expand Up @@ -75,10 +73,10 @@ class Crypto_API Cipher: public Poco::RefCountedObject
/// // and write pass it to the underlying file stream.
/// Poco::FileOutputStream sink("encrypted.dat");
/// CryptoOutputStream encryptor(sink, pCipher->createEncryptor());
///
///
/// Poco::FileInputStream source("source.txt");
/// Poco::StreamCopier::copyStream(source, encryptor);
///
///
/// // Always close output streams to flush all internal buffers
/// encryptor.close();
/// sink.close();
Expand All @@ -95,7 +93,7 @@ class Crypto_API Cipher: public Poco::RefCountedObject
ENC_BINHEX = 0x02, /// BinHex-encoded output
ENC_BASE64_NO_LF = 0x81, /// Base64-encoded output, no linefeeds
ENC_BINHEX_NO_LF = 0x82 /// BinHex-encoded output, no linefeeds

};

virtual ~Cipher();
Expand All @@ -104,10 +102,10 @@ class Crypto_API Cipher: public Poco::RefCountedObject
virtual const std::string& name() const = 0;
/// Returns the name of the Cipher.

virtual CryptoTransform* createEncryptor() = 0;
virtual CryptoTransform::Ptr createEncryptor() = 0;
/// Creates an encryptor object to be used with a CryptoStream.

virtual CryptoTransform* createDecryptor() = 0;
virtual CryptoTransform::Ptr createDecryptor() = 0;
/// Creates a decryptor object to be used with a CryptoStream.

virtual std::string encryptString(const std::string& str, Encoding encoding = ENC_NONE);
Expand Down
4 changes: 2 additions & 2 deletions Crypto/include/Poco/Crypto/CipherImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ class CipherImpl: public Cipher
const std::string& name() const;
/// Returns the name of the cipher.

CryptoTransform* createEncryptor();
CryptoTransform::Ptr createEncryptor();
/// Creates an encryptor object.

CryptoTransform* createDecryptor();
CryptoTransform::Ptr createDecryptor();
/// Creates a decryptor object.

private:
Expand Down
15 changes: 8 additions & 7 deletions Crypto/include/Poco/Crypto/CryptoStream.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@


#include "Poco/Crypto/Crypto.h"
#include "Poco/Crypto/CryptoTransform.h"
#include "Poco/BufferedStreamBuf.h"
#include "Poco/Buffer.h"
#include <iostream>
Expand All @@ -38,8 +39,8 @@ class Crypto_API CryptoStreamBuf: public Poco::BufferedStreamBuf
/// going through it.
{
public:
CryptoStreamBuf(std::istream& istr, CryptoTransform* pTransform, std::streamsize bufferSize = 8192);
CryptoStreamBuf(std::ostream& ostr, CryptoTransform* pTransform, std::streamsize bufferSize = 8192);
CryptoStreamBuf(std::istream& istr, CryptoTransform::Ptr pTransform, std::streamsize bufferSize = 8192);
CryptoStreamBuf(std::ostream& ostr, CryptoTransform::Ptr pTransform, std::streamsize bufferSize = 8192);

virtual ~CryptoStreamBuf();

Expand All @@ -51,7 +52,7 @@ class Crypto_API CryptoStreamBuf: public Poco::BufferedStreamBuf
int writeToDevice(const char* buffer, std::streamsize length);

private:
CryptoTransform* _pTransform;
CryptoTransform::Ptr _pTransform;
std::istream* _pIstr;
std::ostream* _pOstr;
bool _eof;
Expand All @@ -70,8 +71,8 @@ class Crypto_API CryptoIOS: public virtual std::ios
/// stream buffer and base classes.
{
public:
CryptoIOS(std::istream& istr, CryptoTransform* pTransform, std::streamsize bufferSize = 8192);
CryptoIOS(std::ostream& ostr, CryptoTransform* pTransform, std::streamsize bufferSize = 8192);
CryptoIOS(std::istream& istr, CryptoTransform::Ptr pTransform, std::streamsize bufferSize = 8192);
CryptoIOS(std::ostream& ostr, CryptoTransform::Ptr pTransform, std::streamsize bufferSize = 8192);
~CryptoIOS();
CryptoStreamBuf* rdbuf();

Expand All @@ -89,7 +90,7 @@ class Crypto_API CryptoInputStream: public CryptoIOS, public std::istream
/// respectively.
{
public:
CryptoInputStream(std::istream& istr, CryptoTransform* pTransform, std::streamsize bufferSize = 8192);
CryptoInputStream(std::istream& istr, CryptoTransform::Ptr pTransform, std::streamsize bufferSize = 8192);
/// Create a new CryptoInputStream object. The CryptoInputStream takes the
/// ownership of the given CryptoTransform object.

Expand All @@ -113,7 +114,7 @@ class Crypto_API CryptoOutputStream: public CryptoIOS, public std::ostream
/// to ensure completion of cryptographic transformation.
{
public:
CryptoOutputStream(std::ostream& ostr, CryptoTransform* pTransform, std::streamsize bufferSize = 8192);
CryptoOutputStream(std::ostream& ostr, CryptoTransform::Ptr pTransform, std::streamsize bufferSize = 8192);
/// Create a new CryptoOutputStream object. The CryptoOutputStream takes the
/// ownership of the given CryptoTransform object.

Expand Down
3 changes: 3 additions & 0 deletions Crypto/include/Poco/Crypto/CryptoTransform.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@


#include "Poco/Crypto/Crypto.h"
#include "Poco/SharedPtr.h"
#include <ios>


Expand All @@ -35,6 +36,8 @@ class Crypto_API CryptoTransform
/// perform encryption or decryption of data.
{
public:
using Ptr = Poco::SharedPtr<CryptoTransform>;

CryptoTransform();
/// Creates a new CryptoTransform object.

Expand Down
10 changes: 5 additions & 5 deletions Crypto/include/Poco/Crypto/RSACipherImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ namespace Crypto {


class RSACipherImpl: public Cipher
/// An implementation of the Cipher class for
/// An implementation of the Cipher class for
/// asymmetric (public-private key) encryption
/// based on the the RSA algorithm in OpenSSL's
/// based on the the RSA algorithm in OpenSSL's
/// crypto library.
///
/// Encryption is using the public key, decryption
Expand All @@ -48,11 +48,11 @@ class RSACipherImpl: public Cipher

const std::string& name() const;
/// Returns the name of the Cipher.
CryptoTransform* createEncryptor();

CryptoTransform::Ptr createEncryptor();
/// Creates an encryptor object.

CryptoTransform* createDecryptor();
CryptoTransform::Ptr createDecryptor();
/// Creates a decryptor object.

private:
Expand Down
4 changes: 2 additions & 2 deletions Crypto/src/CipherImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -255,14 +255,14 @@ CipherImpl::~CipherImpl()
}


CryptoTransform* CipherImpl::createEncryptor()
CryptoTransform::Ptr CipherImpl::createEncryptor()
{
CipherKeyImpl::Ptr p = _key.impl();
return new CryptoTransformImpl(p->cipher(), p->getKey(), p->getIV(), CryptoTransformImpl::DIR_ENCRYPT);
}


CryptoTransform* CipherImpl::createDecryptor()
CryptoTransform::Ptr CipherImpl::createDecryptor()
{
CipherKeyImpl::Ptr p = _key.impl();
return new CryptoTransformImpl(p->cipher(), p->getKey(), p->getIV(), CryptoTransformImpl::DIR_DECRYPT);
Expand Down
17 changes: 8 additions & 9 deletions Crypto/src/CryptoStream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ namespace Crypto {
//


CryptoStreamBuf::CryptoStreamBuf(std::istream& istr, CryptoTransform* pTransform, std::streamsize bufferSize):
CryptoStreamBuf::CryptoStreamBuf(std::istream& istr, CryptoTransform::Ptr pTransform, std::streamsize bufferSize):
Poco::BufferedStreamBuf(bufferSize, std::ios::in),
_pTransform(pTransform),
_pIstr(&istr),
Expand All @@ -45,7 +45,7 @@ CryptoStreamBuf::CryptoStreamBuf(std::istream& istr, CryptoTransform* pTransform
}


CryptoStreamBuf::CryptoStreamBuf(std::ostream& ostr, CryptoTransform* pTransform, std::streamsize bufferSize):
CryptoStreamBuf::CryptoStreamBuf(std::ostream& ostr, CryptoTransform::Ptr pTransform, std::streamsize bufferSize):
Poco::BufferedStreamBuf(bufferSize, std::ios::out),
_pTransform(pTransform),
_pIstr(0),
Expand All @@ -67,7 +67,6 @@ CryptoStreamBuf::~CryptoStreamBuf()
catch (...)
{
}
delete _pTransform;
}


Expand All @@ -86,10 +85,10 @@ void CryptoStreamBuf::close()
// thrown.
std::ostream* pOstr = _pOstr;
_pOstr = 0;

// Finalize transformation.
std::streamsize n = _pTransform->finalize(_buffer.begin(), static_cast<std::streamsize>(_buffer.size()));

if (n > 0)
{
pOstr->write(reinterpret_cast<char*>(_buffer.begin()), n);
Expand Down Expand Up @@ -193,14 +192,14 @@ int CryptoStreamBuf::writeToDevice(const char* buffer, std::streamsize length)
//


CryptoIOS::CryptoIOS(std::istream& istr, CryptoTransform* pTransform, std::streamsize bufferSize):
CryptoIOS::CryptoIOS(std::istream& istr, CryptoTransform::Ptr pTransform, std::streamsize bufferSize):
_buf(istr, pTransform, bufferSize)
{
poco_ios_init(&_buf);
}


CryptoIOS::CryptoIOS(std::ostream& ostr, CryptoTransform* pTransform, std::streamsize bufferSize):
CryptoIOS::CryptoIOS(std::ostream& ostr, CryptoTransform::Ptr pTransform, std::streamsize bufferSize):
_buf(ostr, pTransform, bufferSize)
{
poco_ios_init(&_buf);
Expand All @@ -223,7 +222,7 @@ CryptoStreamBuf* CryptoIOS::rdbuf()
//


CryptoInputStream::CryptoInputStream(std::istream& istr, CryptoTransform* pTransform, std::streamsize bufferSize):
CryptoInputStream::CryptoInputStream(std::istream& istr, CryptoTransform::Ptr pTransform, std::streamsize bufferSize):
CryptoIOS(istr, pTransform, bufferSize),
std::istream(&_buf)
{
Expand All @@ -247,7 +246,7 @@ CryptoInputStream::~CryptoInputStream()
//


CryptoOutputStream::CryptoOutputStream(std::ostream& ostr, CryptoTransform* pTransform, std::streamsize bufferSize):
CryptoOutputStream::CryptoOutputStream(std::ostream& ostr, CryptoTransform::Ptr pTransform, std::streamsize bufferSize):
CryptoIOS(ostr, pTransform, bufferSize),
std::ostream(&_buf)
{
Expand Down
4 changes: 2 additions & 2 deletions Crypto/src/RSACipherImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -329,13 +329,13 @@ RSACipherImpl::~RSACipherImpl()
}


CryptoTransform* RSACipherImpl::createEncryptor()
CryptoTransform::Ptr RSACipherImpl::createEncryptor()
{
return new RSAEncryptImpl(_key.impl()->getRSA(), _paddingMode);
}


CryptoTransform* RSACipherImpl::createDecryptor()
CryptoTransform::Ptr RSACipherImpl::createDecryptor()
{
return new RSADecryptImpl(_key.impl()->getRSA(), _paddingMode);
}
Expand Down
6 changes: 3 additions & 3 deletions Crypto/testsuite/src/CryptoTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ void CryptoTest::testEncryptDecryptGCM()
for (std::size_t n = 1; n < MAX_DATA_SIZE; n++)
{
std::stringstream str;
CryptoTransform* pEncryptor = pCipher->createEncryptor();
CryptoTransform::Ptr pEncryptor = pCipher->createEncryptor();
CryptoOutputStream encryptorStream(str, pEncryptor);
std::string in(n, 'x');
encryptorStream << in;
Expand All @@ -231,7 +231,7 @@ void CryptoTest::testEncryptDecryptGCM()

std::string tag = pEncryptor->getTag();

CryptoTransform* pDecryptor = pCipher->createDecryptor();
CryptoTransform::Ptr pDecryptor = pCipher->createDecryptor();
pDecryptor->setTag(tag);
CryptoInputStream decryptorStream(str, pDecryptor);
std::string out;
Expand Down Expand Up @@ -318,7 +318,7 @@ void CryptoTest::testStreams()
DecryptingInputStream decryptor(sstr, *pCipher);
std::string result;
Poco::StreamCopier::copyToString(decryptor, result);

assertTrue (result == SECRET_MESSAGE);
assertTrue (decryptor.eof());
assertTrue (!decryptor.bad());
Expand Down
11 changes: 6 additions & 5 deletions Crypto/testsuite/src/EVPTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "Poco/StreamCopier.h"
#include "CppUnit/TestCaller.h"
#include "CppUnit/TestSuite.h"
#include <memory>
#include <sstream>
#include <fstream>
#include <iostream>
Expand All @@ -41,24 +42,24 @@ void EVPTest::testRSAEVPPKey()
{
try
{
RSAKey* key = new RSAKey(RSAKey::KL_1024, RSAKey::EXP_SMALL);
std::unique_ptr<RSAKey> key(new RSAKey(RSAKey::KL_1024, RSAKey::EXP_SMALL));
assertTrue(key->type() == Poco::Crypto::KeyPair::KT_RSA);
// construct EVPPKey from RSAKey*
EVPPKey* pKey = new EVPPKey(key);
EVPPKey* pKey = new EVPPKey(key.get());
// EVPPKey increments reference count, so freeing the original must be ok
delete key;
key.reset();

assertTrue (!pKey->isSupported(0));
assertTrue (!pKey->isSupported(-1));
assertTrue (pKey->isSupported(pKey->type()));
assertTrue (pKey->type() == EVP_PKEY_RSA);

// construct RSAKey from const EVPPKey&
key = new RSAKey(*pKey);
key.reset(new RSAKey(*pKey));
delete pKey;
assertTrue(key->type() == Poco::Crypto::KeyPair::KT_RSA);
// construct EVPPKey from RSAKey*
pKey = new EVPPKey(key);
pKey = new EVPPKey(key.get());
assertTrue (pKey->type() == EVP_PKEY_RSA);

BIO* bioPriv1 = BIO_new(BIO_s_mem());
Expand Down
11 changes: 6 additions & 5 deletions Data/SQLite/src/SessionImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ SessionImpl::SessionImpl(const std::string& fileName, std::size_t loginTimeout):
open();
setConnectionTimeout(loginTimeout);
setProperty("handle", _pDB);
addFeature("autoCommit",
&SessionImpl::autoCommit,
addFeature("autoCommit",
&SessionImpl::autoCommit,
&SessionImpl::isAutoCommit);
addProperty("connectionTimeout", &SessionImpl::setConnectionTimeout, &SessionImpl::getConnectionTimeout);
}
Expand Down Expand Up @@ -163,14 +163,15 @@ void SessionImpl::open(const std::string& connect)
if (rc == SQLITE_OK) break;
if (sw.elapsedSeconds() >= tout)
{
close();
Utility::throwException(_pDB, rc);
}
else Thread::sleep(10);
Thread::sleep(10);
close();
}
}
}
catch (SQLiteException& ex)
{
close();
throw ConnectionFailedException(ex.displayText());
}

Expand Down
2 changes: 1 addition & 1 deletion Data/SQLite/testsuite/src/SQLiteTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3410,7 +3410,7 @@ void SQLiteTest::testIllegalFilePath()
{
try
{
Session tmp (Poco::Data::SQLite::Connector::KEY, "\\/some\\/illegal\\/path\\/dummy.db", 1);
Session tmp(Poco::Data::SQLite::Connector::KEY, "\\/some\\/illegal\\/path\\/dummy.db", 1);
fail("must fail");
}
catch (ConnectionFailedException&)
Expand Down
Loading

0 comments on commit bccea84

Please sign in to comment.