LibreOffice Module package (master) 1
ZipPackageStream.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_ZIPPACKAGESTREAM_HXX
20#define INCLUDED_PACKAGE_INC_ZIPPACKAGESTREAM_HXX
21
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>
29
30#include "EncryptionData.hxx"
31
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
37
38class ZipPackage;
39struct ZipEntry;
40class ZipPackageStream final : public cppu::ImplInheritanceHelper
41<
42 ZipPackageEntry,
43 css::io::XActiveDataSink,
44 css::packages::XDataSinkEncrSupport
45>
46{
47private:
48 css::uno::Reference < css::io::XInputStream > m_xStream;
51
53 css::uno::Sequence< css::beans::NamedValue > m_aStorageEncryptionKeys;
54 css::uno::Sequence< sal_Int8 > m_aEncryptionKey;
55
60
65
71
73 css::uno::Reference< css::io::XInputStream > const & GetOwnSeekStream();
76 css::uno::Reference< css::io::XInputStream > getRawData();
77
78public:
80
81 bool IsFromManifest() const { return m_bFromManifest; }
82 void SetFromManifest( bool bValue ) { m_bFromManifest = bValue; }
83
84 enum class Bugs { None, WinEncodingWrongSHA1, WrongSHA1 };
86
87 css::uno::Sequence<sal_Int8> GetEncryptionKey(Bugs bugs = Bugs::None);
88
89 sal_Int32 GetStartKeyGenID() const;
90
91 sal_Int32 GetEncryptionAlgorithm() const;
92 sal_Int32 GetBlockSize() const;
93
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)
101 {
102 m_bToBeEncrypted = bNewValue;
105 else if ( !m_bToBeEncrypted && m_xBaseEncryptionData.is() )
106 m_xBaseEncryptionData.clear();
107 }
108 void SetPackageMember (bool bNewValue);
109
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);
119
120 ZipPackageStream( ZipPackage & rNewPackage,
121 const css::uno::Reference < css::uno::XComponentContext >& xContext,
122 sal_Int32 nFormat,
123 bool bAllowRemoveOnInsert );
124 virtual ~ZipPackageStream() override;
125
126 css::uno::Reference< css::io::XInputStream > GetRawEncrStreamNoHeaderCopy();
127 css::uno::Reference< css::io::XInputStream > TryToGetRawFromDataStream(bool bAddHeaderForEncr );
128
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;
136
137 void setZipEntryOnLoading( const ZipEntry &rInEntry);
138 void successfullyWritten( ZipEntry const *pEntry );
139
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;
143
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;
152
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;
156
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;
161};
162#endif
163
164/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void * rtlRandomPool
#define PACKAGE_STREAM_PACKAGEMEMBER
virtual css::uno::Any SAL_CALL getPropertyValue(const OUString &PropertyName) override
void setDigest(const css::uno::Sequence< sal_Int8 > &rNewDigest)
virtual css::uno::Reference< css::io::XInputStream > SAL_CALL getPlainRawStream() override
void SetImportedDerivedKeySize(sal_Int32 nSize)
sal_Int32 m_nImportedChecksumAlgorithm
void SetImportedChecksumAlgorithm(sal_Int32 nAlgorithm)
sal_Int32 GetBlockSize() const
void successfullyWritten(ZipEntry const *pEntry)
void SetToBeCompressed(bool bNewValue)
::rtl::Reference< BaseEncryptionData > m_xBaseEncryptionData
virtual css::uno::Reference< css::io::XInputStream > SAL_CALL getDataStream() override
css::uno::Reference< css::io::XInputStream > GetRawEncrStreamNoHeaderCopy()
css::uno::Sequence< sal_Int8 > m_aEncryptionKey
virtual css::uno::Reference< css::io::XInputStream > SAL_CALL getRawStream() override
css::uno::Reference< css::io::XInputStream > getRawData()
get raw data using unbuffered stream
virtual sal_Bool SAL_CALL supportsService(const OUString &ServiceName) override
virtual css::uno::Reference< css::io::XInputStream > SAL_CALL getInputStream() override
void SetPackageMember(bool bNewValue)
void SetImportedEncryptionAlgorithm(sal_Int32 nAlgorithm)
css::uno::Reference< css::io::XInputStream > TryToGetRawFromDataStream(bool bAddHeaderForEncr)
virtual void SAL_CALL setInputStream(const css::uno::Reference< css::io::XInputStream > &aStream) override
void SetFromManifest(bool bValue)
sal_Int64 m_nOwnStreamOrigSize
virtual void SAL_CALL setPropertyValue(const OUString &aPropertyName, const css::uno::Any &aValue) override
sal_Int32 m_nImportedStartKeyAlgorithm
ZipPackageStream(ZipPackage &rNewPackage, const css::uno::Reference< css::uno::XComponentContext > &xContext, sal_Int32 nFormat, bool bAllowRemoveOnInsert)
::rtl::Reference< EncryptionData > GetEncryptionData(Bugs bugs=Bugs::None)
void SetToBeEncrypted(bool bNewValue)
ZipPackage & m_rZipPackage
sal_uInt32 m_nMagicalHackPos
void SetIsEncrypted(bool bNewValue)
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
void SetImportedStartKeyAlgorithm(sal_Int32 nAlgorithm)
sal_Int32 m_nImportedDerivedKeySize
virtual void SAL_CALL setDataStream(const css::uno::Reference< css::io::XInputStream > &aStream) override
sal_Int32 GetStartKeyGenID() const
bool IsPackageMember() const
virtual bool saveChild(const OUString &rPath, std::vector< css::uno::Sequence< css::beans::PropertyValue > > &rManList, ZipOutputStream &rZipOut, const css::uno::Sequence< sal_Int8 > &rEncryptionKey, sal_Int32 nPBKDF2IterationCount, const rtlRandomPool &rRandomPool) override
sal_Int32 GetEncryptionAlgorithm() const
virtual ~ZipPackageStream() override
void setInitialisationVector(const css::uno::Sequence< sal_Int8 > &rNewVector)
void setSalt(const css::uno::Sequence< sal_Int8 > &rNewSalt)
virtual OUString SAL_CALL getImplementationName() override
css::uno::Sequence< css::beans::NamedValue > m_aStorageEncryptionKeys
css::uno::Reference< css::io::XInputStream > const & GetOwnSeekStream()
Check that m_xStream implements io::XSeekable and return it.
bool IsFromManifest() const
sal_uInt32 m_nMagicalHackSize
sal_Int32 m_nImportedEncryptionAlgorithm
void setSize(const sal_Int64 nNewSize)
virtual void SAL_CALL setRawStream(const css::uno::Reference< css::io::XInputStream > &aStream) override
css::uno::Reference< css::io::XInputStream > m_xStream
void setZipEntryOnLoading(const ZipEntry &rInEntry)
void setIterationCount(const sal_Int32 nNewCount)
css::uno::Sequence< sal_Int8 > GetEncryptionKey(Bugs bugs=Bugs::None)
None
unsigned char sal_uInt8
unsigned char sal_Bool