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 _ZIP_PACKAGE_STREAM_HXX
20 #define _ZIP_PACKAGE_STREAM_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/implbase2.hxx>
31 #include <EncryptionData.hxx>
32 #include <mutexholder.hxx>
34 #define PACKAGE_STREAM_NOTSET 0
35 #define PACKAGE_STREAM_PACKAGEMEMBER 1
36 #define PACKAGE_STREAM_DETECT 2
37 #define PACKAGE_STREAM_DATA 3
38 #define PACKAGE_STREAM_RAW 4
42 class ZipPackageStream
: public cppu::ImplInheritanceHelper2
45 ::com::sun::star::io::XActiveDataSink
,
46 ::com::sun::star::packages::XDataSinkEncrSupport
50 com::sun::star::uno::Reference
< com::sun::star::io::XInputStream
> xStream
;
51 const ::com::sun::star::uno::Reference
< com::sun::star::uno::XComponentContext
> m_xContext
;
52 ZipPackage
&rZipPackage
;
53 sal_Bool bToBeCompressed
, bToBeEncrypted
, bHaveOwnKey
, bIsEncrypted
;
55 ::rtl::Reference
< BaseEncryptionData
> m_xBaseEncryptionData
;
56 ::com::sun::star::uno::Sequence
< ::com::sun::star::beans::NamedValue
> m_aStorageEncryptionKeys
;
57 ::com::sun::star::uno::Sequence
< sal_Int8
> m_aEncryptionKey
;
59 sal_Int32 m_nImportedStartKeyAlgorithm
;
60 sal_Int32 m_nImportedEncryptionAlgorithm
;
61 sal_Int32 m_nImportedChecksumAlgorithm
;
62 sal_Int32 m_nImportedDerivedKeySize
;
64 sal_uInt8 m_nStreamMode
;
65 sal_uInt32 m_nMagicalHackPos
;
66 sal_uInt32 m_nMagicalHackSize
;
68 sal_Bool m_bHasSeekable
;
70 sal_Bool m_bCompressedIsSetFromOutside
;
72 sal_Bool m_bFromManifest
;
74 bool m_bUseWinEncoding
;
76 ::com::sun::star::uno::Reference
< ::com::sun::star::io::XInputStream
> GetOwnSeekStream();
79 sal_Bool
HasOwnKey () const { return bHaveOwnKey
;}
80 sal_Bool
IsToBeCompressed () const { return bToBeCompressed
;}
81 sal_Bool
IsToBeEncrypted () const { return bToBeEncrypted
;}
82 sal_Bool
IsEncrypted () const { return bIsEncrypted
;}
83 sal_Bool
IsPackageMember () const { return m_nStreamMode
== PACKAGE_STREAM_PACKAGEMEMBER
;}
85 sal_Bool
IsFromManifest() const { return m_bFromManifest
; }
86 void SetFromManifest( sal_Bool bValue
) { m_bFromManifest
= bValue
; }
88 ::rtl::Reference
< EncryptionData
> GetEncryptionData( bool bWinEncoding
= false );
90 ::com::sun::star::uno::Sequence
< sal_Int8
> GetEncryptionKey( bool bWinEncoding
= false );
92 sal_Int32
GetStartKeyGenID();
94 const com::sun::star::uno::Sequence
< sal_Int8
> getInitialisationVector () const
95 { return m_xBaseEncryptionData
->m_aInitVector
;}
96 const com::sun::star::uno::Sequence
< sal_Int8
> getDigest () const
97 { return m_xBaseEncryptionData
->m_aDigest
;}
98 const com::sun::star::uno::Sequence
< sal_Int8
> getSalt () const
99 { return m_xBaseEncryptionData
->m_aSalt
;}
100 sal_Int32
getIterationCount () const
101 { return m_xBaseEncryptionData
->m_nIterationCount
;}
102 sal_Int64
getSize () const
103 { return aEntry
.nSize
;}
105 sal_uInt8
GetStreamMode() const { return m_nStreamMode
; }
106 sal_uInt32
GetMagicalHackPos() const { return m_nMagicalHackPos
; }
107 sal_uInt32
GetMagicalHackSize() const { return m_nMagicalHackSize
; }
108 sal_Int32
GetEncryptionAlgorithm() const;
109 sal_Int32
GetBlockSize() const;
111 void SetToBeCompressed (sal_Bool bNewValue
) { bToBeCompressed
= bNewValue
;}
112 void SetIsEncrypted (sal_Bool bNewValue
) { bIsEncrypted
= bNewValue
;}
113 void SetImportedStartKeyAlgorithm( sal_Int32 nAlgorithm
) { m_nImportedStartKeyAlgorithm
= nAlgorithm
; }
114 void SetImportedEncryptionAlgorithm( sal_Int32 nAlgorithm
) { m_nImportedEncryptionAlgorithm
= nAlgorithm
; }
115 void SetImportedChecksumAlgorithm( sal_Int32 nAlgorithm
) { m_nImportedChecksumAlgorithm
= nAlgorithm
; }
116 void SetImportedDerivedKeySize( sal_Int32 nSize
) { m_nImportedDerivedKeySize
= nSize
; }
117 void SetToBeEncrypted (sal_Bool bNewValue
)
119 bToBeEncrypted
= bNewValue
;
120 if ( bToBeEncrypted
&& !m_xBaseEncryptionData
.is())
121 m_xBaseEncryptionData
= new BaseEncryptionData
;
122 else if ( !bToBeEncrypted
&& m_xBaseEncryptionData
.is() )
123 m_xBaseEncryptionData
.clear();
125 void SetPackageMember (sal_Bool bNewValue
);
127 void setKey (const com::sun::star::uno::Sequence
< sal_Int8
>& rNewKey
)
128 { m_aEncryptionKey
= rNewKey
; m_aStorageEncryptionKeys
.realloc( 0 ); }
129 void setInitialisationVector (const com::sun::star::uno::Sequence
< sal_Int8
>& rNewVector
)
130 { m_xBaseEncryptionData
->m_aInitVector
= rNewVector
;}
131 void setSalt (const com::sun::star::uno::Sequence
< sal_Int8
>& rNewSalt
)
132 { m_xBaseEncryptionData
->m_aSalt
= rNewSalt
;}
133 void setDigest (const com::sun::star::uno::Sequence
< sal_Int8
>& rNewDigest
)
134 { m_xBaseEncryptionData
->m_aDigest
= rNewDigest
;}
135 void setIterationCount (const sal_Int32 nNewCount
)
136 { m_xBaseEncryptionData
->m_nIterationCount
= nNewCount
;}
137 void setSize (const sal_Int64 nNewSize
);
139 ::com::sun::star::uno::Reference
< ::com::sun::star::io::XInputStream
> GetOwnStreamNoWrap() { return xStream
; }
141 void CloseOwnStreamIfAny();
143 ZipPackageStream ( ZipPackage
& rNewPackage
,
144 const ::com::sun::star::uno::Reference
< com::sun::star::uno::XComponentContext
>& xContext
,
145 sal_Bool bAllowRemoveOnInsert
);
146 virtual ~ZipPackageStream( void );
148 ::com::sun::star::uno::Reference
< ::com::sun::star::io::XInputStream
> GetRawEncrStreamNoHeaderCopy();
149 ::com::sun::star::uno::Reference
< ::com::sun::star::io::XInputStream
> TryToGetRawFromDataStream(
150 sal_Bool bAddHeaderForEncr
);
152 sal_Bool
ParsePackageRawStream();
154 void setZipEntryOnLoading( const ZipEntry
&rInEntry
);
155 ::com::sun::star::uno::Reference
< ::com::sun::star::io::XInputStream
> SAL_CALL
getRawData()
156 throw(::com::sun::star::uno::RuntimeException
);
158 static const ::com::sun::star::uno::Sequence
< sal_Int8
>& static_getImplementationId();
161 virtual void SAL_CALL
setInputStream( const ::com::sun::star::uno::Reference
< ::com::sun::star::io::XInputStream
>& aStream
)
162 throw(::com::sun::star::uno::RuntimeException
);
163 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::io::XInputStream
> SAL_CALL
getInputStream( )
164 throw(::com::sun::star::uno::RuntimeException
);
166 // XDataSinkEncrSupport
167 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::io::XInputStream
> SAL_CALL
getDataStream()
168 throw ( ::com::sun::star::packages::WrongPasswordException
,
169 ::com::sun::star::io::IOException
,
170 ::com::sun::star::uno::RuntimeException
);
171 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::io::XInputStream
> SAL_CALL
getRawStream()
172 throw ( ::com::sun::star::packages::NoEncryptionException
,
173 ::com::sun::star::io::IOException
,
174 ::com::sun::star::uno::RuntimeException
);
175 virtual void SAL_CALL
setDataStream(
176 const ::com::sun::star::uno::Reference
< ::com::sun::star::io::XInputStream
>& aStream
)
177 throw ( ::com::sun::star::io::IOException
,
178 ::com::sun::star::uno::RuntimeException
);
179 virtual void SAL_CALL
setRawStream(
180 const ::com::sun::star::uno::Reference
< ::com::sun::star::io::XInputStream
>& aStream
)
181 throw ( ::com::sun::star::packages::EncryptionNotAllowedException
,
182 ::com::sun::star::packages::NoRawFormatException
,
183 ::com::sun::star::io::IOException
,
184 ::com::sun::star::uno::RuntimeException
);
185 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::io::XInputStream
> SAL_CALL
getPlainRawStream()
186 throw ( ::com::sun::star::io::IOException
,
187 ::com::sun::star::uno::RuntimeException
);
190 virtual sal_Int64 SAL_CALL
getSomething( const ::com::sun::star::uno::Sequence
< sal_Int8
>& aIdentifier
)
191 throw(::com::sun::star::uno::RuntimeException
);
194 virtual void SAL_CALL
setPropertyValue( const OUString
& aPropertyName
, const ::com::sun::star::uno::Any
& aValue
)
195 throw(::com::sun::star::beans::UnknownPropertyException
, ::com::sun::star::beans::PropertyVetoException
, ::com::sun::star::lang::IllegalArgumentException
, ::com::sun::star::lang::WrappedTargetException
, ::com::sun::star::uno::RuntimeException
);
196 virtual ::com::sun::star::uno::Any SAL_CALL
getPropertyValue( const OUString
& PropertyName
)
197 throw(::com::sun::star::beans::UnknownPropertyException
, ::com::sun::star::lang::WrappedTargetException
, ::com::sun::star::uno::RuntimeException
);
200 virtual OUString SAL_CALL
getImplementationName( )
201 throw (::com::sun::star::uno::RuntimeException
);
202 virtual sal_Bool SAL_CALL
supportsService( const OUString
& ServiceName
)
203 throw (::com::sun::star::uno::RuntimeException
);
204 virtual ::com::sun::star::uno::Sequence
< OUString
> SAL_CALL
getSupportedServiceNames( )
205 throw (::com::sun::star::uno::RuntimeException
);
209 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */