LCOV - code coverage report
Current view: top level - libreoffice/sc/source/filter/inc - biffcodec.hxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 5 0.0 %
Date: 2012-12-27 Functions: 0 8 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       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             : 
      20             : #ifndef OOX_XLS_BIFFCODEC_HXX
      21             : #define OOX_XLS_BIFFCODEC_HXX
      22             : 
      23             : #include <vector>
      24             : #include <comphelper/docpasswordhelper.hxx>
      25             : #include "oox/core/binarycodec.hxx"
      26             : #include "workbookhelper.hxx"
      27             : 
      28             : namespace oox {
      29             : namespace xls {
      30             : 
      31             : // ============================================================================
      32             : 
      33             : const sal_Int64 BIFF_RCF_BLOCKSIZE          = 1024;
      34             : 
      35             : // ============================================================================
      36             : 
      37             : /** Base class for BIFF stream decoders. */
      38             : class BiffDecoderBase : public ::comphelper::IDocPasswordVerifier
      39             : {
      40             : public:
      41             :     explicit            BiffDecoderBase();
      42             :     virtual             ~BiffDecoderBase();
      43             : 
      44             :     /** Derived classes return a clone of the decoder for usage in new streams. */
      45           0 :     inline BiffDecoderBase* clone() { return implClone(); }
      46             : 
      47             :     /** Implementation of the ::comphelper::IDocPasswordVerifier interface. */
      48             :     virtual ::comphelper::DocPasswordVerifierResult verifyPassword( const ::rtl::OUString& rPassword, ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue >& o_rEncryptionData );
      49             :     virtual ::comphelper::DocPasswordVerifierResult verifyEncryptionData( const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue >& o_rEncryptionData );
      50             : 
      51             :     /** Returns true, if the decoder has been initialized correctly. */
      52           0 :     inline bool         isValid() const { return mbValid; }
      53             : 
      54             :     /** Decodes nBytes bytes and writes encrypted data into the buffer pnDestData. */
      55             :     void                decode(
      56             :                             sal_uInt8* pnDestData,
      57             :                             const sal_uInt8* pnSrcData,
      58             :                             sal_Int64 nStreamPos,
      59             :                             sal_uInt16 nBytes );
      60             : 
      61             : private:
      62             :     /** Derived classes return a clone of the decoder for usage in new streams. */
      63             :     virtual BiffDecoderBase* implClone() = 0;
      64             : 
      65             :     /** Derived classes implement password verification and initialization of
      66             :         the decoder. */
      67             :     virtual ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue > implVerifyPassword( const ::rtl::OUString& rPassword ) = 0;
      68             :     virtual bool implVerifyEncryptionData( const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue >& rEncryptionData ) = 0;
      69             : 
      70             :     /** Implementation of decryption of a memory block. */
      71             :     virtual void        implDecode(
      72             :                             sal_uInt8* pnDestData,
      73             :                             const sal_uInt8* pnSrcData,
      74             :                             sal_Int64 nStreamPos,
      75             :                             sal_uInt16 nBytes ) = 0;
      76             : 
      77             : private:
      78             :     bool                mbValid;        /// True = decoder is correctly initialized.
      79             : };
      80             : 
      81             : typedef ::boost::shared_ptr< BiffDecoderBase > BiffDecoderRef;
      82             : 
      83             : // ============================================================================
      84             : 
      85             : /** Decodes BIFF stream contents that are encoded using the old XOR algorithm. */
      86           0 : class BiffDecoder_XOR : public BiffDecoderBase
      87             : {
      88             : private:
      89             :     /** Copy constructor for cloning. */
      90             :                         BiffDecoder_XOR( const BiffDecoder_XOR& rDecoder );
      91             : 
      92             :     /** Returns a clone of the decoder for usage in new streams. */
      93             :     virtual BiffDecoder_XOR* implClone();
      94             : 
      95             :     /** Implements password verification and initialization of the decoder. */
      96             :     virtual ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue > implVerifyPassword( const ::rtl::OUString& rPassword );
      97             :     virtual bool implVerifyEncryptionData( const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue >& rEncryptionData );
      98             : 
      99             : 
     100             :     /** Implementation of decryption of a memory block. */
     101             :     virtual void        implDecode(
     102             :                             sal_uInt8* pnDestData,
     103             :                             const sal_uInt8* pnSrcData,
     104             :                             sal_Int64 nStreamPos,
     105             :                             sal_uInt16 nBytes );
     106             : 
     107             : private:
     108             :     ::oox::core::BinaryCodec_XOR maCodec;   /// Cipher algorithm implementation.
     109             :     ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue > maEncryptionData;
     110             :     sal_uInt16          mnKey;
     111             :     sal_uInt16          mnHash;
     112             : };
     113             : 
     114             : // ============================================================================
     115             : 
     116             : /** Decodes BIFF stream contents that are encoded using the RC4 algorithm. */
     117           0 : class BiffDecoder_RCF : public BiffDecoderBase
     118             : {
     119             : private:
     120             :     /** Copy constructor for cloning. */
     121             :                         BiffDecoder_RCF( const BiffDecoder_RCF& rDecoder );
     122             : 
     123             :     /** Returns a clone of the decoder for usage in new streams. */
     124             :     virtual BiffDecoder_RCF* implClone();
     125             : 
     126             :     /** Implements password verification and initialization of the decoder. */
     127             :     virtual ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue > implVerifyPassword( const ::rtl::OUString& rPassword );
     128             :     virtual bool implVerifyEncryptionData( const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue >& rEncryptionData );
     129             : 
     130             :     /** Implementation of decryption of a memory block. */
     131             :     virtual void        implDecode(
     132             :                             sal_uInt8* pnDestData,
     133             :                             const sal_uInt8* pnSrcData,
     134             :                             sal_Int64 nStreamPos,
     135             :                             sal_uInt16 nBytes );
     136             : 
     137             : private:
     138             :     ::oox::core::BinaryCodec_RCF maCodec;   /// Cipher algorithm implementation.
     139             :     ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue > maEncryptionData;
     140             :     ::std::vector< sal_uInt8 > maSalt;
     141             :     ::std::vector< sal_uInt8 > maVerifier;
     142             :     ::std::vector< sal_uInt8 > maVerifierHash;
     143             : };
     144             : 
     145             : // ============================================================================
     146             : 
     147             : /** Helper for BIFF stream codecs. Holds the used codec object. */
     148           0 : class BiffCodecHelper : public WorkbookHelper
     149             : {
     150             : public:
     151             :     explicit            BiffCodecHelper( const WorkbookHelper& rHelper );
     152             : 
     153             :     /** Clones the contained decoder object if existing and sets it at the passed stream. */
     154             :     void                cloneDecoder( BiffInputStream& rStrm );
     155             : 
     156             : private:
     157             :     BiffDecoderRef      mxDecoder;          /// The decoder for import filter.
     158             : };
     159             : 
     160             : // ============================================================================
     161             : 
     162             : } // namespace xls
     163             : } // namespace oox
     164             : 
     165             : #endif
     166             : 
     167             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10