Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / package / inc / ZipPackageStream.hxx
blob194ff729adbe8aec9ef3afb31a9be71b0bf68647
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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_ZIPPACKAGESTREAM_HXX
20 #define INCLUDED_PACKAGE_INC_ZIPPACKAGESTREAM_HXX
22 #include <com/sun/star/io/XActiveDataSink.hpp>
23 #include <com/sun/star/beans/NamedValue.hpp>
24 #include <com/sun/star/packages/XDataSinkEncrSupport.hpp>
25 #include <com/sun/star/uno/XComponentContext.hpp>
26 #include "ZipPackageEntry.hxx"
27 #include <rtl/ref.hxx>
28 #include <cppuhelper/implbase.hxx>
30 #include "EncryptionData.hxx"
32 #define PACKAGE_STREAM_NOTSET 0
33 #define PACKAGE_STREAM_PACKAGEMEMBER 1
34 #define PACKAGE_STREAM_DETECT 2
35 #define PACKAGE_STREAM_DATA 3
36 #define PACKAGE_STREAM_RAW 4
38 class ZipPackage;
39 struct ZipEntry;
40 class ZipPackageStream final : public cppu::ImplInheritanceHelper
42 ZipPackageEntry,
43 css::io::XActiveDataSink,
44 css::packages::XDataSinkEncrSupport
47 private:
48 css::uno::Reference < css::io::XInputStream > m_xStream;
49 ZipPackage &m_rZipPackage;
50 bool m_bToBeCompressed, m_bToBeEncrypted, m_bHaveOwnKey, m_bIsEncrypted;
52 ::rtl::Reference< BaseEncryptionData > m_xBaseEncryptionData;
53 css::uno::Sequence< css::beans::NamedValue > m_aStorageEncryptionKeys;
54 css::uno::Sequence< sal_Int8 > m_aEncryptionKey;
56 sal_Int32 m_nImportedStartKeyAlgorithm;
57 sal_Int32 m_nImportedEncryptionAlgorithm;
58 sal_Int32 m_nImportedChecksumAlgorithm;
59 sal_Int32 m_nImportedDerivedKeySize;
61 sal_uInt8 m_nStreamMode;
62 sal_uInt32 m_nMagicalHackPos;
63 sal_uInt32 m_nMagicalHackSize;
64 sal_Int64 m_nOwnStreamOrigSize;
66 bool m_bHasSeekable;
67 bool m_bCompressedIsSetFromOutside;
68 bool m_bFromManifest;
69 bool m_bUseWinEncoding;
70 bool m_bRawStream;
72 /// Check that m_xStream implements io::XSeekable and return it
73 css::uno::Reference< css::io::XInputStream > const & GetOwnSeekStream();
74 /// get raw data using unbuffered stream
75 /// @throws css::uno::RuntimeException
76 css::uno::Reference< css::io::XInputStream > getRawData();
78 public:
79 bool IsPackageMember () const { return m_nStreamMode == PACKAGE_STREAM_PACKAGEMEMBER;}
81 bool IsFromManifest() const { return m_bFromManifest; }
82 void SetFromManifest( bool bValue ) { m_bFromManifest = bValue; }
84 enum class Bugs { None, WinEncodingWrongSHA1, WrongSHA1 };
85 ::rtl::Reference<EncryptionData> GetEncryptionData(Bugs bugs = Bugs::None);
87 css::uno::Sequence<sal_Int8> GetEncryptionKey(Bugs bugs = Bugs::None);
89 sal_Int32 GetStartKeyGenID() const;
91 sal_Int32 GetEncryptionAlgorithm() const;
92 sal_Int32 GetBlockSize() const;
94 void SetToBeCompressed (bool bNewValue) { m_bToBeCompressed = bNewValue;}
95 void SetIsEncrypted (bool bNewValue) { m_bIsEncrypted = bNewValue;}
96 void SetImportedStartKeyAlgorithm( sal_Int32 nAlgorithm ) { m_nImportedStartKeyAlgorithm = nAlgorithm; }
97 void SetImportedEncryptionAlgorithm( sal_Int32 nAlgorithm ) { m_nImportedEncryptionAlgorithm = nAlgorithm; }
98 void SetImportedChecksumAlgorithm( sal_Int32 nAlgorithm ) { m_nImportedChecksumAlgorithm = nAlgorithm; }
99 void SetImportedDerivedKeySize( sal_Int32 nSize ) { m_nImportedDerivedKeySize = nSize; }
100 void SetToBeEncrypted (bool bNewValue)
102 m_bToBeEncrypted = bNewValue;
103 if ( m_bToBeEncrypted && !m_xBaseEncryptionData.is())
104 m_xBaseEncryptionData = new BaseEncryptionData;
105 else if ( !m_bToBeEncrypted && m_xBaseEncryptionData.is() )
106 m_xBaseEncryptionData.clear();
108 void SetPackageMember (bool bNewValue);
110 void setInitialisationVector (const css::uno::Sequence < sal_Int8 >& rNewVector )
111 { m_xBaseEncryptionData->m_aInitVector = rNewVector;}
112 void setSalt (const css::uno::Sequence < sal_Int8 >& rNewSalt )
113 { m_xBaseEncryptionData->m_aSalt = rNewSalt;}
114 void setDigest (const css::uno::Sequence < sal_Int8 >& rNewDigest )
115 { m_xBaseEncryptionData->m_aDigest = rNewDigest;}
116 void setIterationCount (const sal_Int32 nNewCount)
117 { m_xBaseEncryptionData->m_nIterationCount = nNewCount;}
118 void setSize (const sal_Int64 nNewSize);
120 ZipPackageStream( ZipPackage & rNewPackage,
121 const css::uno::Reference < css::uno::XComponentContext >& xContext,
122 sal_Int32 nFormat,
123 bool bAllowRemoveOnInsert );
124 virtual ~ZipPackageStream() override;
126 css::uno::Reference< css::io::XInputStream > GetRawEncrStreamNoHeaderCopy();
127 css::uno::Reference< css::io::XInputStream > TryToGetRawFromDataStream(bool bAddHeaderForEncr );
129 bool ParsePackageRawStream();
130 virtual bool saveChild( const OUString &rPath,
131 std::vector < css::uno::Sequence < css::beans::PropertyValue > > &rManList,
132 ZipOutputStream & rZipOut,
133 const css::uno::Sequence < sal_Int8 >& rEncryptionKey,
134 sal_Int32 nPBKDF2IterationCount,
135 const rtlRandomPool &rRandomPool ) override;
137 void setZipEntryOnLoading( const ZipEntry &rInEntry);
138 void successfullyWritten( ZipEntry const *pEntry );
140 // XActiveDataSink
141 virtual void SAL_CALL setInputStream( const css::uno::Reference< css::io::XInputStream >& aStream ) override;
142 virtual css::uno::Reference< css::io::XInputStream > SAL_CALL getInputStream( ) override;
144 // XDataSinkEncrSupport
145 virtual css::uno::Reference< css::io::XInputStream > SAL_CALL getDataStream() override;
146 virtual css::uno::Reference< css::io::XInputStream > SAL_CALL getRawStream() override;
147 virtual void SAL_CALL setDataStream(
148 const css::uno::Reference< css::io::XInputStream >& aStream ) override;
149 virtual void SAL_CALL setRawStream(
150 const css::uno::Reference< css::io::XInputStream >& aStream ) override;
151 virtual css::uno::Reference< css::io::XInputStream > SAL_CALL getPlainRawStream() override;
153 // XPropertySet
154 virtual void SAL_CALL setPropertyValue( const OUString& aPropertyName, const css::uno::Any& aValue ) override;
155 virtual css::uno::Any SAL_CALL getPropertyValue( const OUString& PropertyName ) override;
157 // XServiceInfo
158 virtual OUString SAL_CALL getImplementationName( ) override;
159 virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override;
160 virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames( ) override;
162 #endif
164 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */