1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
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 .
19 #ifndef INCLUDED_PACKAGE_INC_ZIPFILE_HXX
20 #define INCLUDED_PACKAGE_INC_ZIPFILE_HXX
22 #include <com/sun/star/xml/crypto/XCipherContext.hpp>
23 #include <com/sun/star/xml/crypto/XDigestContext.hpp>
25 #include <comphelper/refcountedmutex.hxx>
26 #include <package/Inflater.hxx>
27 #include <rtl/ref.hxx>
28 #include "ByteGrabber.hxx"
29 #include "HashMaps.hxx"
30 #include "EncryptionData.hxx"
32 class MemoryByteGrabber
;
33 namespace com::sun::star
{
34 namespace uno
{ class XComponentContext
; }
35 namespace ucb
{ class XProgressHandler
; }
39 template < class T
> class Reference
;
43 * We impose arbitrary but reasonable limit on ZIP files.
46 #define ZIP_MAXNAMELEN 512
47 #define ZIP_MAXENTRIES (0x10000 - 2)
53 rtl::Reference
<comphelper::RefCountedMutex
> m_aMutexHolder
;
57 ZipUtils::Inflater aInflater
;
58 css::uno::Reference
< css::io::XInputStream
> xStream
;
59 const css::uno::Reference
< css::uno::XComponentContext
> m_xContext
;
63 // aMediaType parameter is used only for raw stream header creation
64 css::uno::Reference
< css::io::XInputStream
> createStreamForZipEntry(
65 const rtl::Reference
<comphelper::RefCountedMutex
>& aMutexHolder
,
66 ZipEntry
const & rEntry
,
67 const ::rtl::Reference
< EncryptionData
> &rData
,
70 const bool bUseBufferedStream
= true,
71 const OUString
& aMediaType
= OUString() );
73 bool hasValidPassword ( ZipEntry
const & rEntry
, const rtl::Reference
< EncryptionData
> &rData
);
75 bool checkSizeAndCRC( const ZipEntry
& aEntry
);
77 sal_Int32
getCRC( sal_Int64 nOffset
, sal_Int64 nSize
);
79 void getSizeAndCRC( sal_Int64 nOffset
, sal_Int64 nCompressedSize
, sal_Int64
*nSize
, sal_Int32
*nCRC
);
81 void readLOC( ZipEntry
&rEntry
);
85 static void readExtraFields(MemoryByteGrabber
& aMemGrabber
, sal_Int16 nExtraLen
,
86 sal_uInt64
& nSize
, sal_uInt64
& nCompressedSize
,
91 ZipFile( rtl::Reference
<comphelper::RefCountedMutex
> aMutexHolder
,
92 css::uno::Reference
< css::io::XInputStream
> const &xInput
,
93 css::uno::Reference
< css::uno::XComponentContext
> xContext
,
96 ZipFile( rtl::Reference
<comphelper::RefCountedMutex
> aMutexHolder
,
97 css::uno::Reference
< css::io::XInputStream
> const &xInput
,
98 css::uno::Reference
< css::uno::XComponentContext
> xContext
,
100 bool bForceRecover
);
104 EntryHash
& GetEntryHash() { return aEntries
; }
106 void setInputStream ( const css::uno::Reference
< css::io::XInputStream
>& xNewStream
);
107 css::uno::Reference
< css::io::XInputStream
> getRawData(
109 const ::rtl::Reference
< EncryptionData
> &rData
,
111 const rtl::Reference
<comphelper::RefCountedMutex
>& aMutexHolder
,
112 const bool bUseBufferedStream
= true );
114 static css::uno::Reference
< css::xml::crypto::XDigestContext
> StaticGetDigestContextForChecksum(
115 const css::uno::Reference
< css::uno::XComponentContext
>& xArgContext
,
116 const ::rtl::Reference
< EncryptionData
>& xEncryptionData
);
118 static css::uno::Reference
< css::xml::crypto::XCipherContext
> StaticGetCipher(
119 const css::uno::Reference
< css::uno::XComponentContext
>& xArgContext
,
120 const ::rtl::Reference
< EncryptionData
>& xEncryptionData
,
123 static void StaticFillHeader ( const ::rtl::Reference
< EncryptionData
> & rData
,
125 const OUString
& aMediaType
,
126 sal_Int8
* & pHeader
);
128 static bool StaticFillData ( ::rtl::Reference
< BaseEncryptionData
> const & rData
,
129 sal_Int32
&rEncAlgorithm
,
130 sal_Int32
&rChecksumAlgorithm
,
131 sal_Int32
&rDerivedKeySize
,
132 sal_Int32
&rStartKeyGenID
,
134 OUString
& aMediaType
,
135 const css::uno::Reference
< css::io::XInputStream
>& rStream
);
137 static css::uno::Reference
< css::io::XInputStream
> StaticGetDataFromRawStream(
138 const rtl::Reference
<comphelper::RefCountedMutex
>& aMutexHolder
,
139 const css::uno::Reference
< css::uno::XComponentContext
>& rxContext
,
140 const css::uno::Reference
< css::io::XInputStream
>& xStream
,
141 const ::rtl::Reference
< EncryptionData
> &rData
);
143 static bool StaticHasValidPassword (
144 const css::uno::Reference
< css::uno::XComponentContext
>& rxContext
,
145 const css::uno::Sequence
< sal_Int8
> &aReadBuffer
,
146 const ::rtl::Reference
< EncryptionData
> &rData
);
148 css::uno::Reference
< css::io::XInputStream
> getInputStream(
150 const ::rtl::Reference
< EncryptionData
> &rData
,
152 const rtl::Reference
<comphelper::RefCountedMutex
>& aMutexHolder
);
154 css::uno::Reference
< css::io::XInputStream
> getDataStream(
156 const ::rtl::Reference
< EncryptionData
> &rData
,
158 const rtl::Reference
<comphelper::RefCountedMutex
>& aMutexHolder
);
160 css::uno::Reference
< css::io::XInputStream
> getWrappedRawStream(
162 const ::rtl::Reference
< EncryptionData
> &rData
,
163 const OUString
& aMediaType
,
164 const rtl::Reference
<comphelper::RefCountedMutex
>& aMutexHolder
);
166 ZipEnumeration
entries();
171 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */