fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / sc / source / filter / inc / biffcodec.hxx
blob475e2eaf48ce415bd33fd73241fcb07d471a7307
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 .
20 #ifndef INCLUDED_SC_SOURCE_FILTER_INC_BIFFCODEC_HXX
21 #define INCLUDED_SC_SOURCE_FILTER_INC_BIFFCODEC_HXX
23 #include <vector>
24 #include <comphelper/docpasswordhelper.hxx>
25 #include <oox/core/binarycodec.hxx>
26 #include "workbookhelper.hxx"
28 namespace oox {
29 namespace xls {
31 const sal_Int64 BIFF_RCF_BLOCKSIZE = 1024;
33 /** Base class for BIFF stream decoders. */
34 class BiffDecoderBase : public ::comphelper::IDocPasswordVerifier
36 public:
37 explicit BiffDecoderBase();
38 virtual ~BiffDecoderBase();
40 /** Derived classes return a clone of the decoder for usage in new streams. */
41 inline BiffDecoderBase* clone() { return implClone(); }
43 /** Implementation of the ::comphelper::IDocPasswordVerifier interface. */
44 virtual ::comphelper::DocPasswordVerifierResult verifyPassword( const OUString& rPassword, ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue >& o_rEncryptionData ) SAL_OVERRIDE;
45 virtual ::comphelper::DocPasswordVerifierResult verifyEncryptionData( const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue >& o_rEncryptionData ) SAL_OVERRIDE;
47 /** Returns true, if the decoder has been initialized correctly. */
48 inline bool isValid() const { return mbValid; }
50 /** Decodes nBytes bytes and writes encrypted data into the buffer pnDestData. */
51 void decode(
52 sal_uInt8* pnDestData,
53 const sal_uInt8* pnSrcData,
54 sal_Int64 nStreamPos,
55 sal_uInt16 nBytes );
57 private:
58 /** Derived classes return a clone of the decoder for usage in new streams. */
59 virtual BiffDecoderBase* implClone() = 0;
61 /** Derived classes implement password verification and initialization of
62 the decoder. */
63 virtual ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue > implVerifyPassword( const OUString& rPassword ) = 0;
64 virtual bool implVerifyEncryptionData( const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue >& rEncryptionData ) = 0;
66 /** Implementation of decryption of a memory block. */
67 virtual void implDecode(
68 sal_uInt8* pnDestData,
69 const sal_uInt8* pnSrcData,
70 sal_Int64 nStreamPos,
71 sal_uInt16 nBytes ) = 0;
73 private:
74 bool mbValid; /// True = decoder is correctly initialized.
77 typedef ::boost::shared_ptr< BiffDecoderBase > BiffDecoderRef;
79 /** Decodes BIFF stream contents that are encoded using the old XOR algorithm. */
80 class BiffDecoder_XOR : public BiffDecoderBase
82 private:
83 /** Copy constructor for cloning. */
84 BiffDecoder_XOR( const BiffDecoder_XOR& rDecoder );
86 /** Returns a clone of the decoder for usage in new streams. */
87 virtual BiffDecoder_XOR* implClone() SAL_OVERRIDE;
89 /** Implements password verification and initialization of the decoder. */
90 virtual ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue > implVerifyPassword( const OUString& rPassword ) SAL_OVERRIDE;
91 virtual bool implVerifyEncryptionData( const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue >& rEncryptionData ) SAL_OVERRIDE;
93 /** Implementation of decryption of a memory block. */
94 virtual void implDecode(
95 sal_uInt8* pnDestData,
96 const sal_uInt8* pnSrcData,
97 sal_Int64 nStreamPos,
98 sal_uInt16 nBytes ) SAL_OVERRIDE;
100 private:
101 ::oox::core::BinaryCodec_XOR maCodec; /// Cipher algorithm implementation.
102 ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue > maEncryptionData;
103 sal_uInt16 mnKey;
104 sal_uInt16 mnHash;
107 /** Decodes BIFF stream contents that are encoded using the RC4 algorithm. */
108 class BiffDecoder_RCF : public BiffDecoderBase
110 private:
111 /** Copy constructor for cloning. */
112 BiffDecoder_RCF( const BiffDecoder_RCF& rDecoder );
114 /** Returns a clone of the decoder for usage in new streams. */
115 virtual BiffDecoder_RCF* implClone() SAL_OVERRIDE;
117 /** Implements password verification and initialization of the decoder. */
118 virtual ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue > implVerifyPassword( const OUString& rPassword ) SAL_OVERRIDE;
119 virtual bool implVerifyEncryptionData( const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue >& rEncryptionData ) SAL_OVERRIDE;
121 /** Implementation of decryption of a memory block. */
122 virtual void implDecode(
123 sal_uInt8* pnDestData,
124 const sal_uInt8* pnSrcData,
125 sal_Int64 nStreamPos,
126 sal_uInt16 nBytes ) SAL_OVERRIDE;
128 private:
129 ::oox::core::BinaryCodec_RCF maCodec; /// Cipher algorithm implementation.
130 ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue > maEncryptionData;
131 ::std::vector< sal_uInt8 > maSalt;
132 ::std::vector< sal_uInt8 > maVerifier;
133 ::std::vector< sal_uInt8 > maVerifierHash;
136 /** Helper for BIFF stream codecs. Holds the used codec object. */
137 class BiffCodecHelper : public WorkbookHelper
139 public:
140 explicit BiffCodecHelper( const WorkbookHelper& rHelper );
142 /** Clones the contained decoder object if existing and sets it at the passed stream. */
143 void cloneDecoder( BiffInputStream& rStrm );
145 private:
146 BiffDecoderRef mxDecoder; /// The decoder for import filter.
149 } // namespace xls
150 } // namespace oox
152 #endif
154 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */