bump product version to 6.4.0.3
[LibreOffice.git] / package / inc / ZipPackageStream.hxx
blob7f704ca592326b199cf9b9987f2ccf0dd7a5690a
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/io/XSeekable.hpp>
24 #include <com/sun/star/beans/NamedValue.hpp>
25 #include <com/sun/star/packages/XDataSinkEncrSupport.hpp>
26 #include <com/sun/star/uno/XComponentContext.hpp>
27 #include "ZipPackageEntry.hxx"
28 #include <rtl/ref.hxx>
29 #include <cppuhelper/implbase.hxx>
31 #include "EncryptionData.hxx"
33 #define PACKAGE_STREAM_NOTSET 0
34 #define PACKAGE_STREAM_PACKAGEMEMBER 1
35 #define PACKAGE_STREAM_DETECT 2
36 #define PACKAGE_STREAM_DATA 3
37 #define PACKAGE_STREAM_RAW 4
39 class ZipPackage;
40 struct ZipEntry;
41 class ZipPackageStream : public cppu::ImplInheritanceHelper
43 ZipPackageEntry,
44 css::io::XActiveDataSink,
45 css::packages::XDataSinkEncrSupport
48 private:
49 css::uno::Reference < css::io::XInputStream > m_xStream;
50 ZipPackage &m_rZipPackage;
51 bool m_bToBeCompressed, m_bToBeEncrypted, m_bHaveOwnKey, m_bIsEncrypted;
53 ::rtl::Reference< BaseEncryptionData > m_xBaseEncryptionData;
54 css::uno::Sequence< css::beans::NamedValue > m_aStorageEncryptionKeys;
55 css::uno::Sequence< sal_Int8 > m_aEncryptionKey;
57 sal_Int32 m_nImportedStartKeyAlgorithm;
58 sal_Int32 m_nImportedEncryptionAlgorithm;
59 sal_Int32 m_nImportedChecksumAlgorithm;
60 sal_Int32 m_nImportedDerivedKeySize;
62 sal_uInt8 m_nStreamMode;
63 sal_uInt32 m_nMagicalHackPos;
64 sal_uInt32 m_nMagicalHackSize;
65 sal_Int64 m_nOwnStreamOrigSize;
67 bool m_bHasSeekable;
68 bool m_bCompressedIsSetFromOutside;
69 bool m_bFromManifest;
70 bool m_bUseWinEncoding;
71 bool m_bRawStream;
73 /// Check that m_xStream implements io::XSeekable and return it
74 css::uno::Reference< css::io::XInputStream > const & GetOwnSeekStream();
75 /// get raw data using unbuffered stream
76 /// @throws css::uno::RuntimeException
77 css::uno::Reference< css::io::XInputStream > getRawData();
79 public:
80 bool IsPackageMember () const { return m_nStreamMode == PACKAGE_STREAM_PACKAGEMEMBER;}
82 bool IsFromManifest() const { return m_bFromManifest; }
83 void SetFromManifest( bool bValue ) { m_bFromManifest = bValue; }
85 enum class Bugs { None, WinEncodingWrongSHA1, WrongSHA1 };
86 ::rtl::Reference<EncryptionData> GetEncryptionData(Bugs bugs = Bugs::None);
88 css::uno::Sequence<sal_Int8> GetEncryptionKey(Bugs bugs = Bugs::None);
90 sal_Int32 GetStartKeyGenID() const;
92 sal_Int32 GetEncryptionAlgorithm() const;
93 sal_Int32 GetBlockSize() const;
95 void SetToBeCompressed (bool bNewValue) { m_bToBeCompressed = bNewValue;}
96 void SetIsEncrypted (bool bNewValue) { m_bIsEncrypted = bNewValue;}
97 void SetImportedStartKeyAlgorithm( sal_Int32 nAlgorithm ) { m_nImportedStartKeyAlgorithm = nAlgorithm; }
98 void SetImportedEncryptionAlgorithm( sal_Int32 nAlgorithm ) { m_nImportedEncryptionAlgorithm = nAlgorithm; }
99 void SetImportedChecksumAlgorithm( sal_Int32 nAlgorithm ) { m_nImportedChecksumAlgorithm = nAlgorithm; }
100 void SetImportedDerivedKeySize( sal_Int32 nSize ) { m_nImportedDerivedKeySize = nSize; }
101 void SetToBeEncrypted (bool bNewValue)
103 m_bToBeEncrypted = bNewValue;
104 if ( m_bToBeEncrypted && !m_xBaseEncryptionData.is())
105 m_xBaseEncryptionData = new BaseEncryptionData;
106 else if ( !m_bToBeEncrypted && m_xBaseEncryptionData.is() )
107 m_xBaseEncryptionData.clear();
109 void SetPackageMember (bool bNewValue);
111 void setInitialisationVector (const css::uno::Sequence < sal_Int8 >& rNewVector )
112 { m_xBaseEncryptionData->m_aInitVector = rNewVector;}
113 void setSalt (const css::uno::Sequence < sal_Int8 >& rNewSalt )
114 { m_xBaseEncryptionData->m_aSalt = rNewSalt;}
115 void setDigest (const css::uno::Sequence < sal_Int8 >& rNewDigest )
116 { m_xBaseEncryptionData->m_aDigest = rNewDigest;}
117 void setIterationCount (const sal_Int32 nNewCount)
118 { m_xBaseEncryptionData->m_nIterationCount = nNewCount;}
119 void setSize (const sal_Int64 nNewSize);
121 ZipPackageStream( ZipPackage & rNewPackage,
122 const css::uno::Reference < css::uno::XComponentContext >& xContext,
123 sal_Int32 nFormat,
124 bool bAllowRemoveOnInsert );
125 virtual ~ZipPackageStream() override;
127 css::uno::Reference< css::io::XInputStream > GetRawEncrStreamNoHeaderCopy();
128 css::uno::Reference< css::io::XInputStream > TryToGetRawFromDataStream(bool bAddHeaderForEncr );
130 bool ParsePackageRawStream();
131 virtual bool saveChild( const OUString &rPath,
132 std::vector < css::uno::Sequence < css::beans::PropertyValue > > &rManList,
133 ZipOutputStream & rZipOut,
134 const css::uno::Sequence < sal_Int8 >& rEncryptionKey,
135 sal_Int32 nPBKDF2IterationCount,
136 const rtlRandomPool &rRandomPool ) override;
138 void setZipEntryOnLoading( const ZipEntry &rInEntry);
139 void successfullyWritten( ZipEntry const *pEntry );
141 static css::uno::Sequence < sal_Int8 > getUnoTunnelId();
143 // XActiveDataSink
144 virtual void SAL_CALL setInputStream( const css::uno::Reference< css::io::XInputStream >& aStream ) override;
145 virtual css::uno::Reference< css::io::XInputStream > SAL_CALL getInputStream( ) override;
147 // XDataSinkEncrSupport
148 virtual css::uno::Reference< css::io::XInputStream > SAL_CALL getDataStream() override;
149 virtual css::uno::Reference< css::io::XInputStream > SAL_CALL getRawStream() override;
150 virtual void SAL_CALL setDataStream(
151 const css::uno::Reference< css::io::XInputStream >& aStream ) override;
152 virtual void SAL_CALL setRawStream(
153 const css::uno::Reference< css::io::XInputStream >& aStream ) override;
154 virtual css::uno::Reference< css::io::XInputStream > SAL_CALL getPlainRawStream() override;
156 // XUnoTunnel
157 virtual sal_Int64 SAL_CALL getSomething( const css::uno::Sequence< sal_Int8 >& aIdentifier ) override;
159 // XPropertySet
160 virtual void SAL_CALL setPropertyValue( const OUString& aPropertyName, const css::uno::Any& aValue ) override;
161 virtual css::uno::Any SAL_CALL getPropertyValue( const OUString& PropertyName ) override;
163 // XServiceInfo
164 virtual OUString SAL_CALL getImplementationName( ) override;
165 virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override;
166 virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames( ) override;
168 #endif
170 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */