fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / oox / source / crypto / DocumentEncryption.cxx
blobcd6527aa95a2c25c66a962d016a4efe9d8ba11d4
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 */
11 #include "oox/crypto/DocumentEncryption.hxx"
13 #include <com/sun/star/io/XSeekable.hpp>
15 #include "oox/helper/binaryinputstream.hxx"
16 #include "oox/helper/binaryoutputstream.hxx"
18 namespace oox {
19 namespace core {
21 using namespace css::beans;
22 using namespace css::io;
23 using namespace css::lang;
24 using namespace css::uno;
26 using namespace std;
28 DocumentEncryption::DocumentEncryption(Reference< XStream > xDocumentStream, oox::ole::OleStorage& rOleStorage, const OUString& aPassword) :
29 mxDocumentStream(xDocumentStream),
30 mrOleStorage(rOleStorage),
31 maPassword(aPassword)
34 bool DocumentEncryption::encrypt()
36 Reference< XInputStream > xInputStream ( mxDocumentStream->getInputStream(), UNO_SET_THROW );
37 Reference< XSeekable > xSeekable( xInputStream, UNO_QUERY );
39 if (!xSeekable.is())
40 return false;
42 sal_uInt32 aLength = xSeekable->getLength();
44 if (!mrOleStorage.isStorage())
45 return false;
47 Reference< XOutputStream > xEncryptionInfo( mrOleStorage.openOutputStream( "EncryptionInfo" ), UNO_SET_THROW );
48 BinaryXOutputStream aEncryptionInfoBinaryOutputStream( xEncryptionInfo, false );
50 mEngine.writeEncryptionInfo(maPassword, aEncryptionInfoBinaryOutputStream);
52 aEncryptionInfoBinaryOutputStream.close();
53 xEncryptionInfo->flush();
54 xEncryptionInfo->closeOutput();
56 Reference< XOutputStream > xEncryptedPackage( mrOleStorage.openOutputStream( "EncryptedPackage" ), UNO_SET_THROW );
57 BinaryXOutputStream aEncryptedPackageStream( xEncryptedPackage, false );
59 BinaryXInputStream aDocumentInputStream( xInputStream, false );
60 aDocumentInputStream.seekToStart();
62 aEncryptedPackageStream.WriteUInt32( aLength ); // size
63 aEncryptedPackageStream.WriteUInt32( 0U ); // reserved
65 mEngine.encrypt(aDocumentInputStream, aEncryptedPackageStream);
67 aEncryptedPackageStream.close();
68 aDocumentInputStream.close();
70 xEncryptedPackage->flush();
71 xEncryptedPackage->closeOutput();
73 return true;
76 } // namespace core
77 } // namespace oox
79 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */