LibreOffice Module package (master) 1
ZipFile.hxx
Go to the documentation of this file.
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#ifndef INCLUDED_PACKAGE_INC_ZIPFILE_HXX
20#define INCLUDED_PACKAGE_INC_ZIPFILE_HXX
21
22#include <com/sun/star/xml/crypto/XCipherContext.hpp>
23#include <com/sun/star/xml/crypto/XDigestContext.hpp>
24
26#include <package/Inflater.hxx>
27#include <rtl/ref.hxx>
28#include "ByteGrabber.hxx"
29#include "HashMaps.hxx"
30#include "EncryptionData.hxx"
31
33namespace com::sun::star {
34 namespace uno { class XComponentContext; }
35 namespace ucb { class XProgressHandler; }
36}
37namespace rtl
38{
39 template < class T > class Reference;
40}
41
42/*
43 * We impose arbitrary but reasonable limit on ZIP files.
44 */
45
46#define ZIP_MAXNAMELEN 512
47#define ZIP_MAXENTRIES (0x10000 - 2)
48
49class ZipEnumeration;
50
51class ZipFile
52{
54
55 EntryHash aEntries;
56 ByteGrabber aGrabber;
57 ZipUtils::Inflater aInflater;
58 css::uno::Reference < css::io::XInputStream > xStream;
59 const css::uno::Reference < css::uno::XComponentContext > m_xContext;
60
61 bool bRecoveryMode;
62
63 // aMediaType parameter is used only for raw stream header creation
64 css::uno::Reference < css::io::XInputStream > createStreamForZipEntry(
66 ZipEntry const & rEntry,
67 const ::rtl::Reference < EncryptionData > &rData,
68 sal_Int8 nStreamMode,
69 bool bDecrypt,
70 const bool bUseBufferedStream = true,
71 const OUString& aMediaType = OUString() );
72
73 bool hasValidPassword ( ZipEntry const & rEntry, const rtl::Reference < EncryptionData > &rData );
74
75 bool checkSizeAndCRC( const ZipEntry& aEntry );
76
77 sal_Int32 getCRC( sal_Int64 nOffset, sal_Int64 nSize );
78
79 void getSizeAndCRC( sal_Int64 nOffset, sal_Int64 nCompressedSize, sal_Int64 *nSize, sal_Int32 *nCRC );
80
81 void readLOC( ZipEntry &rEntry );
82 sal_Int32 readCEN();
83 sal_Int32 findEND();
84 void recover();
85 static void readExtraFields(MemoryByteGrabber& aMemGrabber, sal_Int16 nExtraLen,
86 sal_uInt64& nSize, sal_uInt64& nCompressedSize,
87 sal_uInt64* nOffset);
88
89public:
90
92 css::uno::Reference < css::io::XInputStream > const &xInput,
93 css::uno::Reference < css::uno::XComponentContext > xContext,
94 bool bInitialise );
95
97 css::uno::Reference < css::io::XInputStream > const &xInput,
98 css::uno::Reference < css::uno::XComponentContext > xContext,
99 bool bInitialise,
100 bool bForceRecover );
101
102 ~ZipFile();
103
104 EntryHash& GetEntryHash() { return aEntries; }
105
106 void setInputStream ( const css::uno::Reference < css::io::XInputStream >& xNewStream );
107 css::uno::Reference< css::io::XInputStream > getRawData(
108 ZipEntry& rEntry,
109 const ::rtl::Reference < EncryptionData > &rData,
110 bool bDecrypt,
112 const bool bUseBufferedStream = true );
113
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 );
117
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,
121 bool bEncrypt );
122
123 static void StaticFillHeader ( const ::rtl::Reference < EncryptionData > & rData,
124 sal_Int64 nSize,
125 const OUString& aMediaType,
126 sal_Int8 * & pHeader );
127
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,
133 sal_Int32 &rSize,
134 OUString& aMediaType,
135 const css::uno::Reference < css::io::XInputStream >& rStream );
136
137 static css::uno::Reference< css::io::XInputStream > StaticGetDataFromRawStream(
139 const css::uno::Reference< css::uno::XComponentContext >& rxContext,
140 const css::uno::Reference< css::io::XInputStream >& xStream,
141 const ::rtl::Reference < EncryptionData > &rData );
142
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 );
147
148 css::uno::Reference< css::io::XInputStream > getInputStream(
149 ZipEntry& rEntry,
150 const ::rtl::Reference < EncryptionData > &rData,
151 bool bDecrypt,
153
154 css::uno::Reference< css::io::XInputStream > getDataStream(
155 ZipEntry& rEntry,
156 const ::rtl::Reference < EncryptionData > &rData,
157 bool bDecrypt,
159
160 css::uno::Reference< css::io::XInputStream > getWrappedRawStream(
161 ZipEntry& rEntry,
162 const ::rtl::Reference < EncryptionData > &rData,
163 const OUString& aMediaType,
165
166 ZipEnumeration entries();
167};
168
169#endif
170
171/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
std::unordered_map< OUString, ZipEntry > EntryHash
Definition: HashMaps.hxx:32
~ZipFile()
Definition: ZipFile.cxx:121
ZipFile(const Filepath_t &FileName)
ScXMLEditAttributeMap::Entry const aEntries[]
Reference
signed char sal_Int8