[Libreoffice-commits] core.git: Branch 'feature/cib_contract3756' - 2 commits - include/oox offapi/com oox/source
Vasily Melenchuk (via logerrit)
logerrit at kemper.freedesktop.org
Sun Oct 13 20:56:25 UTC 2019
include/oox/crypto/AgileEngine.hxx | 8 ++--
include/oox/crypto/Standard2007Engine.hxx | 7 +---
offapi/com/sun/star/packages/XPackageEncryption.idl | 8 ----
oox/source/core/filterbase.cxx | 35 ++++++++++----------
oox/source/crypto/AgileEngine.cxx | 29 +++++++++++-----
oox/source/crypto/DocumentEncryption.cxx | 7 ----
oox/source/crypto/Standard2007Engine.cxx | 33 ++++++++++++------
7 files changed, 70 insertions(+), 57 deletions(-)
New commits:
commit b199349fb8adaf3eedf232aea607a5b9e909e2ac
Author: Vasily Melenchuk <vasily.melenchuk at cib.de>
AuthorDate: Sun Oct 13 23:53:22 2019 +0300
Commit: Vasily Melenchuk <vasily.melenchuk at cib.de>
CommitDate: Sun Oct 13 23:53:22 2019 +0300
oox: XPackageEncryption interface simplification
instead of two methods to write ecrypted data and encryption info
just one is used.
Change-Id: Ie31f363a0b76cfe5b67b15c1b98b0e556578b5c8
diff --git a/include/oox/crypto/AgileEngine.hxx b/include/oox/crypto/AgileEngine.hxx
index afef194e53e9..de3836ffdb19 100644
--- a/include/oox/crypto/AgileEngine.hxx
+++ b/include/oox/crypto/AgileEngine.hxx
@@ -128,6 +128,9 @@ private:
void setupEncryptionParameters(AgileEncryptionParameters const & rAgileEncryptionParameters);
bool setupEncryptionKey(OUString const & rPassword);
+ css::uno::Sequence<sal_Int8> writeEncryptionInfo();
+ css::uno::Sequence<sal_Int8> writeEncryptedDocument(const css::uno::Reference<css::io::XInputStream>& rxInputStream);
+
public:
AgileEngine(const css::uno::Reference< css::uno::XComponentContext >& rxContext);
@@ -143,10 +146,7 @@ public:
// Encryption
- virtual css::uno::Sequence<css::beans::NamedValue> SAL_CALL writeEncryptionInfo() override;
-
- virtual void SAL_CALL encrypt(const css::uno::Reference<css::io::XInputStream>& rxInputStream,
- css::uno::Reference<css::io::XOutputStream>& rxOutputStream) override;
+ virtual css::uno::Sequence<css::beans::NamedValue> SAL_CALL encrypt(const css::uno::Reference<css::io::XInputStream>& rxInputStream) override;
virtual sal_Bool SAL_CALL setupEncryption(const css::uno::Sequence<css::beans::NamedValue>& rMediaEncData) override;
diff --git a/include/oox/crypto/Standard2007Engine.hxx b/include/oox/crypto/Standard2007Engine.hxx
index feaf6a3ada6f..50be627a86e7 100644
--- a/include/oox/crypto/Standard2007Engine.hxx
+++ b/include/oox/crypto/Standard2007Engine.hxx
@@ -37,6 +37,8 @@ class OOX_DLLPUBLIC Standard2007Engine : public cppu::WeakImplHelper<css::packag
bool calculateEncryptionKey(const OUString& rPassword);
css::uno::Reference<css::io::XInputStream> getStream(const css::uno::Sequence<css::beans::NamedValue> & rStreams, const OUString sStreamName);
+ css::uno::Sequence<sal_Int8> writeEncryptionInfo();
+ css::uno::Sequence<sal_Int8> writeEncryptedDocument(const css::uno::Reference<css::io::XInputStream>& rxInputStream);
public:
Standard2007Engine(const css::uno::Reference<css::uno::XComponentContext>& rxContext);
@@ -53,10 +55,7 @@ public:
// Encryption
- virtual css::uno::Sequence<css::beans::NamedValue> SAL_CALL writeEncryptionInfo() override;
-
- virtual void SAL_CALL encrypt(const css::uno::Reference<css::io::XInputStream>& rxInputStream,
- css::uno::Reference<css::io::XOutputStream>& rxOutputStream) override;
+ virtual css::uno::Sequence<css::beans::NamedValue> SAL_CALL encrypt(const css::uno::Reference<css::io::XInputStream>& rxInputStream) override;
virtual sal_Bool SAL_CALL setupEncryption(const css::uno::Sequence<css::beans::NamedValue>& rMediaEncData) override;
diff --git a/offapi/com/sun/star/packages/XPackageEncryption.idl b/offapi/com/sun/star/packages/XPackageEncryption.idl
index 298a089af6c7..0fba1d9c3ba7 100644
--- a/offapi/com/sun/star/packages/XPackageEncryption.idl
+++ b/offapi/com/sun/star/packages/XPackageEncryption.idl
@@ -52,11 +52,6 @@ interface XPackageEncryption: com::sun::star::uno::XInterface
/**
TODO
*/
- sequence<com::sun::star::beans::NamedValue> writeEncryptionInfo();
-
- /**
- TODO
- */
sequence<com::sun::star::beans::NamedValue> createEncryptionData([in] string rPassword);
/**
@@ -67,8 +62,7 @@ interface XPackageEncryption: com::sun::star::uno::XInterface
/**
TODO
*/
- void encrypt([in] com::sun::star::io::XInputStream rxInputStream,
- [out] com::sun::star::io::XOutputStream rxOutputStream);
+ sequence<com::sun::star::beans::NamedValue> encrypt([in] com::sun::star::io::XInputStream rxInputStream);
/**
TODO
diff --git a/oox/source/crypto/AgileEngine.cxx b/oox/source/crypto/AgileEngine.cxx
index 35104903d918..54dd841ef2bf 100644
--- a/oox/source/crypto/AgileEngine.cxx
+++ b/oox/source/crypto/AgileEngine.cxx
@@ -756,7 +756,7 @@ bool AgileEngine::setupEncryptionKey(OUString const & rPassword)
return true;
}
-css::uno::Sequence<css::beans::NamedValue> AgileEngine::writeEncryptionInfo()
+css::uno::Sequence<sal_Int8> AgileEngine::writeEncryptionInfo()
{
Reference<XOutputStream> aEncryptionInfoStream(
mxContext->getServiceManager()->createInstanceWithContext("com.sun.star.io.SequenceOutputStream", mxContext),
@@ -820,20 +820,19 @@ css::uno::Sequence<css::beans::NamedValue> AgileEngine::writeEncryptionInfo()
rStream.close();
aEncryptionInfoStream->flush();
- // Store all streams into sequence and return back
- comphelper::SequenceAsHashMap aStreams;
-
Reference<XSequenceOutputStream> aEncryptionInfoSequenceStream(aEncryptionInfoStream, UNO_QUERY);
- aStreams["EncryptionInfo"] <<= aEncryptionInfoSequenceStream->getWrittenBytes();
- return aStreams.getAsConstNamedValueList();
+ return aEncryptionInfoSequenceStream->getWrittenBytes();
}
-void AgileEngine::encrypt(const css::uno::Reference<css::io::XInputStream> & rxInputStream,
- css::uno::Reference<css::io::XOutputStream> & rxOutputStream)
+css::uno::Sequence<sal_Int8> AgileEngine::writeEncryptedDocument(const css::uno::Reference<css::io::XInputStream>& rxInputStream)
{
CryptoHash aCryptoHash(mInfo.hmacKey, cryptoHashTypeFromString(mInfo.hashAlgorithm));
- BinaryXOutputStream aBinaryOutputStream(rxOutputStream, false);
+ Reference<XOutputStream> aOutputStream(
+ mxContext->getServiceManager()->createInstanceWithContext("com.sun.star.io.SequenceOutputStream", mxContext),
+ UNO_QUERY);
+ BinaryXOutputStream aBinaryOutputStream(aOutputStream, false);
+
BinaryXInputStream aBinaryInputStream(rxInputStream, false);
Reference<XSeekable> xSeekable(rxInputStream, UNO_QUERY);
sal_uInt32 nLength = xSeekable->getLength();
@@ -890,6 +889,18 @@ void AgileEngine::encrypt(const css::uno::Reference<css::io::XInputStream> & rx
}
mInfo.hmacHash = aCryptoHash.finalize();
encryptHmacValue();
+
+ Reference<XSequenceOutputStream> aSequenceStream(aOutputStream, UNO_QUERY);
+ return aSequenceStream->getWrittenBytes();
+}
+
+
+css::uno::Sequence<css::beans::NamedValue> AgileEngine::encrypt(const css::uno::Reference<css::io::XInputStream> & rxInputStream)
+{
+ comphelper::SequenceAsHashMap aStreams;
+ aStreams["EncryptedPackage"] <<= writeEncryptedDocument(rxInputStream);
+ aStreams["EncryptionInfo"] <<= writeEncryptionInfo();
+ return aStreams.getAsConstNamedValueList();
}
} // namespace core
diff --git a/oox/source/crypto/DocumentEncryption.cxx b/oox/source/crypto/DocumentEncryption.cxx
index 2dba0f035df5..2f0457911aed 100644
--- a/oox/source/crypto/DocumentEncryption.cxx
+++ b/oox/source/crypto/DocumentEncryption.cxx
@@ -78,12 +78,7 @@ bool DocumentEncryption::encrypt()
mxPackageEncryption->setupEncryption(mMediaEncData);
- Reference<XOutputStream> xOutputStream(mrOleStorage.openOutputStream("EncryptedPackage"), UNO_SET_THROW);
- mxPackageEncryption->encrypt(xInputStream, xOutputStream);
- xOutputStream->flush();
- xOutputStream->closeOutput();
-
- Sequence<NamedValue> aStreams = mxPackageEncryption->writeEncryptionInfo();
+ Sequence<NamedValue> aStreams = mxPackageEncryption->encrypt(xInputStream);
for (const NamedValue & aStream : aStreams)
{
diff --git a/oox/source/crypto/Standard2007Engine.cxx b/oox/source/crypto/Standard2007Engine.cxx
index 50f23e2cf491..9ddde339b1d5 100644
--- a/oox/source/crypto/Standard2007Engine.cxx
+++ b/oox/source/crypto/Standard2007Engine.cxx
@@ -257,7 +257,7 @@ sal_Bool Standard2007Engine::setupEncryption(const css::uno::Sequence<css::beans
return true;
}
-css::uno::Sequence<css::beans::NamedValue> Standard2007Engine::writeEncryptionInfo()
+css::uno::Sequence<sal_Int8> Standard2007Engine::writeEncryptionInfo()
{
Reference<XOutputStream> aEncryptionInfoStream(
mxContext->getServiceManager()->createInstanceWithContext("com.sun.star.io.SequenceOutputStream", mxContext),
@@ -283,21 +283,17 @@ css::uno::Sequence<css::beans::NamedValue> Standard2007Engine::writeEncryptionIn
rStream.close();
aEncryptionInfoStream->flush();
- // Store all streams into sequence and return back
- comphelper::SequenceAsHashMap aStreams;
-
Reference<XSequenceOutputStream> aEncryptionInfoSequenceStream(aEncryptionInfoStream, UNO_QUERY);
- aStreams["EncryptionInfo"] <<= aEncryptionInfoSequenceStream->getWrittenBytes();
- return aStreams.getAsConstNamedValueList();
+ return aEncryptionInfoSequenceStream->getWrittenBytes();
}
-void Standard2007Engine::encrypt(const css::uno::Reference<css::io::XInputStream> & rxInputStream,
- css::uno::Reference<css::io::XOutputStream> & rxOutputStream)
+css::uno::Sequence<sal_Int8> Standard2007Engine::writeEncryptedDocument(const css::uno::Reference<css::io::XInputStream> & rxInputStream)
{
- if (mKey.empty())
- return;
+ Reference<XOutputStream> aOutputStream(
+ mxContext->getServiceManager()->createInstanceWithContext("com.sun.star.io.SequenceOutputStream", mxContext),
+ UNO_QUERY);
+ BinaryXOutputStream aBinaryOutputStream(aOutputStream, false);
- BinaryXOutputStream aBinaryOutputStream(rxOutputStream, false);
BinaryXInputStream aBinaryInputStream(rxInputStream, false);
Reference<XSeekable> xSeekable(rxInputStream, UNO_QUERY);
@@ -321,6 +317,21 @@ void Standard2007Engine::encrypt(const css::uno::Reference<css::io::XInputStream
outputLength = aEncryptor.update(outputBuffer, inputBuffer, inputLength);
aBinaryOutputStream.writeMemory(outputBuffer.data(), outputLength);
}
+
+ Reference<XSequenceOutputStream> aSequenceStream(aOutputStream, UNO_QUERY);
+ return aSequenceStream->getWrittenBytes();
+}
+
+css::uno::Sequence<css::beans::NamedValue> Standard2007Engine::encrypt(const css::uno::Reference<css::io::XInputStream> & rxInputStream)
+{
+ if (mKey.empty())
+ return css::uno::Sequence<css::beans::NamedValue>();
+
+ comphelper::SequenceAsHashMap aStreams;
+
+ aStreams["EncryptedPackage"] <<= writeEncryptedDocument(rxInputStream);
+ aStreams["EncryptionInfo"] <<= writeEncryptionInfo();
+ return aStreams.getAsConstNamedValueList();
}
css::uno::Reference<css::io::XInputStream> Standard2007Engine::getStream(const css::uno::Sequence<css::beans::NamedValue> & rStreams, const OUString sStreamName)
commit ce684e7d06fc37ac6b672f5676e6113fcf41a03e
Author: Vasily Melenchuk <vasily.melenchuk at cib.de>
AuthorDate: Sun Oct 13 21:29:24 2019 +0300
Commit: Vasily Melenchuk <vasily.melenchuk at cib.de>
CommitDate: Sun Oct 13 21:29:24 2019 +0300
oox: avoid control freeze on exception
If exception happens somewhere in exportDocument() or later,
document controls could be remain locked and later cause crash
due to missing exception handler.
To avoid this simple lock guard was implemented releasing controls
even on exception.
Change-Id: I1ce4e487833ddc4b1f1b708f3a7e10bb299ef354
diff --git a/oox/source/core/filterbase.cxx b/oox/source/core/filterbase.cxx
index 1346353c9d22..1a0ae42ebcf4 100644
--- a/oox/source/core/filterbase.cxx
+++ b/oox/source/core/filterbase.cxx
@@ -109,6 +109,23 @@ DocumentOpenedGuard::~DocumentOpenedGuard()
rUrlPool.maUrls.erase( maUrl );
}
+class ControllerLockGuard
+{
+public:
+ explicit ControllerLockGuard(const Reference< XModel > & xModel)
+ : mxModel (xModel)
+ {
+ mxModel->lockControllers();
+ }
+
+ ~ControllerLockGuard()
+ {
+ mxModel->unlockControllers();
+ }
+private:
+ const Reference< XModel > & mxModel;
+};
+
} // namespace
/** Specifies whether this filter is an import or export filter. */
@@ -158,8 +175,6 @@ struct FilterBaseImpl
/// @throws IllegalArgumentException
void setDocumentModel( const Reference< XComponent >& rxComponent );
-
- void initializeFilter();
};
FilterBaseImpl::FilterBaseImpl( const Reference< XComponentContext >& rxContext ) :
@@ -184,18 +199,6 @@ void FilterBaseImpl::setDocumentModel( const Reference< XComponent >& rxComponen
}
}
-void FilterBaseImpl::initializeFilter()
-{
- try
- {
- // lock the model controllers
- mxModel->lockControllers();
- }
- catch( Exception& )
- {
- }
-}
-
FilterBase::FilterBase( const Reference< XComponentContext >& rxContext ) :
mxImpl( new FilterBaseImpl( rxContext ) )
{
@@ -477,7 +480,8 @@ sal_Bool SAL_CALL FilterBase::filter( const Sequence< PropertyValue >& rMediaDes
DocumentOpenedGuard aOpenedGuard( mxImpl->maFileUrl );
if( aOpenedGuard.isValid() || mxImpl->maFileUrl.isEmpty() )
{
- mxImpl->initializeFilter();
+ ControllerLockGuard aCtrlLockGuard(mxImpl->mxModel);
+
switch( mxImpl->meDirection )
{
case FILTERDIRECTION_UNKNOWN:
@@ -497,7 +501,6 @@ sal_Bool SAL_CALL FilterBase::filter( const Sequence< PropertyValue >& rMediaDes
}
break;
}
- mxImpl->mxModel->unlockControllers();
}
return bRet;
}
More information about the Libreoffice-commits
mailing list