xref: /AOO41X/main/package/source/zippackage/ZipPackageStream.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * ( a copy is included in the LICENSE file that accompanied this code ).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER( update_precomp.py ): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_package.hxx"
30*cdf0e10cSrcweir #include <com/sun/star/packages/zip/ZipConstants.hpp>
31*cdf0e10cSrcweir #include <com/sun/star/embed/StorageFormats.hpp>
32*cdf0e10cSrcweir #include <com/sun/star/packages/zip/ZipIOException.hpp>
33*cdf0e10cSrcweir #include <com/sun/star/io/XInputStream.hpp>
34*cdf0e10cSrcweir #include <com/sun/star/io/XOutputStream.hpp>
35*cdf0e10cSrcweir #include <com/sun/star/io/XStream.hpp>
36*cdf0e10cSrcweir #include <com/sun/star/io/XSeekable.hpp>
37*cdf0e10cSrcweir #include <com/sun/star/xml/crypto/DigestID.hpp>
38*cdf0e10cSrcweir #include <com/sun/star/xml/crypto/CipherID.hpp>
39*cdf0e10cSrcweir 
40*cdf0e10cSrcweir 
41*cdf0e10cSrcweir #include <ZipPackageStream.hxx>
42*cdf0e10cSrcweir #include <ZipPackage.hxx>
43*cdf0e10cSrcweir #include <ZipFile.hxx>
44*cdf0e10cSrcweir #include <EncryptedDataHeader.hxx>
45*cdf0e10cSrcweir #include <vos/diagnose.hxx>
46*cdf0e10cSrcweir #include "wrapstreamforshare.hxx"
47*cdf0e10cSrcweir 
48*cdf0e10cSrcweir #include <comphelper/seekableinput.hxx>
49*cdf0e10cSrcweir #include <comphelper/storagehelper.hxx>
50*cdf0e10cSrcweir 
51*cdf0e10cSrcweir #include <rtl/instance.hxx>
52*cdf0e10cSrcweir 
53*cdf0e10cSrcweir #include <PackageConstants.hxx>
54*cdf0e10cSrcweir 
55*cdf0e10cSrcweir using namespace com::sun::star::packages::zip::ZipConstants;
56*cdf0e10cSrcweir using namespace com::sun::star::packages::zip;
57*cdf0e10cSrcweir using namespace com::sun::star::uno;
58*cdf0e10cSrcweir using namespace com::sun::star::lang;
59*cdf0e10cSrcweir using namespace com::sun::star;
60*cdf0e10cSrcweir using namespace cppu;
61*cdf0e10cSrcweir using namespace rtl;
62*cdf0e10cSrcweir 
63*cdf0e10cSrcweir namespace { struct lcl_CachedImplId : public rtl::Static< Sequence < sal_Int8 >, lcl_CachedImplId > {}; }
64*cdf0e10cSrcweir 
65*cdf0e10cSrcweir const ::com::sun::star::uno::Sequence < sal_Int8 >& ZipPackageStream::static_getImplementationId()
66*cdf0e10cSrcweir {
67*cdf0e10cSrcweir     return lcl_CachedImplId::get();
68*cdf0e10cSrcweir }
69*cdf0e10cSrcweir 
70*cdf0e10cSrcweir ZipPackageStream::ZipPackageStream ( ZipPackage & rNewPackage,
71*cdf0e10cSrcweir 									const uno::Reference< XMultiServiceFactory >& xFactory,
72*cdf0e10cSrcweir 									sal_Bool bAllowRemoveOnInsert )
73*cdf0e10cSrcweir : m_xFactory( xFactory )
74*cdf0e10cSrcweir , rZipPackage( rNewPackage )
75*cdf0e10cSrcweir , bToBeCompressed ( sal_True )
76*cdf0e10cSrcweir , bToBeEncrypted ( sal_False )
77*cdf0e10cSrcweir , bHaveOwnKey ( sal_False )
78*cdf0e10cSrcweir , bIsEncrypted ( sal_False )
79*cdf0e10cSrcweir , m_nImportedStartKeyAlgorithm( 0 )
80*cdf0e10cSrcweir , m_nImportedEncryptionAlgorithm( 0 )
81*cdf0e10cSrcweir , m_nImportedChecksumAlgorithm( 0 )
82*cdf0e10cSrcweir , m_nImportedDerivedKeySize( 0 )
83*cdf0e10cSrcweir , m_nStreamMode( PACKAGE_STREAM_NOTSET )
84*cdf0e10cSrcweir , m_nMagicalHackPos( 0 )
85*cdf0e10cSrcweir , m_nMagicalHackSize( 0 )
86*cdf0e10cSrcweir , m_bHasSeekable( sal_False )
87*cdf0e10cSrcweir , m_bCompressedIsSetFromOutside( sal_False )
88*cdf0e10cSrcweir , m_bFromManifest( sal_False )
89*cdf0e10cSrcweir , m_bUseWinEncoding( false )
90*cdf0e10cSrcweir {
91*cdf0e10cSrcweir 	OSL_ENSURE( m_xFactory.is(), "No factory is provided to ZipPackageStream!\n" );
92*cdf0e10cSrcweir 
93*cdf0e10cSrcweir 	this->mbAllowRemoveOnInsert = bAllowRemoveOnInsert;
94*cdf0e10cSrcweir 
95*cdf0e10cSrcweir 	SetFolder ( sal_False );
96*cdf0e10cSrcweir 	aEntry.nVersion		= -1;
97*cdf0e10cSrcweir 	aEntry.nFlag		= 0;
98*cdf0e10cSrcweir 	aEntry.nMethod		= -1;
99*cdf0e10cSrcweir 	aEntry.nTime		= -1;
100*cdf0e10cSrcweir 	aEntry.nCrc			= -1;
101*cdf0e10cSrcweir 	aEntry.nCompressedSize	= -1;
102*cdf0e10cSrcweir 	aEntry.nSize		= -1;
103*cdf0e10cSrcweir 	aEntry.nOffset		= -1;
104*cdf0e10cSrcweir 	aEntry.nPathLen		= -1;
105*cdf0e10cSrcweir 	aEntry.nExtraLen	= -1;
106*cdf0e10cSrcweir 
107*cdf0e10cSrcweir 	Sequence < sal_Int8 > &rCachedImplId = lcl_CachedImplId::get();
108*cdf0e10cSrcweir 	if ( !rCachedImplId.getLength() )
109*cdf0e10cSrcweir 	    rCachedImplId = getImplementationId();
110*cdf0e10cSrcweir }
111*cdf0e10cSrcweir 
112*cdf0e10cSrcweir ZipPackageStream::~ZipPackageStream( void )
113*cdf0e10cSrcweir {
114*cdf0e10cSrcweir }
115*cdf0e10cSrcweir 
116*cdf0e10cSrcweir void ZipPackageStream::setZipEntryOnLoading( const ZipEntry &rInEntry )
117*cdf0e10cSrcweir {
118*cdf0e10cSrcweir 	aEntry.nVersion = rInEntry.nVersion;
119*cdf0e10cSrcweir 	aEntry.nFlag = rInEntry.nFlag;
120*cdf0e10cSrcweir 	aEntry.nMethod = rInEntry.nMethod;
121*cdf0e10cSrcweir 	aEntry.nTime = rInEntry.nTime;
122*cdf0e10cSrcweir 	aEntry.nCrc = rInEntry.nCrc;
123*cdf0e10cSrcweir 	aEntry.nCompressedSize = rInEntry.nCompressedSize;
124*cdf0e10cSrcweir 	aEntry.nSize = rInEntry.nSize;
125*cdf0e10cSrcweir 	aEntry.nOffset = rInEntry.nOffset;
126*cdf0e10cSrcweir 	aEntry.sPath = rInEntry.sPath;
127*cdf0e10cSrcweir 	aEntry.nPathLen = rInEntry.nPathLen;
128*cdf0e10cSrcweir 	aEntry.nExtraLen = rInEntry.nExtraLen;
129*cdf0e10cSrcweir 
130*cdf0e10cSrcweir 	if ( aEntry.nMethod == STORED )
131*cdf0e10cSrcweir 		bToBeCompressed = sal_False;
132*cdf0e10cSrcweir }
133*cdf0e10cSrcweir 
134*cdf0e10cSrcweir //--------------------------------------------------------------------------
135*cdf0e10cSrcweir void ZipPackageStream::CloseOwnStreamIfAny()
136*cdf0e10cSrcweir {
137*cdf0e10cSrcweir 	if ( xStream.is() )
138*cdf0e10cSrcweir 	{
139*cdf0e10cSrcweir 		xStream->closeInput();
140*cdf0e10cSrcweir 		xStream = uno::Reference< io::XInputStream >();
141*cdf0e10cSrcweir 		m_bHasSeekable = sal_False;
142*cdf0e10cSrcweir 	}
143*cdf0e10cSrcweir }
144*cdf0e10cSrcweir 
145*cdf0e10cSrcweir //--------------------------------------------------------------------------
146*cdf0e10cSrcweir uno::Reference< io::XInputStream > ZipPackageStream::GetOwnSeekStream()
147*cdf0e10cSrcweir {
148*cdf0e10cSrcweir 	if ( !m_bHasSeekable && xStream.is() )
149*cdf0e10cSrcweir 	{
150*cdf0e10cSrcweir 		// The package component requires that every stream either be FROM a package or it must support XSeekable!
151*cdf0e10cSrcweir 		// The only exception is a nonseekable stream that is provided only for storing, if such a stream
152*cdf0e10cSrcweir 		// is accessed before commit it MUST be wrapped.
153*cdf0e10cSrcweir 		// Wrap the stream in case it is not seekable
154*cdf0e10cSrcweir 		xStream = ::comphelper::OSeekableInputWrapper::CheckSeekableCanWrap( xStream, m_xFactory );
155*cdf0e10cSrcweir 		uno::Reference< io::XSeekable > xSeek( xStream, UNO_QUERY );
156*cdf0e10cSrcweir 		if ( !xSeek.is() )
157*cdf0e10cSrcweir 			throw RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "The stream must support XSeekable!" ) ),
158*cdf0e10cSrcweir 									uno::Reference< XInterface >() );
159*cdf0e10cSrcweir 
160*cdf0e10cSrcweir 		m_bHasSeekable = sal_True;
161*cdf0e10cSrcweir 	}
162*cdf0e10cSrcweir 
163*cdf0e10cSrcweir 	return xStream;
164*cdf0e10cSrcweir }
165*cdf0e10cSrcweir 
166*cdf0e10cSrcweir //--------------------------------------------------------------------------
167*cdf0e10cSrcweir uno::Reference< io::XInputStream > ZipPackageStream::GetRawEncrStreamNoHeaderCopy()
168*cdf0e10cSrcweir {
169*cdf0e10cSrcweir 	if ( m_nStreamMode != PACKAGE_STREAM_RAW || !GetOwnSeekStream().is() )
170*cdf0e10cSrcweir 		throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
171*cdf0e10cSrcweir 
172*cdf0e10cSrcweir 	if ( m_xBaseEncryptionData.is() )
173*cdf0e10cSrcweir 		throw ZipIOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Encrypted stream without encryption data!\n" ) ),
174*cdf0e10cSrcweir 							uno::Reference< XInterface >() );
175*cdf0e10cSrcweir 
176*cdf0e10cSrcweir 	uno::Reference< io::XSeekable > xSeek( GetOwnSeekStream(), UNO_QUERY );
177*cdf0e10cSrcweir 	if ( !xSeek.is() )
178*cdf0e10cSrcweir 		throw ZipIOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "The stream must be seekable!\n" ) ),
179*cdf0e10cSrcweir 							uno::Reference< XInterface >() );
180*cdf0e10cSrcweir 
181*cdf0e10cSrcweir 	// skip header
182*cdf0e10cSrcweir 	xSeek->seek( n_ConstHeaderSize + getInitialisationVector().getLength() +
183*cdf0e10cSrcweir 					getSalt().getLength() + getDigest().getLength() );
184*cdf0e10cSrcweir 
185*cdf0e10cSrcweir 	// create temporary stream
186*cdf0e10cSrcweir 	uno::Reference < io::XOutputStream > xTempOut(
187*cdf0e10cSrcweir 						m_xFactory->createInstance( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.io.TempFile" ) ) ),
188*cdf0e10cSrcweir 						uno::UNO_QUERY );
189*cdf0e10cSrcweir 	uno::Reference < io::XInputStream > xTempIn( xTempOut, UNO_QUERY );
190*cdf0e10cSrcweir 	uno::Reference < io::XSeekable > xTempSeek( xTempOut, UNO_QUERY );
191*cdf0e10cSrcweir 	if ( !xTempOut.is() || !xTempIn.is() || !xTempSeek.is() )
192*cdf0e10cSrcweir 		throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
193*cdf0e10cSrcweir 
194*cdf0e10cSrcweir 	// copy the raw stream to the temporary file starting from the current position
195*cdf0e10cSrcweir 	::comphelper::OStorageHelper::CopyInputToOutput( GetOwnSeekStream(), xTempOut );
196*cdf0e10cSrcweir 	xTempOut->closeOutput();
197*cdf0e10cSrcweir 	xTempSeek->seek( 0 );
198*cdf0e10cSrcweir 
199*cdf0e10cSrcweir 	return xTempIn;
200*cdf0e10cSrcweir }
201*cdf0e10cSrcweir 
202*cdf0e10cSrcweir //--------------------------------------------------------------------------
203*cdf0e10cSrcweir sal_Int32 ZipPackageStream::GetEncryptionAlgorithm() const
204*cdf0e10cSrcweir {
205*cdf0e10cSrcweir     return m_nImportedEncryptionAlgorithm ? m_nImportedEncryptionAlgorithm : rZipPackage.GetEncAlgID();
206*cdf0e10cSrcweir }
207*cdf0e10cSrcweir 
208*cdf0e10cSrcweir //--------------------------------------------------------------------------
209*cdf0e10cSrcweir sal_Int32 ZipPackageStream::GetBlockSize() const
210*cdf0e10cSrcweir {
211*cdf0e10cSrcweir     return GetEncryptionAlgorithm() == ::com::sun::star::xml::crypto::CipherID::AES_CBC_W3C_PADDING ? 16 : 8;
212*cdf0e10cSrcweir }
213*cdf0e10cSrcweir 
214*cdf0e10cSrcweir //--------------------------------------------------------------------------
215*cdf0e10cSrcweir ::rtl::Reference< EncryptionData > ZipPackageStream::GetEncryptionData( bool bUseWinEncoding )
216*cdf0e10cSrcweir {
217*cdf0e10cSrcweir     ::rtl::Reference< EncryptionData > xResult;
218*cdf0e10cSrcweir     if ( m_xBaseEncryptionData.is() )
219*cdf0e10cSrcweir         xResult = new EncryptionData(
220*cdf0e10cSrcweir             *m_xBaseEncryptionData,
221*cdf0e10cSrcweir             GetEncryptionKey( bUseWinEncoding ),
222*cdf0e10cSrcweir             GetEncryptionAlgorithm(),
223*cdf0e10cSrcweir             m_nImportedChecksumAlgorithm ? m_nImportedChecksumAlgorithm : rZipPackage.GetChecksumAlgID(),
224*cdf0e10cSrcweir             m_nImportedDerivedKeySize ? m_nImportedDerivedKeySize : rZipPackage.GetDefaultDerivedKeySize(),
225*cdf0e10cSrcweir             GetStartKeyGenID() );
226*cdf0e10cSrcweir 
227*cdf0e10cSrcweir     return xResult;
228*cdf0e10cSrcweir }
229*cdf0e10cSrcweir 
230*cdf0e10cSrcweir //--------------------------------------------------------------------------
231*cdf0e10cSrcweir void ZipPackageStream::SetBaseEncryptionData( const ::rtl::Reference< BaseEncryptionData >& xData )
232*cdf0e10cSrcweir {
233*cdf0e10cSrcweir     m_xBaseEncryptionData = xData;
234*cdf0e10cSrcweir }
235*cdf0e10cSrcweir 
236*cdf0e10cSrcweir //--------------------------------------------------------------------------
237*cdf0e10cSrcweir uno::Sequence< sal_Int8 > ZipPackageStream::GetEncryptionKey( bool bUseWinEncoding )
238*cdf0e10cSrcweir {
239*cdf0e10cSrcweir     uno::Sequence< sal_Int8 > aResult;
240*cdf0e10cSrcweir     sal_Int32 nKeyGenID = GetStartKeyGenID();
241*cdf0e10cSrcweir     bUseWinEncoding = ( bUseWinEncoding || m_bUseWinEncoding );
242*cdf0e10cSrcweir 
243*cdf0e10cSrcweir     if ( bHaveOwnKey && m_aStorageEncryptionKeys.getLength() )
244*cdf0e10cSrcweir     {
245*cdf0e10cSrcweir         ::rtl::OUString aNameToFind;
246*cdf0e10cSrcweir         if ( nKeyGenID == xml::crypto::DigestID::SHA256 )
247*cdf0e10cSrcweir             aNameToFind = PACKAGE_ENCRYPTIONDATA_SHA256UTF8;
248*cdf0e10cSrcweir         else if ( nKeyGenID == xml::crypto::DigestID::SHA1 )
249*cdf0e10cSrcweir         {
250*cdf0e10cSrcweir             aNameToFind = bUseWinEncoding ? PACKAGE_ENCRYPTIONDATA_SHA1MS1252 : PACKAGE_ENCRYPTIONDATA_SHA1UTF8;
251*cdf0e10cSrcweir         }
252*cdf0e10cSrcweir         else
253*cdf0e10cSrcweir             throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "No expected key is provided!" ) ), uno::Reference< uno::XInterface >() );
254*cdf0e10cSrcweir 
255*cdf0e10cSrcweir         for ( sal_Int32 nInd = 0; nInd < m_aStorageEncryptionKeys.getLength(); nInd++ )
256*cdf0e10cSrcweir             if ( m_aStorageEncryptionKeys[nInd].Name.equals( aNameToFind ) )
257*cdf0e10cSrcweir                 m_aStorageEncryptionKeys[nInd].Value >>= aResult;
258*cdf0e10cSrcweir 
259*cdf0e10cSrcweir         // empty keys are not allowed here
260*cdf0e10cSrcweir         // so it is not important whether there is no key, or the key is empty, it is an error
261*cdf0e10cSrcweir         if ( !aResult.getLength() )
262*cdf0e10cSrcweir             throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "No expected key is provided!" ) ), uno::Reference< uno::XInterface >() );
263*cdf0e10cSrcweir     }
264*cdf0e10cSrcweir     else
265*cdf0e10cSrcweir         aResult = m_aEncryptionKey;
266*cdf0e10cSrcweir 
267*cdf0e10cSrcweir     if ( !aResult.getLength() || !bHaveOwnKey )
268*cdf0e10cSrcweir         aResult = rZipPackage.GetEncryptionKey();
269*cdf0e10cSrcweir 
270*cdf0e10cSrcweir     return aResult;
271*cdf0e10cSrcweir }
272*cdf0e10cSrcweir 
273*cdf0e10cSrcweir //--------------------------------------------------------------------------
274*cdf0e10cSrcweir sal_Int32 ZipPackageStream::GetStartKeyGenID()
275*cdf0e10cSrcweir {
276*cdf0e10cSrcweir     // generally should all the streams use the same Start Key
277*cdf0e10cSrcweir     // but if raw copy without password takes place, we should preserve the imported algorithm
278*cdf0e10cSrcweir     return m_nImportedStartKeyAlgorithm ? m_nImportedStartKeyAlgorithm : rZipPackage.GetStartKeyGenID();
279*cdf0e10cSrcweir }
280*cdf0e10cSrcweir 
281*cdf0e10cSrcweir //--------------------------------------------------------------------------
282*cdf0e10cSrcweir uno::Reference< io::XInputStream > ZipPackageStream::TryToGetRawFromDataStream( sal_Bool bAddHeaderForEncr )
283*cdf0e10cSrcweir {
284*cdf0e10cSrcweir 	if ( m_nStreamMode != PACKAGE_STREAM_DATA || !GetOwnSeekStream().is() || ( bAddHeaderForEncr && !bToBeEncrypted ) )
285*cdf0e10cSrcweir 		throw packages::NoEncryptionException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
286*cdf0e10cSrcweir 
287*cdf0e10cSrcweir 	Sequence< sal_Int8 > aKey;
288*cdf0e10cSrcweir 
289*cdf0e10cSrcweir 	if ( bToBeEncrypted )
290*cdf0e10cSrcweir 	{
291*cdf0e10cSrcweir 		aKey = GetEncryptionKey();
292*cdf0e10cSrcweir 		if ( !aKey.getLength() )
293*cdf0e10cSrcweir 			throw packages::NoEncryptionException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
294*cdf0e10cSrcweir 	}
295*cdf0e10cSrcweir 
296*cdf0e10cSrcweir 	try
297*cdf0e10cSrcweir 	{
298*cdf0e10cSrcweir 		// create temporary file
299*cdf0e10cSrcweir 		uno::Reference < io::XStream > xTempStream(
300*cdf0e10cSrcweir 							m_xFactory->createInstance ( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.io.TempFile" ) ) ),
301*cdf0e10cSrcweir 							uno::UNO_QUERY );
302*cdf0e10cSrcweir 		if ( !xTempStream.is() )
303*cdf0e10cSrcweir 			throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
304*cdf0e10cSrcweir 
305*cdf0e10cSrcweir 		// create a package based on it
306*cdf0e10cSrcweir 		ZipPackage* pPackage = new ZipPackage( m_xFactory );
307*cdf0e10cSrcweir 		uno::Reference< XSingleServiceFactory > xPackageAsFactory( static_cast< XSingleServiceFactory* >( pPackage ) );
308*cdf0e10cSrcweir 		if ( !xPackageAsFactory.is() )
309*cdf0e10cSrcweir 			throw RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
310*cdf0e10cSrcweir 
311*cdf0e10cSrcweir 		Sequence< Any > aArgs( 1 );
312*cdf0e10cSrcweir 		aArgs[0] <<= xTempStream;
313*cdf0e10cSrcweir 		pPackage->initialize( aArgs );
314*cdf0e10cSrcweir 
315*cdf0e10cSrcweir 		// create a new package stream
316*cdf0e10cSrcweir 		uno::Reference< XDataSinkEncrSupport > xNewPackStream( xPackageAsFactory->createInstance(), UNO_QUERY );
317*cdf0e10cSrcweir 		if ( !xNewPackStream.is() )
318*cdf0e10cSrcweir 			throw RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
319*cdf0e10cSrcweir 
320*cdf0e10cSrcweir 		xNewPackStream->setDataStream( static_cast< io::XInputStream* >(
321*cdf0e10cSrcweir 													new WrapStreamForShare( GetOwnSeekStream(), rZipPackage.GetSharedMutexRef() ) ) );
322*cdf0e10cSrcweir 
323*cdf0e10cSrcweir 		uno::Reference< XPropertySet > xNewPSProps( xNewPackStream, UNO_QUERY );
324*cdf0e10cSrcweir 		if ( !xNewPSProps.is() )
325*cdf0e10cSrcweir 			throw RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
326*cdf0e10cSrcweir 
327*cdf0e10cSrcweir 		// copy all the properties of this stream to the new stream
328*cdf0e10cSrcweir 		xNewPSProps->setPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "MediaType" ) ), makeAny( sMediaType ) );
329*cdf0e10cSrcweir 		xNewPSProps->setPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Compressed" ) ), makeAny( bToBeCompressed ) );
330*cdf0e10cSrcweir 		if ( bToBeEncrypted )
331*cdf0e10cSrcweir 		{
332*cdf0e10cSrcweir 			xNewPSProps->setPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ENCRYPTION_KEY_PROPERTY ) ), makeAny( aKey ) );
333*cdf0e10cSrcweir 			xNewPSProps->setPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Encrypted" ) ), makeAny( sal_True ) );
334*cdf0e10cSrcweir 		}
335*cdf0e10cSrcweir 
336*cdf0e10cSrcweir 		// insert a new stream in the package
337*cdf0e10cSrcweir 		uno::Reference< XUnoTunnel > xTunnel;
338*cdf0e10cSrcweir 		Any aRoot = pPackage->getByHierarchicalName( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "/" ) ) );
339*cdf0e10cSrcweir 		aRoot >>= xTunnel;
340*cdf0e10cSrcweir 		uno::Reference< container::XNameContainer > xRootNameContainer( xTunnel, UNO_QUERY );
341*cdf0e10cSrcweir 		if ( !xRootNameContainer.is() )
342*cdf0e10cSrcweir 			throw RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
343*cdf0e10cSrcweir 
344*cdf0e10cSrcweir 		uno::Reference< XUnoTunnel > xNPSTunnel( xNewPackStream, UNO_QUERY );
345*cdf0e10cSrcweir 		xRootNameContainer->insertByName( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "dummy" ) ), makeAny( xNPSTunnel ) );
346*cdf0e10cSrcweir 
347*cdf0e10cSrcweir 		// commit the temporary package
348*cdf0e10cSrcweir 		pPackage->commitChanges();
349*cdf0e10cSrcweir 
350*cdf0e10cSrcweir 		// get raw stream from the temporary package
351*cdf0e10cSrcweir 		uno::Reference< io::XInputStream > xInRaw;
352*cdf0e10cSrcweir 		if ( bAddHeaderForEncr )
353*cdf0e10cSrcweir 			xInRaw = xNewPackStream->getRawStream();
354*cdf0e10cSrcweir 		else
355*cdf0e10cSrcweir 			xInRaw = xNewPackStream->getPlainRawStream();
356*cdf0e10cSrcweir 
357*cdf0e10cSrcweir 		// create another temporary file
358*cdf0e10cSrcweir 		uno::Reference < io::XOutputStream > xTempOut(
359*cdf0e10cSrcweir 							m_xFactory->createInstance ( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.io.TempFile" ) ) ),
360*cdf0e10cSrcweir 							uno::UNO_QUERY );
361*cdf0e10cSrcweir 		uno::Reference < io::XInputStream > xTempIn( xTempOut, UNO_QUERY );
362*cdf0e10cSrcweir 		uno::Reference < io::XSeekable > xTempSeek( xTempOut, UNO_QUERY );
363*cdf0e10cSrcweir 		if ( !xTempOut.is() || !xTempIn.is() || !xTempSeek.is() )
364*cdf0e10cSrcweir 			throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
365*cdf0e10cSrcweir 
366*cdf0e10cSrcweir 		// copy the raw stream to the temporary file
367*cdf0e10cSrcweir 		::comphelper::OStorageHelper::CopyInputToOutput( xInRaw, xTempOut );
368*cdf0e10cSrcweir 		xTempOut->closeOutput();
369*cdf0e10cSrcweir 		xTempSeek->seek( 0 );
370*cdf0e10cSrcweir 
371*cdf0e10cSrcweir 		// close raw stream, package stream and folder
372*cdf0e10cSrcweir 		xInRaw = uno::Reference< io::XInputStream >();
373*cdf0e10cSrcweir 		xNewPSProps = uno::Reference< XPropertySet >();
374*cdf0e10cSrcweir 		xNPSTunnel = uno::Reference< XUnoTunnel >();
375*cdf0e10cSrcweir 		xNewPackStream = uno::Reference< XDataSinkEncrSupport >();
376*cdf0e10cSrcweir 		xTunnel = uno::Reference< XUnoTunnel >();
377*cdf0e10cSrcweir 		xRootNameContainer = uno::Reference< container::XNameContainer >();
378*cdf0e10cSrcweir 
379*cdf0e10cSrcweir 		// return the stream representing the first temporary file
380*cdf0e10cSrcweir 		return xTempIn;
381*cdf0e10cSrcweir 	}
382*cdf0e10cSrcweir 	catch ( RuntimeException& )
383*cdf0e10cSrcweir 	{
384*cdf0e10cSrcweir 		throw;
385*cdf0e10cSrcweir 	}
386*cdf0e10cSrcweir 	catch ( Exception& )
387*cdf0e10cSrcweir 	{
388*cdf0e10cSrcweir 	}
389*cdf0e10cSrcweir 
390*cdf0e10cSrcweir 	throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
391*cdf0e10cSrcweir }
392*cdf0e10cSrcweir 
393*cdf0e10cSrcweir //--------------------------------------------------------------------------
394*cdf0e10cSrcweir sal_Bool ZipPackageStream::ParsePackageRawStream()
395*cdf0e10cSrcweir {
396*cdf0e10cSrcweir 	OSL_ENSURE( GetOwnSeekStream().is(), "A stream must be provided!\n" );
397*cdf0e10cSrcweir 
398*cdf0e10cSrcweir 	if ( !GetOwnSeekStream().is() )
399*cdf0e10cSrcweir 		return sal_False;
400*cdf0e10cSrcweir 
401*cdf0e10cSrcweir 	sal_Bool bOk = sal_False;
402*cdf0e10cSrcweir 
403*cdf0e10cSrcweir 	::rtl::Reference< BaseEncryptionData > xTempEncrData;
404*cdf0e10cSrcweir 	sal_Int32 nMagHackSize = 0;
405*cdf0e10cSrcweir 	Sequence < sal_Int8 > aHeader ( 4 );
406*cdf0e10cSrcweir 
407*cdf0e10cSrcweir 	try
408*cdf0e10cSrcweir 	{
409*cdf0e10cSrcweir 		if ( GetOwnSeekStream()->readBytes ( aHeader, 4 ) == 4 )
410*cdf0e10cSrcweir 		{
411*cdf0e10cSrcweir 			const sal_Int8 *pHeader = aHeader.getConstArray();
412*cdf0e10cSrcweir 			sal_uInt32 nHeader = ( pHeader [0] & 0xFF )       |
413*cdf0e10cSrcweir 							 	( pHeader [1] & 0xFF ) << 8  |
414*cdf0e10cSrcweir 							 	( pHeader [2] & 0xFF ) << 16 |
415*cdf0e10cSrcweir 							 	( pHeader [3] & 0xFF ) << 24;
416*cdf0e10cSrcweir 			if ( nHeader == n_ConstHeader )
417*cdf0e10cSrcweir 			{
418*cdf0e10cSrcweir 				// this is one of our god-awful, but extremely devious hacks, everyone cheer
419*cdf0e10cSrcweir 				xTempEncrData = new BaseEncryptionData;
420*cdf0e10cSrcweir 
421*cdf0e10cSrcweir 				::rtl::OUString aMediaType;
422*cdf0e10cSrcweir                 sal_Int32 nEncAlgorithm = 0;
423*cdf0e10cSrcweir                 sal_Int32 nChecksumAlgorithm = 0;
424*cdf0e10cSrcweir                 sal_Int32 nDerivedKeySize = 0;
425*cdf0e10cSrcweir                 sal_Int32 nStartKeyGenID = 0;
426*cdf0e10cSrcweir 				if ( ZipFile::StaticFillData( xTempEncrData, nEncAlgorithm, nChecksumAlgorithm, nDerivedKeySize, nStartKeyGenID, nMagHackSize, aMediaType, GetOwnSeekStream() ) )
427*cdf0e10cSrcweir 				{
428*cdf0e10cSrcweir 					// We'll want to skip the data we've just read, so calculate how much we just read
429*cdf0e10cSrcweir 					// and remember it
430*cdf0e10cSrcweir 					m_nMagicalHackPos = n_ConstHeaderSize + xTempEncrData->m_aSalt.getLength()
431*cdf0e10cSrcweir 														+ xTempEncrData->m_aInitVector.getLength()
432*cdf0e10cSrcweir 														+ xTempEncrData->m_aDigest.getLength()
433*cdf0e10cSrcweir 														+ aMediaType.getLength() * sizeof( sal_Unicode );
434*cdf0e10cSrcweir                     m_nImportedEncryptionAlgorithm = nEncAlgorithm;
435*cdf0e10cSrcweir                     m_nImportedChecksumAlgorithm = nChecksumAlgorithm;
436*cdf0e10cSrcweir                     m_nImportedDerivedKeySize = nDerivedKeySize;
437*cdf0e10cSrcweir                     m_nImportedStartKeyAlgorithm = nStartKeyGenID;
438*cdf0e10cSrcweir 					m_nMagicalHackSize = nMagHackSize;
439*cdf0e10cSrcweir 					sMediaType = aMediaType;
440*cdf0e10cSrcweir 
441*cdf0e10cSrcweir 					bOk = sal_True;
442*cdf0e10cSrcweir 				}
443*cdf0e10cSrcweir 			}
444*cdf0e10cSrcweir 		}
445*cdf0e10cSrcweir 	}
446*cdf0e10cSrcweir 	catch( Exception& )
447*cdf0e10cSrcweir 	{
448*cdf0e10cSrcweir 	}
449*cdf0e10cSrcweir 
450*cdf0e10cSrcweir 	if ( !bOk )
451*cdf0e10cSrcweir 	{
452*cdf0e10cSrcweir 		// the provided stream is not a raw stream
453*cdf0e10cSrcweir 		return sal_False;
454*cdf0e10cSrcweir 	}
455*cdf0e10cSrcweir 
456*cdf0e10cSrcweir 	m_xBaseEncryptionData = xTempEncrData;
457*cdf0e10cSrcweir 	SetIsEncrypted ( sal_True );
458*cdf0e10cSrcweir 	// it's already compressed and encrypted
459*cdf0e10cSrcweir 	bToBeEncrypted = bToBeCompressed = sal_False;
460*cdf0e10cSrcweir 
461*cdf0e10cSrcweir 	return sal_True;
462*cdf0e10cSrcweir }
463*cdf0e10cSrcweir 
464*cdf0e10cSrcweir void ZipPackageStream::SetPackageMember( sal_Bool bNewValue )
465*cdf0e10cSrcweir {
466*cdf0e10cSrcweir 	if ( bNewValue )
467*cdf0e10cSrcweir 	{
468*cdf0e10cSrcweir 		m_nStreamMode = PACKAGE_STREAM_PACKAGEMEMBER;
469*cdf0e10cSrcweir 		m_nMagicalHackPos = 0;
470*cdf0e10cSrcweir 		m_nMagicalHackSize = 0;
471*cdf0e10cSrcweir 	}
472*cdf0e10cSrcweir 	else if ( m_nStreamMode == PACKAGE_STREAM_PACKAGEMEMBER )
473*cdf0e10cSrcweir 		m_nStreamMode = PACKAGE_STREAM_NOTSET; // must be reset
474*cdf0e10cSrcweir }
475*cdf0e10cSrcweir 
476*cdf0e10cSrcweir // XActiveDataSink
477*cdf0e10cSrcweir //--------------------------------------------------------------------------
478*cdf0e10cSrcweir void SAL_CALL ZipPackageStream::setInputStream( const uno::Reference< io::XInputStream >& aStream )
479*cdf0e10cSrcweir 		throw( RuntimeException )
480*cdf0e10cSrcweir {
481*cdf0e10cSrcweir 	// if seekable access is required the wrapping will be done on demand
482*cdf0e10cSrcweir 	xStream = aStream;
483*cdf0e10cSrcweir     m_nImportedEncryptionAlgorithm = 0;
484*cdf0e10cSrcweir 	m_bHasSeekable = sal_False;
485*cdf0e10cSrcweir 	SetPackageMember ( sal_False );
486*cdf0e10cSrcweir 	aEntry.nTime = -1;
487*cdf0e10cSrcweir 	m_nStreamMode = PACKAGE_STREAM_DETECT;
488*cdf0e10cSrcweir }
489*cdf0e10cSrcweir 
490*cdf0e10cSrcweir //--------------------------------------------------------------------------
491*cdf0e10cSrcweir uno::Reference< io::XInputStream > SAL_CALL ZipPackageStream::getRawData()
492*cdf0e10cSrcweir 		throw( RuntimeException )
493*cdf0e10cSrcweir {
494*cdf0e10cSrcweir 	try
495*cdf0e10cSrcweir 	{
496*cdf0e10cSrcweir 		if ( IsPackageMember() )
497*cdf0e10cSrcweir 		{
498*cdf0e10cSrcweir 			return rZipPackage.getZipFile().getRawData( aEntry, GetEncryptionData(), bIsEncrypted, rZipPackage.GetSharedMutexRef() );
499*cdf0e10cSrcweir 		}
500*cdf0e10cSrcweir 		else if ( GetOwnSeekStream().is() )
501*cdf0e10cSrcweir 		{
502*cdf0e10cSrcweir 			return new WrapStreamForShare( GetOwnSeekStream(), rZipPackage.GetSharedMutexRef() );
503*cdf0e10cSrcweir 		}
504*cdf0e10cSrcweir 		else
505*cdf0e10cSrcweir 			return uno::Reference < io::XInputStream > ();
506*cdf0e10cSrcweir 	}
507*cdf0e10cSrcweir 	catch ( ZipException & )//rException )
508*cdf0e10cSrcweir 	{
509*cdf0e10cSrcweir 		VOS_ENSURE( 0, "ZipException thrown" );//rException.Message );
510*cdf0e10cSrcweir 		return uno::Reference < io::XInputStream > ();
511*cdf0e10cSrcweir 	}
512*cdf0e10cSrcweir 	catch ( Exception & )
513*cdf0e10cSrcweir 	{
514*cdf0e10cSrcweir 		VOS_ENSURE( 0, "Exception is thrown during stream wrapping!\n" );
515*cdf0e10cSrcweir 		return uno::Reference < io::XInputStream > ();
516*cdf0e10cSrcweir 	}
517*cdf0e10cSrcweir }
518*cdf0e10cSrcweir 
519*cdf0e10cSrcweir //--------------------------------------------------------------------------
520*cdf0e10cSrcweir uno::Reference< io::XInputStream > SAL_CALL ZipPackageStream::getInputStream()
521*cdf0e10cSrcweir 		throw( RuntimeException )
522*cdf0e10cSrcweir {
523*cdf0e10cSrcweir 	try
524*cdf0e10cSrcweir 	{
525*cdf0e10cSrcweir 		if ( IsPackageMember() )
526*cdf0e10cSrcweir 		{
527*cdf0e10cSrcweir 			return rZipPackage.getZipFile().getInputStream( aEntry, GetEncryptionData(), bIsEncrypted, rZipPackage.GetSharedMutexRef() );
528*cdf0e10cSrcweir 		}
529*cdf0e10cSrcweir 		else if ( GetOwnSeekStream().is() )
530*cdf0e10cSrcweir 		{
531*cdf0e10cSrcweir 			return new WrapStreamForShare( GetOwnSeekStream(), rZipPackage.GetSharedMutexRef() );
532*cdf0e10cSrcweir 		}
533*cdf0e10cSrcweir 		else
534*cdf0e10cSrcweir 			return uno::Reference < io::XInputStream > ();
535*cdf0e10cSrcweir 	}
536*cdf0e10cSrcweir 	catch ( ZipException & )//rException )
537*cdf0e10cSrcweir 	{
538*cdf0e10cSrcweir 		VOS_ENSURE( 0,"ZipException thrown" );//rException.Message );
539*cdf0e10cSrcweir 		return uno::Reference < io::XInputStream > ();
540*cdf0e10cSrcweir 	}
541*cdf0e10cSrcweir 	catch ( Exception & )
542*cdf0e10cSrcweir 	{
543*cdf0e10cSrcweir 		VOS_ENSURE( 0, "Exception is thrown during stream wrapping!\n" );
544*cdf0e10cSrcweir 		return uno::Reference < io::XInputStream > ();
545*cdf0e10cSrcweir 	}
546*cdf0e10cSrcweir }
547*cdf0e10cSrcweir 
548*cdf0e10cSrcweir // XDataSinkEncrSupport
549*cdf0e10cSrcweir //--------------------------------------------------------------------------
550*cdf0e10cSrcweir uno::Reference< io::XInputStream > SAL_CALL ZipPackageStream::getDataStream()
551*cdf0e10cSrcweir 		throw ( packages::WrongPasswordException,
552*cdf0e10cSrcweir 				io::IOException,
553*cdf0e10cSrcweir 				RuntimeException )
554*cdf0e10cSrcweir {
555*cdf0e10cSrcweir 	// There is no stream attached to this object
556*cdf0e10cSrcweir 	if ( m_nStreamMode == PACKAGE_STREAM_NOTSET )
557*cdf0e10cSrcweir 		return uno::Reference< io::XInputStream >();
558*cdf0e10cSrcweir 
559*cdf0e10cSrcweir 	// this method can not be used together with old approach
560*cdf0e10cSrcweir 	if ( m_nStreamMode == PACKAGE_STREAM_DETECT )
561*cdf0e10cSrcweir 		throw packages::zip::ZipIOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
562*cdf0e10cSrcweir 
563*cdf0e10cSrcweir 	if ( IsPackageMember() )
564*cdf0e10cSrcweir 	{
565*cdf0e10cSrcweir         uno::Reference< io::XInputStream > xResult;
566*cdf0e10cSrcweir         try
567*cdf0e10cSrcweir         {
568*cdf0e10cSrcweir 		    xResult = rZipPackage.getZipFile().getDataStream( aEntry, GetEncryptionData(), bIsEncrypted, rZipPackage.GetSharedMutexRef() );
569*cdf0e10cSrcweir         }
570*cdf0e10cSrcweir         catch( packages::WrongPasswordException& )
571*cdf0e10cSrcweir         {
572*cdf0e10cSrcweir             // workaround for the encrypted documents generated with the old OOo1.x bug.
573*cdf0e10cSrcweir             if ( rZipPackage.GetStartKeyGenID() == xml::crypto::DigestID::SHA1 && !m_bUseWinEncoding )
574*cdf0e10cSrcweir             {
575*cdf0e10cSrcweir                 xResult = rZipPackage.getZipFile().getDataStream( aEntry, GetEncryptionData( true ), bIsEncrypted, rZipPackage.GetSharedMutexRef() );
576*cdf0e10cSrcweir                 m_bUseWinEncoding = true;
577*cdf0e10cSrcweir             }
578*cdf0e10cSrcweir             else
579*cdf0e10cSrcweir                 throw;
580*cdf0e10cSrcweir         }
581*cdf0e10cSrcweir         return xResult;
582*cdf0e10cSrcweir 	}
583*cdf0e10cSrcweir 	else if ( m_nStreamMode == PACKAGE_STREAM_RAW )
584*cdf0e10cSrcweir 		return ZipFile::StaticGetDataFromRawStream( m_xFactory, GetOwnSeekStream(), GetEncryptionData() );
585*cdf0e10cSrcweir 	else if ( GetOwnSeekStream().is() )
586*cdf0e10cSrcweir 	{
587*cdf0e10cSrcweir 		return new WrapStreamForShare( GetOwnSeekStream(), rZipPackage.GetSharedMutexRef() );
588*cdf0e10cSrcweir 	}
589*cdf0e10cSrcweir 	else
590*cdf0e10cSrcweir 		return uno::Reference< io::XInputStream >();
591*cdf0e10cSrcweir }
592*cdf0e10cSrcweir 
593*cdf0e10cSrcweir //--------------------------------------------------------------------------
594*cdf0e10cSrcweir uno::Reference< io::XInputStream > SAL_CALL ZipPackageStream::getRawStream()
595*cdf0e10cSrcweir 		throw ( packages::NoEncryptionException,
596*cdf0e10cSrcweir 				io::IOException,
597*cdf0e10cSrcweir 				uno::RuntimeException )
598*cdf0e10cSrcweir {
599*cdf0e10cSrcweir 	// There is no stream attached to this object
600*cdf0e10cSrcweir 	if ( m_nStreamMode == PACKAGE_STREAM_NOTSET )
601*cdf0e10cSrcweir 		return uno::Reference< io::XInputStream >();
602*cdf0e10cSrcweir 
603*cdf0e10cSrcweir 	// this method can not be used together with old approach
604*cdf0e10cSrcweir 	if ( m_nStreamMode == PACKAGE_STREAM_DETECT )
605*cdf0e10cSrcweir 		throw packages::zip::ZipIOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
606*cdf0e10cSrcweir 
607*cdf0e10cSrcweir 	if ( IsPackageMember() )
608*cdf0e10cSrcweir 	{
609*cdf0e10cSrcweir 		if ( !bIsEncrypted || !GetEncryptionData().is() )
610*cdf0e10cSrcweir 			throw packages::NoEncryptionException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
611*cdf0e10cSrcweir 
612*cdf0e10cSrcweir 		return rZipPackage.getZipFile().getWrappedRawStream( aEntry, GetEncryptionData(), sMediaType, rZipPackage.GetSharedMutexRef() );
613*cdf0e10cSrcweir 	}
614*cdf0e10cSrcweir 	else if ( GetOwnSeekStream().is() )
615*cdf0e10cSrcweir 	{
616*cdf0e10cSrcweir 		if ( m_nStreamMode == PACKAGE_STREAM_RAW )
617*cdf0e10cSrcweir 		{
618*cdf0e10cSrcweir 			return new WrapStreamForShare( GetOwnSeekStream(), rZipPackage.GetSharedMutexRef() );
619*cdf0e10cSrcweir 		}
620*cdf0e10cSrcweir 		else if ( m_nStreamMode == PACKAGE_STREAM_DATA && bToBeEncrypted )
621*cdf0e10cSrcweir 			return TryToGetRawFromDataStream( sal_True );
622*cdf0e10cSrcweir 	}
623*cdf0e10cSrcweir 
624*cdf0e10cSrcweir 	throw packages::NoEncryptionException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
625*cdf0e10cSrcweir }
626*cdf0e10cSrcweir 
627*cdf0e10cSrcweir 
628*cdf0e10cSrcweir //--------------------------------------------------------------------------
629*cdf0e10cSrcweir void SAL_CALL ZipPackageStream::setDataStream( const uno::Reference< io::XInputStream >& aStream )
630*cdf0e10cSrcweir 		throw ( io::IOException,
631*cdf0e10cSrcweir 				RuntimeException )
632*cdf0e10cSrcweir {
633*cdf0e10cSrcweir 	setInputStream( aStream );
634*cdf0e10cSrcweir 	m_nStreamMode = PACKAGE_STREAM_DATA;
635*cdf0e10cSrcweir }
636*cdf0e10cSrcweir 
637*cdf0e10cSrcweir //--------------------------------------------------------------------------
638*cdf0e10cSrcweir void SAL_CALL ZipPackageStream::setRawStream( const uno::Reference< io::XInputStream >& aStream )
639*cdf0e10cSrcweir 		throw ( packages::EncryptionNotAllowedException,
640*cdf0e10cSrcweir 				packages::NoRawFormatException,
641*cdf0e10cSrcweir 				io::IOException,
642*cdf0e10cSrcweir 				RuntimeException )
643*cdf0e10cSrcweir {
644*cdf0e10cSrcweir 	// wrap the stream in case it is not seekable
645*cdf0e10cSrcweir 	uno::Reference< io::XInputStream > xNewStream = ::comphelper::OSeekableInputWrapper::CheckSeekableCanWrap( aStream, m_xFactory );
646*cdf0e10cSrcweir 	uno::Reference< io::XSeekable > xSeek( xNewStream, UNO_QUERY );
647*cdf0e10cSrcweir 	if ( !xSeek.is() )
648*cdf0e10cSrcweir 		throw RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "The stream must support XSeekable!" ) ),
649*cdf0e10cSrcweir 									uno::Reference< XInterface >() );
650*cdf0e10cSrcweir 
651*cdf0e10cSrcweir 	xSeek->seek( 0 );
652*cdf0e10cSrcweir 	uno::Reference< io::XInputStream > xOldStream = xStream;
653*cdf0e10cSrcweir 	xStream = xNewStream;
654*cdf0e10cSrcweir 	if ( !ParsePackageRawStream() )
655*cdf0e10cSrcweir 	{
656*cdf0e10cSrcweir 		xStream = xOldStream;
657*cdf0e10cSrcweir 		throw packages::NoRawFormatException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
658*cdf0e10cSrcweir 	}
659*cdf0e10cSrcweir 
660*cdf0e10cSrcweir 	// the raw stream MUST have seekable access
661*cdf0e10cSrcweir 	m_bHasSeekable = sal_True;
662*cdf0e10cSrcweir 
663*cdf0e10cSrcweir 	SetPackageMember ( sal_False );
664*cdf0e10cSrcweir 	aEntry.nTime = -1;
665*cdf0e10cSrcweir 	m_nStreamMode = PACKAGE_STREAM_RAW;
666*cdf0e10cSrcweir }
667*cdf0e10cSrcweir 
668*cdf0e10cSrcweir //--------------------------------------------------------------------------
669*cdf0e10cSrcweir uno::Reference< io::XInputStream > SAL_CALL ZipPackageStream::getPlainRawStream()
670*cdf0e10cSrcweir 		throw ( io::IOException,
671*cdf0e10cSrcweir 				uno::RuntimeException )
672*cdf0e10cSrcweir {
673*cdf0e10cSrcweir 	// There is no stream attached to this object
674*cdf0e10cSrcweir 	if ( m_nStreamMode == PACKAGE_STREAM_NOTSET )
675*cdf0e10cSrcweir 		return uno::Reference< io::XInputStream >();
676*cdf0e10cSrcweir 
677*cdf0e10cSrcweir 	// this method can not be used together with old approach
678*cdf0e10cSrcweir 	if ( m_nStreamMode == PACKAGE_STREAM_DETECT )
679*cdf0e10cSrcweir 		throw packages::zip::ZipIOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
680*cdf0e10cSrcweir 
681*cdf0e10cSrcweir 	if ( IsPackageMember() )
682*cdf0e10cSrcweir 	{
683*cdf0e10cSrcweir 		return rZipPackage.getZipFile().getRawData( aEntry, GetEncryptionData(), bIsEncrypted, rZipPackage.GetSharedMutexRef() );
684*cdf0e10cSrcweir 	}
685*cdf0e10cSrcweir 	else if ( GetOwnSeekStream().is() )
686*cdf0e10cSrcweir 	{
687*cdf0e10cSrcweir 		if ( m_nStreamMode == PACKAGE_STREAM_RAW )
688*cdf0e10cSrcweir 		{
689*cdf0e10cSrcweir 			// the header should not be returned here
690*cdf0e10cSrcweir 			return GetRawEncrStreamNoHeaderCopy();
691*cdf0e10cSrcweir 		}
692*cdf0e10cSrcweir 		else if ( m_nStreamMode == PACKAGE_STREAM_DATA )
693*cdf0e10cSrcweir 			return TryToGetRawFromDataStream( sal_False );
694*cdf0e10cSrcweir 	}
695*cdf0e10cSrcweir 
696*cdf0e10cSrcweir 	return uno::Reference< io::XInputStream >();
697*cdf0e10cSrcweir }
698*cdf0e10cSrcweir 
699*cdf0e10cSrcweir // XUnoTunnel
700*cdf0e10cSrcweir 
701*cdf0e10cSrcweir //--------------------------------------------------------------------------
702*cdf0e10cSrcweir sal_Int64 SAL_CALL ZipPackageStream::getSomething( const Sequence< sal_Int8 >& aIdentifier )
703*cdf0e10cSrcweir 	throw( RuntimeException )
704*cdf0e10cSrcweir {
705*cdf0e10cSrcweir 	sal_Int64 nMe = 0;
706*cdf0e10cSrcweir 	if ( aIdentifier.getLength() == 16 &&
707*cdf0e10cSrcweir 		 0 == rtl_compareMemory( static_getImplementationId().getConstArray(), aIdentifier.getConstArray(), 16 ) )
708*cdf0e10cSrcweir 		nMe = reinterpret_cast < sal_Int64 > ( this );
709*cdf0e10cSrcweir 	return nMe;
710*cdf0e10cSrcweir }
711*cdf0e10cSrcweir 
712*cdf0e10cSrcweir // XPropertySet
713*cdf0e10cSrcweir //--------------------------------------------------------------------------
714*cdf0e10cSrcweir void SAL_CALL ZipPackageStream::setPropertyValue( const OUString& aPropertyName, const Any& aValue )
715*cdf0e10cSrcweir 		throw( beans::UnknownPropertyException, beans::PropertyVetoException, IllegalArgumentException, WrappedTargetException, RuntimeException )
716*cdf0e10cSrcweir {
717*cdf0e10cSrcweir 	if ( aPropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "MediaType" )) )
718*cdf0e10cSrcweir 	{
719*cdf0e10cSrcweir 		if ( rZipPackage.getFormat() != embed::StorageFormats::PACKAGE && rZipPackage.getFormat() != embed::StorageFormats::OFOPXML )
720*cdf0e10cSrcweir 			throw beans::PropertyVetoException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
721*cdf0e10cSrcweir 
722*cdf0e10cSrcweir 		if ( aValue >>= sMediaType )
723*cdf0e10cSrcweir 		{
724*cdf0e10cSrcweir 			if ( sMediaType.getLength() > 0 )
725*cdf0e10cSrcweir 			{
726*cdf0e10cSrcweir 				if ( sMediaType.indexOf ( OUString( RTL_CONSTASCII_USTRINGPARAM ( "text" ) ) ) != -1
727*cdf0e10cSrcweir 			 	|| sMediaType.equals( OUString( RTL_CONSTASCII_USTRINGPARAM ( "application/vnd.sun.star.oleobject" ) ) ) )
728*cdf0e10cSrcweir 					bToBeCompressed = sal_True;
729*cdf0e10cSrcweir 				else if ( !m_bCompressedIsSetFromOutside )
730*cdf0e10cSrcweir 					bToBeCompressed = sal_False;
731*cdf0e10cSrcweir 			}
732*cdf0e10cSrcweir 		}
733*cdf0e10cSrcweir 		else
734*cdf0e10cSrcweir 			throw IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "MediaType must be a string!\n" ) ),
735*cdf0e10cSrcweir 											uno::Reference< XInterface >(),
736*cdf0e10cSrcweir 											2 );
737*cdf0e10cSrcweir 
738*cdf0e10cSrcweir 	}
739*cdf0e10cSrcweir 	else if ( aPropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "Size" ) ) )
740*cdf0e10cSrcweir 	{
741*cdf0e10cSrcweir 		if ( !( aValue >>= aEntry.nSize ) )
742*cdf0e10cSrcweir 			throw IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Wrong type for Size property!\n" ) ),
743*cdf0e10cSrcweir 											uno::Reference< XInterface >(),
744*cdf0e10cSrcweir 											2 );
745*cdf0e10cSrcweir 	}
746*cdf0e10cSrcweir 	else if ( aPropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "Encrypted" ) ) )
747*cdf0e10cSrcweir 	{
748*cdf0e10cSrcweir 		if ( rZipPackage.getFormat() != embed::StorageFormats::PACKAGE )
749*cdf0e10cSrcweir 			throw beans::PropertyVetoException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
750*cdf0e10cSrcweir 
751*cdf0e10cSrcweir 		sal_Bool bEnc = sal_False;
752*cdf0e10cSrcweir 		if ( aValue >>= bEnc )
753*cdf0e10cSrcweir 		{
754*cdf0e10cSrcweir 			// In case of new raw stream, the stream must not be encrypted on storing
755*cdf0e10cSrcweir 			if ( bEnc && m_nStreamMode == PACKAGE_STREAM_RAW )
756*cdf0e10cSrcweir 				throw IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Raw stream can not be encrypted on storing" ) ),
757*cdf0e10cSrcweir 												uno::Reference< XInterface >(),
758*cdf0e10cSrcweir 												2 );
759*cdf0e10cSrcweir 
760*cdf0e10cSrcweir 			bToBeEncrypted = bEnc;
761*cdf0e10cSrcweir 			if ( bToBeEncrypted && !m_xBaseEncryptionData.is() )
762*cdf0e10cSrcweir 				m_xBaseEncryptionData = new BaseEncryptionData;
763*cdf0e10cSrcweir 		}
764*cdf0e10cSrcweir 		else
765*cdf0e10cSrcweir 			throw IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Wrong type for Encrypted property!\n" ) ),
766*cdf0e10cSrcweir 											uno::Reference< XInterface >(),
767*cdf0e10cSrcweir 											2 );
768*cdf0e10cSrcweir 
769*cdf0e10cSrcweir 	}
770*cdf0e10cSrcweir 	else if ( aPropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( ENCRYPTION_KEY_PROPERTY ) ) )
771*cdf0e10cSrcweir 	{
772*cdf0e10cSrcweir 		if ( rZipPackage.getFormat() != embed::StorageFormats::PACKAGE )
773*cdf0e10cSrcweir 			throw beans::PropertyVetoException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
774*cdf0e10cSrcweir 
775*cdf0e10cSrcweir 		uno::Sequence< sal_Int8 > aNewKey;
776*cdf0e10cSrcweir 
777*cdf0e10cSrcweir 		if ( !( aValue >>= aNewKey ) )
778*cdf0e10cSrcweir 		{
779*cdf0e10cSrcweir 			OUString sTempString;
780*cdf0e10cSrcweir 			if ( ( aValue >>= sTempString ) )
781*cdf0e10cSrcweir 			{
782*cdf0e10cSrcweir 				sal_Int32 nPathLength = sTempString.getLength();
783*cdf0e10cSrcweir 				Sequence < sal_Int8 > aSequence ( nPathLength );
784*cdf0e10cSrcweir 				sal_Int8 *pArray = aSequence.getArray();
785*cdf0e10cSrcweir 				const sal_Unicode *pChar = sTempString.getStr();
786*cdf0e10cSrcweir 				for ( sal_Int16 i = 0; i < nPathLength; i++ )
787*cdf0e10cSrcweir 					pArray[i] = static_cast < const sal_Int8 > ( pChar[i] );
788*cdf0e10cSrcweir 				aNewKey = aSequence;
789*cdf0e10cSrcweir 			}
790*cdf0e10cSrcweir 			else
791*cdf0e10cSrcweir 				throw IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Wrong type for EncryptionKey property!\n" ) ),
792*cdf0e10cSrcweir 												uno::Reference< XInterface >(),
793*cdf0e10cSrcweir 												2 );
794*cdf0e10cSrcweir 		}
795*cdf0e10cSrcweir 
796*cdf0e10cSrcweir 		if ( aNewKey.getLength() )
797*cdf0e10cSrcweir 		{
798*cdf0e10cSrcweir 			if ( !m_xBaseEncryptionData.is() )
799*cdf0e10cSrcweir 				m_xBaseEncryptionData = new BaseEncryptionData;
800*cdf0e10cSrcweir 
801*cdf0e10cSrcweir 			m_aEncryptionKey = aNewKey;
802*cdf0e10cSrcweir 			// In case of new raw stream, the stream must not be encrypted on storing
803*cdf0e10cSrcweir 			bHaveOwnKey = sal_True;
804*cdf0e10cSrcweir 			if ( m_nStreamMode != PACKAGE_STREAM_RAW )
805*cdf0e10cSrcweir 				bToBeEncrypted = sal_True;
806*cdf0e10cSrcweir 		}
807*cdf0e10cSrcweir 		else
808*cdf0e10cSrcweir         {
809*cdf0e10cSrcweir 			bHaveOwnKey = sal_False;
810*cdf0e10cSrcweir             m_aEncryptionKey.realloc( 0 );
811*cdf0e10cSrcweir         }
812*cdf0e10cSrcweir 
813*cdf0e10cSrcweir         m_aStorageEncryptionKeys.realloc( 0 );
814*cdf0e10cSrcweir 	}
815*cdf0e10cSrcweir 	else if ( aPropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( STORAGE_ENCRYPTION_KEYS_PROPERTY ) ) )
816*cdf0e10cSrcweir 	{
817*cdf0e10cSrcweir 		if ( rZipPackage.getFormat() != embed::StorageFormats::PACKAGE )
818*cdf0e10cSrcweir 			throw beans::PropertyVetoException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
819*cdf0e10cSrcweir 
820*cdf0e10cSrcweir 		uno::Sequence< beans::NamedValue > aKeys;
821*cdf0e10cSrcweir 		if ( !( aValue >>= aKeys ) )
822*cdf0e10cSrcweir 		{
823*cdf0e10cSrcweir 				throw IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Wrong type for StorageEncryptionKeys property!\n" ) ),
824*cdf0e10cSrcweir 												uno::Reference< XInterface >(),
825*cdf0e10cSrcweir 												2 );
826*cdf0e10cSrcweir 		}
827*cdf0e10cSrcweir 
828*cdf0e10cSrcweir 		if ( aKeys.getLength() )
829*cdf0e10cSrcweir 		{
830*cdf0e10cSrcweir 			if ( !m_xBaseEncryptionData.is() )
831*cdf0e10cSrcweir 				m_xBaseEncryptionData = new BaseEncryptionData;
832*cdf0e10cSrcweir 
833*cdf0e10cSrcweir 			m_aStorageEncryptionKeys = aKeys;
834*cdf0e10cSrcweir 
835*cdf0e10cSrcweir 			// In case of new raw stream, the stream must not be encrypted on storing
836*cdf0e10cSrcweir 			bHaveOwnKey = sal_True;
837*cdf0e10cSrcweir 			if ( m_nStreamMode != PACKAGE_STREAM_RAW )
838*cdf0e10cSrcweir 				bToBeEncrypted = sal_True;
839*cdf0e10cSrcweir 		}
840*cdf0e10cSrcweir 		else
841*cdf0e10cSrcweir         {
842*cdf0e10cSrcweir 			bHaveOwnKey = sal_False;
843*cdf0e10cSrcweir             m_aStorageEncryptionKeys.realloc( 0 );
844*cdf0e10cSrcweir         }
845*cdf0e10cSrcweir 
846*cdf0e10cSrcweir         m_aEncryptionKey.realloc( 0 );
847*cdf0e10cSrcweir 	}
848*cdf0e10cSrcweir 	else if ( aPropertyName.equalsAsciiL ( RTL_CONSTASCII_STRINGPARAM ( "Compressed" ) ) )
849*cdf0e10cSrcweir 	{
850*cdf0e10cSrcweir 		sal_Bool bCompr = sal_False;
851*cdf0e10cSrcweir 
852*cdf0e10cSrcweir 		if ( aValue >>= bCompr )
853*cdf0e10cSrcweir 		{
854*cdf0e10cSrcweir 			// In case of new raw stream, the stream must not be encrypted on storing
855*cdf0e10cSrcweir 			if ( bCompr && m_nStreamMode == PACKAGE_STREAM_RAW )
856*cdf0e10cSrcweir 				throw IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Raw stream can not be encrypted on storing" ) ),
857*cdf0e10cSrcweir 												uno::Reference< XInterface >(),
858*cdf0e10cSrcweir 												2 );
859*cdf0e10cSrcweir 
860*cdf0e10cSrcweir 			bToBeCompressed = bCompr;
861*cdf0e10cSrcweir 			m_bCompressedIsSetFromOutside = sal_True;
862*cdf0e10cSrcweir 		}
863*cdf0e10cSrcweir 		else
864*cdf0e10cSrcweir 			throw IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Wrong type for Compressed property!\n" ) ),
865*cdf0e10cSrcweir 											uno::Reference< XInterface >(),
866*cdf0e10cSrcweir 											2 );
867*cdf0e10cSrcweir 	}
868*cdf0e10cSrcweir 	else
869*cdf0e10cSrcweir 		throw beans::UnknownPropertyException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
870*cdf0e10cSrcweir }
871*cdf0e10cSrcweir 
872*cdf0e10cSrcweir //--------------------------------------------------------------------------
873*cdf0e10cSrcweir Any SAL_CALL ZipPackageStream::getPropertyValue( const OUString& PropertyName )
874*cdf0e10cSrcweir 		throw( beans::UnknownPropertyException, WrappedTargetException, RuntimeException )
875*cdf0e10cSrcweir {
876*cdf0e10cSrcweir 	Any aAny;
877*cdf0e10cSrcweir 	if ( PropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "MediaType" ) ) )
878*cdf0e10cSrcweir 	{
879*cdf0e10cSrcweir 		aAny <<= sMediaType;
880*cdf0e10cSrcweir 		return aAny;
881*cdf0e10cSrcweir 	}
882*cdf0e10cSrcweir 	else if ( PropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( "Size" ) ) )
883*cdf0e10cSrcweir 	{
884*cdf0e10cSrcweir 		aAny <<= aEntry.nSize;
885*cdf0e10cSrcweir 		return aAny;
886*cdf0e10cSrcweir 	}
887*cdf0e10cSrcweir 	else if ( PropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( "Encrypted" ) ) )
888*cdf0e10cSrcweir 	{
889*cdf0e10cSrcweir 		aAny <<= ( m_nStreamMode == PACKAGE_STREAM_RAW ) ? sal_True : bToBeEncrypted;
890*cdf0e10cSrcweir 		return aAny;
891*cdf0e10cSrcweir 	}
892*cdf0e10cSrcweir 	else if ( PropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( "WasEncrypted" ) ) )
893*cdf0e10cSrcweir 	{
894*cdf0e10cSrcweir 		aAny <<= bIsEncrypted;
895*cdf0e10cSrcweir 		return aAny;
896*cdf0e10cSrcweir 	}
897*cdf0e10cSrcweir 	else if ( PropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( "Compressed" ) ) )
898*cdf0e10cSrcweir 	{
899*cdf0e10cSrcweir 		aAny <<= bToBeCompressed;
900*cdf0e10cSrcweir 		return aAny;
901*cdf0e10cSrcweir 	}
902*cdf0e10cSrcweir 	else if ( PropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( ENCRYPTION_KEY_PROPERTY ) ) )
903*cdf0e10cSrcweir 	{
904*cdf0e10cSrcweir 		aAny <<= m_aEncryptionKey;
905*cdf0e10cSrcweir 		return aAny;
906*cdf0e10cSrcweir 	}
907*cdf0e10cSrcweir 	else if ( PropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( STORAGE_ENCRYPTION_KEYS_PROPERTY ) ) )
908*cdf0e10cSrcweir 	{
909*cdf0e10cSrcweir 		aAny <<= m_aStorageEncryptionKeys;
910*cdf0e10cSrcweir 		return aAny;
911*cdf0e10cSrcweir 	}
912*cdf0e10cSrcweir 	else
913*cdf0e10cSrcweir 		throw beans::UnknownPropertyException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
914*cdf0e10cSrcweir }
915*cdf0e10cSrcweir 
916*cdf0e10cSrcweir //--------------------------------------------------------------------------
917*cdf0e10cSrcweir void ZipPackageStream::setSize ( const sal_Int32 nNewSize )
918*cdf0e10cSrcweir {
919*cdf0e10cSrcweir 	if ( aEntry.nCompressedSize != nNewSize )
920*cdf0e10cSrcweir 		aEntry.nMethod = DEFLATED;
921*cdf0e10cSrcweir 	aEntry.nSize = nNewSize;
922*cdf0e10cSrcweir }
923*cdf0e10cSrcweir //--------------------------------------------------------------------------
924*cdf0e10cSrcweir OUString ZipPackageStream::getImplementationName()
925*cdf0e10cSrcweir 	throw ( RuntimeException )
926*cdf0e10cSrcweir {
927*cdf0e10cSrcweir 	return OUString ( RTL_CONSTASCII_USTRINGPARAM ( "ZipPackageStream" ) );
928*cdf0e10cSrcweir }
929*cdf0e10cSrcweir 
930*cdf0e10cSrcweir //--------------------------------------------------------------------------
931*cdf0e10cSrcweir Sequence< OUString > ZipPackageStream::getSupportedServiceNames()
932*cdf0e10cSrcweir 	throw ( RuntimeException )
933*cdf0e10cSrcweir {
934*cdf0e10cSrcweir 	Sequence< OUString > aNames( 1 );
935*cdf0e10cSrcweir 	aNames[0] = OUString( RTL_CONSTASCII_USTRINGPARAM ( "com.sun.star.packages.PackageStream" ) );
936*cdf0e10cSrcweir 	return aNames;
937*cdf0e10cSrcweir }
938*cdf0e10cSrcweir //--------------------------------------------------------------------------
939*cdf0e10cSrcweir sal_Bool SAL_CALL ZipPackageStream::supportsService( OUString const & rServiceName )
940*cdf0e10cSrcweir 	throw ( RuntimeException )
941*cdf0e10cSrcweir {
942*cdf0e10cSrcweir 	return rServiceName == getSupportedServiceNames()[0];
943*cdf0e10cSrcweir }
944*cdf0e10cSrcweir 
945