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/packages/zip/ZipException.hpp>
23 #include <com/sun/star/packages/zip/ZipIOException.hpp>
24 #include <com/sun/star/packages/NoEncryptionException.hpp>
25 #include <com/sun/star/packages/WrongPasswordException.hpp>
26 #include <com/sun/star/xml/crypto/XCipherContext.hpp>
27 #include <com/sun/star/xml/crypto/XDigestContext.hpp>
29 #include <package/Inflater.hxx>
30 #include <ByteGrabber.hxx>
31 #include <HashMaps.hxx>
32 #include <EncryptionData.hxx>
34 #include <mutexholder.hxx>
36 namespace com
{ namespace sun
{ namespace star
{
37 namespace uno
{ class XComponentContext
; }
38 namespace ucb
{ class XProgressHandler
; }
42 template < class T
> class Reference
;
46 * We impose arbitrary but reasonable limit on ZIP files.
49 #define ZIP_MAXNAMELEN 512
50 #define ZIP_MAXENTRIES (0x10000 - 2)
57 ::osl::Mutex m_aMutex
;
59 OUString sComment
; /* zip file comment */
62 ZipUtils::Inflater aInflater
;
63 com::sun::star::uno::Reference
< com::sun::star::io::XInputStream
> xStream
;
64 com::sun::star::uno::Reference
< com::sun::star::io::XSeekable
> xSeek
;
65 const ::com::sun::star::uno::Reference
< com::sun::star::uno::XComponentContext
> m_xContext
;
66 ::com::sun::star::uno::Reference
< ::com::sun::star::ucb::XProgressHandler
> xProgressHandler
;
70 com::sun::star::uno::Reference
< com::sun::star::io::XInputStream
> createMemoryStream(
72 const ::rtl::Reference
< EncryptionData
> &rData
,
76 com::sun::star::uno::Reference
< com::sun::star::io::XInputStream
> createFileStream(
78 const ::rtl::Reference
< EncryptionData
> &rData
,
82 // aMediaType parameter is used only for raw stream header creation
83 com::sun::star::uno::Reference
< com::sun::star::io::XInputStream
> createUnbufferedStream(
84 SotMutexHolderRef aMutexHolder
,
86 const ::rtl::Reference
< EncryptionData
> &rData
,
89 const OUString
& aMediaType
= OUString() );
91 bool hasValidPassword ( ZipEntry
& rEntry
, const rtl::Reference
< EncryptionData
> &rData
);
93 bool checkSizeAndCRC( const ZipEntry
& aEntry
);
95 sal_Int32
getCRC( sal_Int64 nOffset
, sal_Int64 nSize
);
97 void getSizeAndCRC( sal_Int64 nOffset
, sal_Int64 nCompressedSize
, sal_Int64
*nSize
, sal_Int32
*nCRC
);
101 ZipFile( com::sun::star::uno::Reference
< com::sun::star::io::XInputStream
> &xInput
,
102 const com::sun::star::uno::Reference
< com::sun::star::uno::XComponentContext
> &rxContext
,
105 throw(::com::sun::star::io::IOException
, com::sun::star::packages::zip::ZipException
, com::sun::star::uno::RuntimeException
);
107 ZipFile( com::sun::star::uno::Reference
< com::sun::star::io::XInputStream
> &xInput
,
108 const com::sun::star::uno::Reference
< com::sun::star::uno::XComponentContext
> &rxContext
,
111 ::com::sun::star::uno::Reference
< ::com::sun::star::ucb::XProgressHandler
> xProgress
113 throw(::com::sun::star::io::IOException
, com::sun::star::packages::zip::ZipException
, com::sun::star::uno::RuntimeException
);
117 EntryHash
& GetEntryHash() { return aEntries
; }
119 void setInputStream ( com::sun::star::uno::Reference
< com::sun::star::io::XInputStream
> xNewStream
);
120 ::com::sun::star::uno::Reference
< ::com::sun::star::io::XInputStream
> SAL_CALL
getRawData(
122 const ::rtl::Reference
< EncryptionData
> &rData
,
124 SotMutexHolderRef aMutexHolder
)
125 throw(::com::sun::star::io::IOException
, ::com::sun::star::packages::zip::ZipException
, ::com::sun::star::uno::RuntimeException
);
127 static ::com::sun::star::uno::Reference
< ::com::sun::star::xml::crypto::XDigestContext
> StaticGetDigestContextForChecksum(
128 const ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XComponentContext
>& xArgContext
,
129 const ::rtl::Reference
< EncryptionData
>& xEncryptionData
);
131 static ::com::sun::star::uno::Reference
< ::com::sun::star::xml::crypto::XCipherContext
> StaticGetCipher(
132 const ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XComponentContext
>& xArgContext
,
133 const ::rtl::Reference
< EncryptionData
>& xEncryptionData
,
136 static void StaticFillHeader ( const ::rtl::Reference
< EncryptionData
> & rData
,
138 const OUString
& aMediaType
,
139 sal_Int8
* & pHeader
);
141 static bool StaticFillData ( ::rtl::Reference
< BaseEncryptionData
> & rData
,
142 sal_Int32
&rEncAlgorithm
,
143 sal_Int32
&rChecksumAlgorithm
,
144 sal_Int32
&rDerivedKeySize
,
145 sal_Int32
&rStartKeyGenID
,
147 OUString
& aMediaType
,
148 const ::com::sun::star::uno::Reference
< com::sun::star::io::XInputStream
>& rStream
);
150 static ::com::sun::star::uno::Reference
< ::com::sun::star::io::XInputStream
> StaticGetDataFromRawStream(
151 const ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XComponentContext
>& rxContext
,
152 const ::com::sun::star::uno::Reference
< ::com::sun::star::io::XInputStream
>& xStream
,
153 const ::rtl::Reference
< EncryptionData
> &rData
)
154 throw ( ::com::sun::star::packages::WrongPasswordException
,
155 ::com::sun::star::packages::zip::ZipIOException
,
156 ::com::sun::star::uno::RuntimeException
);
158 static bool StaticHasValidPassword (
159 const ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XComponentContext
>& rxContext
,
160 const ::com::sun::star::uno::Sequence
< sal_Int8
> &aReadBuffer
,
161 const ::rtl::Reference
< EncryptionData
> &rData
);
163 ::com::sun::star::uno::Reference
< ::com::sun::star::io::XInputStream
> SAL_CALL
getInputStream(
165 const ::rtl::Reference
< EncryptionData
> &rData
,
167 SotMutexHolderRef aMutexHolder
)
168 throw(::com::sun::star::io::IOException
, ::com::sun::star::packages::zip::ZipException
, ::com::sun::star::uno::RuntimeException
);
170 ::com::sun::star::uno::Reference
< ::com::sun::star::io::XInputStream
> SAL_CALL
getDataStream(
172 const ::rtl::Reference
< EncryptionData
> &rData
,
174 SotMutexHolderRef aMutexHolder
)
175 throw ( ::com::sun::star::packages::WrongPasswordException
,
176 ::com::sun::star::io::IOException
,
177 ::com::sun::star::packages::zip::ZipException
,
178 ::com::sun::star::uno::RuntimeException
);
180 ::com::sun::star::uno::Reference
< ::com::sun::star::io::XInputStream
> SAL_CALL
getWrappedRawStream(
182 const ::rtl::Reference
< EncryptionData
> &rData
,
183 const OUString
& aMediaType
,
184 SotMutexHolderRef aMutexHolder
)
185 throw ( ::com::sun::star::packages::NoEncryptionException
,
186 ::com::sun::star::io::IOException
,
187 ::com::sun::star::packages::zip::ZipException
,
188 ::com::sun::star::uno::RuntimeException
);
190 ZipEnumeration
* SAL_CALL
entries( );
192 bool readLOC ( ZipEntry
&rEntry
)
193 throw(::com::sun::star::io::IOException
, com::sun::star::packages::zip::ZipException
, com::sun::star::uno::RuntimeException
);
195 throw(::com::sun::star::io::IOException
, com::sun::star::packages::zip::ZipException
, com::sun::star::uno::RuntimeException
);
197 throw(::com::sun::star::io::IOException
, com::sun::star::packages::zip::ZipException
, com::sun::star::uno::RuntimeException
);
199 throw(::com::sun::star::io::IOException
, com::sun::star::packages::zip::ZipException
, com::sun::star::uno::RuntimeException
);
205 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */