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