LCOV - code coverage report
Current view: top level - sc/source/filter/inc - biffcodec.hxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 5 0.0 %
Date: 2014-04-14 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             : 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             : 
      94             :     /** Implementation of decryption of a memory block. */
      95             :     virtual void        implDecode(
      96             :                             sal_uInt8* pnDestData,
      97             :                             const sal_uInt8* pnSrcData,
      98             :                             sal_Int64 nStreamPos,
      99             :                             sal_uInt16 nBytes ) SAL_OVERRIDE;
     100             : 
     101             : private:
     102             :     ::oox::core::BinaryCodec_XOR maCodec;   /// Cipher algorithm implementation.
     103             :     ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue > maEncryptionData;
     104             :     sal_uInt16          mnKey;
     105             :     sal_uInt16          mnHash;
     106             : };
     107             : 
     108             : /** Decodes BIFF stream contents that are encoded using the RC4 algorithm. */
     109           0 : class BiffDecoder_RCF : public BiffDecoderBase
     110             : {
     111             : private:
     112             :     /** Copy constructor for cloning. */
     113             :                         BiffDecoder_RCF( const BiffDecoder_RCF& rDecoder );
     114             : 
     115             :     /** Returns a clone of the decoder for usage in new streams. */
     116             :     virtual BiffDecoder_RCF* implClone() SAL_OVERRIDE;
     117             : 
     118             :     /** Implements password verification and initialization of the decoder. */
     119             :     virtual ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue > implVerifyPassword( const OUString& rPassword ) SAL_OVERRIDE;
     120             :     virtual bool implVerifyEncryptionData( const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue >& rEncryptionData ) SAL_OVERRIDE;
     121             : 
     122             :     /** Implementation of decryption of a memory block. */
     123             :     virtual void        implDecode(
     124             :                             sal_uInt8* pnDestData,
     125             :                             const sal_uInt8* pnSrcData,
     126             :                             sal_Int64 nStreamPos,
     127             :                             sal_uInt16 nBytes ) SAL_OVERRIDE;
     128             : 
     129             : private:
     130             :     ::oox::core::BinaryCodec_RCF maCodec;   /// Cipher algorithm implementation.
     131             :     ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue > maEncryptionData;
     132             :     ::std::vector< sal_uInt8 > maSalt;
     133             :     ::std::vector< sal_uInt8 > maVerifier;
     134             :     ::std::vector< sal_uInt8 > maVerifierHash;
     135             : };
     136             : 
     137             : /** Helper for BIFF stream codecs. Holds the used codec object. */
     138           0 : class BiffCodecHelper : public WorkbookHelper
     139             : {
     140             : public:
     141             :     explicit            BiffCodecHelper( const WorkbookHelper& rHelper );
     142             : 
     143             :     /** Clones the contained decoder object if existing and sets it at the passed stream. */
     144             :     void                cloneDecoder( BiffInputStream& rStrm );
     145             : 
     146             : private:
     147             :     BiffDecoderRef      mxDecoder;          /// The decoder for import filter.
     148             : };
     149             : 
     150             : } // namespace xls
     151             : } // namespace oox
     152             : 
     153             : #endif
     154             : 
     155             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10