[Libreoffice-commits] core.git: include/oox oox/CppunitTest_oox_crypto.mk oox/Module_oox.mk oox/qa
Tomaž Vajngerl
tomaz.vajngerl at collabora.co.uk
Fri Jun 22 21:42:49 UTC 2018
include/oox/crypto/Standard2007Engine.hxx | 5 -
include/oox/helper/binaryoutputstream.hxx | 4 -
oox/CppunitTest_oox_crypto.mk | 74 ++++++++++++++++++++
oox/Module_oox.mk | 1
oox/qa/unit/CryptoTest.cxx | 106 ++++++++++++++++++++++++++++++
5 files changed, 186 insertions(+), 4 deletions(-)
New commits:
commit 057c33b6609fe49efb6fa757db5f336acddb2a3d
Author: Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
Date: Fri Jun 22 16:15:38 2018 +0200
oox: encryption/decryption test for Standard2007Engine
Change-Id: I8de25182c40004edffad4452179f191a75f130d9
Reviewed-on: https://gerrit.libreoffice.org/56300
Tested-by: Jenkins
Reviewed-by: Tomaž Vajngerl <quikee at gmail.com>
diff --git a/include/oox/crypto/Standard2007Engine.hxx b/include/oox/crypto/Standard2007Engine.hxx
index 40aba8137161..ea92c4b5df51 100644
--- a/include/oox/crypto/Standard2007Engine.hxx
+++ b/include/oox/crypto/Standard2007Engine.hxx
@@ -11,8 +11,9 @@
#ifndef INCLUDED_OOX_CRYPTO_STANDARD2007ENGINE_HXX
#define INCLUDED_OOX_CRYPTO_STANDARD2007ENGINE_HXX
-#include <filter/msfilter/mscodec.hxx>
+#include <oox/dllapi.h>
#include <oox/crypto/CryptoEngine.hxx>
+#include <filter/msfilter/mscodec.hxx>
#include <rtl/digest.h>
#include <rtl/ustring.hxx>
#include <sal/types.h>
@@ -25,7 +26,7 @@ namespace oox {
namespace oox {
namespace core {
-class Standard2007Engine : public CryptoEngine
+class OOX_DLLPUBLIC Standard2007Engine : public CryptoEngine
{
msfilter::StandardEncryptionInfo mInfo;
diff --git a/include/oox/helper/binaryoutputstream.hxx b/include/oox/helper/binaryoutputstream.hxx
index fe0ce9ae34c5..7041131d81e3 100644
--- a/include/oox/helper/binaryoutputstream.hxx
+++ b/include/oox/helper/binaryoutputstream.hxx
@@ -42,7 +42,7 @@ namespace oox {
The binary data in the stream is written in little-endian format.
*/
-class BinaryOutputStream : public virtual BinaryStreamBase
+class OOX_DLLPUBLIC BinaryOutputStream : public virtual BinaryStreamBase
{
public:
/** Derived classes implement writing the contents of the passed data
@@ -125,7 +125,7 @@ void BinaryOutputStream::writeValue( Type nValue )
The binary data in the stream is written in little-endian format.
*/
-class BinaryXOutputStream : public BinaryXSeekableStream, public BinaryOutputStream
+class OOX_DLLPUBLIC BinaryXOutputStream : public BinaryXSeekableStream, public BinaryOutputStream
{
public:
/** Constructs the wrapper object for the passed output stream.
diff --git a/oox/CppunitTest_oox_crypto.mk b/oox/CppunitTest_oox_crypto.mk
new file mode 100644
index 000000000000..64fd4df490b5
--- /dev/null
+++ b/oox/CppunitTest_oox_crypto.mk
@@ -0,0 +1,74 @@
+# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*-
+#
+#
+# This file is part of the LibreOffice project.
+#
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+#
+
+$(eval $(call gb_CppunitTest_CppunitTest,oox_crypto))
+
+$(eval $(call gb_CppunitTest_add_exception_objects,oox_crypto,\
+ oox/qa/unit/CryptoTest \
+))
+
+$(eval $(call gb_CppunitTest_use_sdk_api,oox_crypto))
+
+$(eval $(call gb_CppunitTest_use_libraries,oox_crypto,\
+ basegfx \
+ comphelper \
+ cppu \
+ cppuhelper \
+ editeng \
+ drawinglayer \
+ msfilter \
+ sal \
+ oox \
+ sax \
+ sfx \
+ svl \
+ svt \
+ svx \
+ svxcore \
+ sot \
+ tl \
+ unotest \
+ utl \
+ vcl \
+ xo \
+ xmlscript \
+))
+
+$(eval $(call gb_CppunitTest_use_api,oox_crypto,\
+ offapi \
+ udkapi \
+))
+
+$(eval $(call gb_CppunitTest_use_ure,oox_crypto))
+$(eval $(call gb_CppunitTest_use_vcl,oox_crypto))
+$(eval $(call gb_CppunitTest_use_configuration,oox_crypto))
+
+$(eval $(call gb_CppunitTest_use_components,oox_crypto,\
+ comphelper/util/comphelp \
+ configmgr/source/configmgr \
+ filter/source/config/cache/filterconfig1 \
+ filter/source/storagefilterdetect/storagefd \
+ i18npool/util/i18npool \
+ package/source/xstor/xstor \
+ package/util/package2 \
+ sfx2/util/sfx \
+ sot/util/sot \
+ svl/source/fsstor/fsstorage \
+ svtools/util/svt \
+ ucb/source/core/ucb1 \
+ ucb/source/ucp/file/ucpfile1 \
+ ucb/source/ucp/tdoc/ucptdoc1 \
+ unotools/util/utl \
+ uui/util/uui \
+ vcl/vcl.common \
+))
+
+
+# vim: set noet sw=4 ts=4:
diff --git a/oox/Module_oox.mk b/oox/Module_oox.mk
index 4d7a79e3d60c..db79a0f8e093 100644
--- a/oox/Module_oox.mk
+++ b/oox/Module_oox.mk
@@ -20,6 +20,7 @@ $(eval $(call gb_Module_add_check_targets,oox,\
CppunitTest_oox_tokenmap \
CppunitTest_oox_vba_compression \
CppunitTest_oox_vba_encryption \
+ CppunitTest_oox_crypto \
))
# vim: set noet sw=4 ts=4:
diff --git a/oox/qa/unit/CryptoTest.cxx b/oox/qa/unit/CryptoTest.cxx
new file mode 100644
index 000000000000..efe3e0cb5d6e
--- /dev/null
+++ b/oox/qa/unit/CryptoTest.cxx
@@ -0,0 +1,106 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#include <cppunit/plugin/TestPlugIn.h>
+#include <cppunit/extensions/HelperMacros.h>
+#include <cppunit/TestFixture.h>
+
+#include <algorithm>
+#include <tools/stream.hxx>
+#include <unotools/streamwrap.hxx>
+
+#include <oox/crypto/Standard2007Engine.hxx>
+#include <oox/helper/binaryinputstream.hxx>
+#include <oox/helper/binaryoutputstream.hxx>
+
+using namespace css;
+
+class CryptoTest : public CppUnit::TestFixture
+{
+public:
+ void testStandard2007();
+
+ CPPUNIT_TEST_SUITE(CryptoTest);
+ CPPUNIT_TEST(testStandard2007);
+ CPPUNIT_TEST_SUITE_END();
+};
+
+void CryptoTest::testStandard2007()
+{
+ oox::core::Standard2007Engine aEngine;
+ {
+ SvMemoryStream aEncryptionInfo;
+ oox::BinaryXOutputStream aBinaryEncryptionInfoOutputStream(
+ new utl::OSeekableOutputStreamWrapper(aEncryptionInfo), false);
+
+ aEngine.writeEncryptionInfo("Password", aBinaryEncryptionInfoOutputStream);
+ aBinaryEncryptionInfoOutputStream.close();
+
+ CPPUNIT_ASSERT_EQUAL(sal_uInt64(224), aEncryptionInfo.GetSize());
+ }
+
+ SvMemoryStream aUnencryptedInput;
+ SvMemoryStream aEncryptedStream;
+
+ OString aTestString = OUStringToOString("1234567890ABCDEFG", RTL_TEXTENCODING_UTF8);
+
+ aUnencryptedInput.WriteOString(aTestString);
+ aUnencryptedInput.Seek(STREAM_SEEK_TO_BEGIN);
+
+ {
+ oox::BinaryXInputStream aBinaryInputStream(
+ new utl::OSeekableInputStreamWrapper(aUnencryptedInput), true);
+ oox::BinaryXOutputStream aBinaryOutputStream(
+ new utl::OSeekableOutputStreamWrapper(aEncryptedStream), true);
+
+ aEncryptedStream.WriteUInt32(aUnencryptedInput.GetSize());
+ aEncryptedStream.WriteUInt32(0U);
+
+ aEngine.encrypt(aBinaryInputStream, aBinaryOutputStream);
+ aBinaryOutputStream.close();
+ aBinaryInputStream.close();
+
+ const sal_uInt8* pData = static_cast<const sal_uInt8*>(aEncryptedStream.GetData());
+ sal_uInt64 nSize = aEncryptedStream.GetSize();
+
+ std::vector<sal_uInt8> aData(nSize);
+ std::copy(pData, pData + nSize, aData.data());
+
+ CPPUNIT_ASSERT_EQUAL(sal_uInt64(40), nSize);
+ }
+
+ aEncryptedStream.Seek(STREAM_SEEK_TO_BEGIN);
+ SvMemoryStream aUnencryptedOutput;
+
+ {
+ oox::BinaryXInputStream aBinaryInputStream(
+ new utl::OSeekableInputStreamWrapper(aEncryptedStream), true);
+ oox::BinaryXOutputStream aBinaryOutputStream(
+ new utl::OSeekableOutputStreamWrapper(aUnencryptedOutput), true);
+
+ aEngine.decrypt(aBinaryInputStream, aBinaryOutputStream);
+ aBinaryOutputStream.close();
+ aBinaryInputStream.close();
+
+ const sal_Char* pData = static_cast<const sal_Char*>(aUnencryptedOutput.GetData());
+ sal_uInt64 nSize = aUnencryptedOutput.GetSize();
+
+ CPPUNIT_ASSERT_EQUAL(sal_uInt64(32), nSize);
+
+ OString aString(pData);
+
+ CPPUNIT_ASSERT_EQUAL(aTestString, aString);
+ }
+}
+
+CPPUNIT_TEST_SUITE_REGISTRATION(CryptoTest);
+
+CPPUNIT_PLUGIN_IMPLEMENT();
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
More information about the Libreoffice-commits
mailing list