Kaydet (Commit) 057c33b6 authored tarafından Tomaž Vajngerl's avatar Tomaž Vajngerl Kaydeden (comit) Tomaž Vajngerl

oox: encryption/decryption test for Standard2007Engine

Change-Id: I8de25182c40004edffad4452179f191a75f130d9
Reviewed-on: https://gerrit.libreoffice.org/56300
Tested-by: Jenkins
Reviewed-by: 's avatarTomaž Vajngerl <quikee@gmail.com>
üst 32f55666
...@@ -11,8 +11,9 @@ ...@@ -11,8 +11,9 @@
#ifndef INCLUDED_OOX_CRYPTO_STANDARD2007ENGINE_HXX #ifndef INCLUDED_OOX_CRYPTO_STANDARD2007ENGINE_HXX
#define 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 <oox/crypto/CryptoEngine.hxx>
#include <filter/msfilter/mscodec.hxx>
#include <rtl/digest.h> #include <rtl/digest.h>
#include <rtl/ustring.hxx> #include <rtl/ustring.hxx>
#include <sal/types.h> #include <sal/types.h>
...@@ -25,7 +26,7 @@ namespace oox { ...@@ -25,7 +26,7 @@ namespace oox {
namespace oox { namespace oox {
namespace core { namespace core {
class Standard2007Engine : public CryptoEngine class OOX_DLLPUBLIC Standard2007Engine : public CryptoEngine
{ {
msfilter::StandardEncryptionInfo mInfo; msfilter::StandardEncryptionInfo mInfo;
......
...@@ -42,7 +42,7 @@ namespace oox { ...@@ -42,7 +42,7 @@ namespace oox {
The binary data in the stream is written in little-endian format. 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: public:
/** Derived classes implement writing the contents of the passed data /** Derived classes implement writing the contents of the passed data
...@@ -125,7 +125,7 @@ void BinaryOutputStream::writeValue( Type nValue ) ...@@ -125,7 +125,7 @@ void BinaryOutputStream::writeValue( Type nValue )
The binary data in the stream is written in little-endian format. 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: public:
/** Constructs the wrapper object for the passed output stream. /** Constructs the wrapper object for the passed output stream.
......
# -*- 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:
...@@ -20,6 +20,7 @@ $(eval $(call gb_Module_add_check_targets,oox,\ ...@@ -20,6 +20,7 @@ $(eval $(call gb_Module_add_check_targets,oox,\
CppunitTest_oox_tokenmap \ CppunitTest_oox_tokenmap \
CppunitTest_oox_vba_compression \ CppunitTest_oox_vba_compression \
CppunitTest_oox_vba_encryption \ CppunitTest_oox_vba_encryption \
CppunitTest_oox_crypto \
)) ))
# vim: set noet sw=4 ts=4: # vim: set noet sw=4 ts=4:
/* -*- 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: */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment