LCOV - code coverage report
Current view: top level - sc/source/filter/inc - biffcodec.hxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 0 5 0.0 %
Date: 2015-06-13 12:38:46 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 INCLUDED_SC_SOURCE_FILTER_INC_BIFFCODEC_HXX
      21             : #define INCLUDED_SC_SOURCE_FILTER_INC_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             : const sal_Int64 BIFF_RCF_BLOCKSIZE          = 1024;
      32             : 
      33             : /** Base class for BIFF stream decoders. */
      34             : class BiffDecoderBase : public ::comphelper::IDocPasswordVerifier
      35             : {
      36             : public:
      37             :     explicit            BiffDecoderBase();
      38             :     virtual             ~BiffDecoderBase();
      39             : 
      40             :     /** Derived classes return a clone of the decoder for usage in new streams. */
      41           0 :     inline BiffDecoderBase* clone() { return implClone(); }
      42             : 
      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;
      46             : 
      47             :     /** Returns true, if the decoder has been initialized correctly. */
      48           0 :     inline bool         isValid() const { return mbValid; }
      49             : 
      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 );
      56             : 
      57             : private:
      58             :     /** Derived classes return a clone of the decoder for usage in new streams. */
      59             :     virtual BiffDecoderBase* implClone() = 0;
      60             : 
      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;
      65             : 
      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;
      72             : 
      73             : private:
      74             :     bool                mbValid;        /// True = decoder is correctly initialized.
      75             : };
      76             : 
      77             : typedef ::boost::shared_ptr< BiffDecoderBase > BiffDecoderRef;
      78             : 
      79             : /** Decodes BIFF stream contents that are encoded using the old XOR algorithm. */
      80           0 : class BiffDecoder_XOR : public BiffDecoderBase
      81             : {
      82             : private:
      83             :     /** Copy constructor for cloning. */
      84             :                         BiffDecoder_XOR( const BiffDecoder_XOR& rDecoder );
      85             : 
      86             :     /** Returns a clone of the decoder for usage in new streams. */
      87             :     virtual BiffDecoder_XOR* implClone() SAL_OVERRIDE;
      88             : 
      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;
      92             : 
      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;
      99             : 
     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;
     105             : };
     106             : 
     107             : /** Decodes BIFF stream contents that are encoded using the RC4 algorithm. */
     108           0 : class BiffDecoder_RCF : public BiffDecoderBase
     109             : {
     110             : private:
     111             :     /** Copy constructor for cloning. */
     112             :                         BiffDecoder_RCF( const BiffDecoder_RCF& rDecoder );
     113             : 
     114             :     /** Returns a clone of the decoder for usage in new streams. */
     115             :     virtual BiffDecoder_RCF* implClone() SAL_OVERRIDE;
     116             : 
     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;
     120             : 
     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;
     127             : 
     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;
     134             : };
     135             : 
     136             : /** Helper for BIFF stream codecs. Holds the used codec object. */
     137           0 : class BiffCodecHelper : public WorkbookHelper
     138             : {
     139             : public:
     140             :     explicit            BiffCodecHelper( const WorkbookHelper& rHelper );
     141             : 
     142             :     /** Clones the contained decoder object if existing and sets it at the passed stream. */
     143             :     void                cloneDecoder( BiffInputStream& rStrm );
     144             : 
     145             : private:
     146             :     BiffDecoderRef      mxDecoder;          /// The decoder for import filter.
     147             : };
     148             : 
     149             : } // namespace xls
     150             : } // namespace oox
     151             : 
     152             : #endif
     153             : 
     154             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11