LCOV - code coverage report
Current view: top level - sc/inc - tabprotection.hxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 7 7 100.0 %
Date: 2015-06-13 12:38:46 Functions: 6 7 85.7 %
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_INC_TABPROTECTION_HXX
      21             : #define INCLUDED_SC_INC_TABPROTECTION_HXX
      22             : 
      23             : #include <sal/types.h>
      24             : #include <com/sun/star/uno/Sequence.hxx>
      25             : 
      26             : #include "global.hxx"
      27             : #include "rangelst.hxx"
      28             : #include <boost/scoped_ptr.hpp>
      29             : 
      30             : class ScDocument;
      31             : class ScTableProtectionImpl;
      32             : 
      33             : enum ScPasswordHash
      34             : {
      35             :     PASSHASH_SHA1 = 0,
      36             :     PASSHASH_XL,
      37             :     PASSHASH_UNSPECIFIED
      38             : };
      39             : 
      40             : namespace ScPassHashHelper
      41             : {
      42             :     /** Check for the compatibility of all password hashes.  If there is at
      43             :      * least one hash that needs to be regenerated, it returns true.  If all
      44             :      * hash values are compatible with the specified hash type, then it
      45             :      * returns false. */
      46             :     bool needsPassHashRegen(const ScDocument& rDoc, ScPasswordHash eHash1, ScPasswordHash eHash2 = PASSHASH_UNSPECIFIED);
      47             : 
      48             :     OUString getHashURI(ScPasswordHash eHash);
      49             : 
      50             :     ScPasswordHash getHashTypeFromURI(const OUString& rURI);
      51             : }
      52             : 
      53          43 : class SAL_NO_VTABLE ScPassHashProtectable
      54             : {
      55             : public:
      56             :     virtual ~ScPassHashProtectable() = 0;
      57             : 
      58             :     virtual bool isProtected() const = 0;
      59             :     virtual bool isProtectedWithPass() const = 0;
      60             :     virtual void setProtected(bool bProtected) = 0;
      61             : 
      62             :     virtual bool isPasswordEmpty() const = 0;
      63             :     virtual bool hasPasswordHash(ScPasswordHash eHash, ScPasswordHash eHash2 = PASSHASH_UNSPECIFIED) const = 0;
      64             :     virtual void setPassword(const OUString& aPassText) = 0;
      65             :     virtual ::com::sun::star::uno::Sequence<sal_Int8> getPasswordHash(
      66             :         ScPasswordHash eHash, ScPasswordHash eHas2 = PASSHASH_UNSPECIFIED) const = 0;
      67             :     virtual void setPasswordHash(
      68             :         const ::com::sun::star::uno::Sequence<sal_Int8>& aPassword,
      69             :         ScPasswordHash eHash = PASSHASH_SHA1, ScPasswordHash eHash2 = PASSHASH_UNSPECIFIED) = 0;
      70             :     virtual bool verifyPassword(const OUString& aPassText) const = 0;
      71             : };
      72             : 
      73             : class SC_DLLPUBLIC ScDocProtection : public ScPassHashProtectable
      74             : {
      75             : public:
      76             :     enum Option
      77             :     {
      78             :         STRUCTURE = 0,
      79             :         WINDOWS,
      80             :         CONTENT,
      81             :         NONE        ///< last item - used to resize the vector
      82             :     };
      83             : 
      84             :     explicit ScDocProtection();
      85             :     explicit ScDocProtection(const ScDocProtection& r);
      86             :     virtual ~ScDocProtection();
      87             : 
      88             :     virtual bool isProtected() const SAL_OVERRIDE;
      89             :     virtual bool isProtectedWithPass() const SAL_OVERRIDE;
      90             :     virtual void setProtected(bool bProtected) SAL_OVERRIDE;
      91             : 
      92             :     virtual bool isPasswordEmpty() const SAL_OVERRIDE;
      93             :     virtual bool hasPasswordHash(ScPasswordHash eHash, ScPasswordHash eHash2 = PASSHASH_UNSPECIFIED) const SAL_OVERRIDE;
      94             :     virtual void setPassword(const OUString& aPassText) SAL_OVERRIDE;
      95             :     virtual ::com::sun::star::uno::Sequence<sal_Int8> getPasswordHash(
      96             :         ScPasswordHash eHash, ScPasswordHash eHash2 = PASSHASH_UNSPECIFIED) const SAL_OVERRIDE;
      97             :     virtual void setPasswordHash(
      98             :         const ::com::sun::star::uno::Sequence<sal_Int8>& aPassword,
      99             :         ScPasswordHash eHash = PASSHASH_SHA1, ScPasswordHash eHash2 = PASSHASH_UNSPECIFIED) SAL_OVERRIDE;
     100             :     virtual bool verifyPassword(const OUString& aPassText) const SAL_OVERRIDE;
     101             : 
     102             :     bool isOptionEnabled(Option eOption) const;
     103             :     void setOption(Option eOption, bool bEnabled);
     104             : 
     105             : private:
     106             :     ::boost::scoped_ptr<ScTableProtectionImpl> mpImpl;
     107             : };
     108             : 
     109             : /** Container for the Excel EnhancedProtection feature.
     110             :  */
     111          98 : struct ScEnhancedProtection
     112             : {
     113             :     ScRangeListRef              maRangeList;
     114             :     sal_uInt32                  mnAreserved;
     115             :     sal_uInt32                  mnPasswordVerifier;
     116             :     OUString                    maTitle;
     117             :     ::std::vector< sal_uInt8 >  maSecurityDescriptor;       // imported as raw BIFF data
     118             :     OUString                    maSecurityDescriptorXML;    // imported from OOXML
     119             :     // OOXML password definitions
     120             :     OUString                    maAlgorithmName;
     121             :     OUString                    maHashValue;
     122             :     OUString                    maSaltValue;
     123             :     sal_uInt32                  mnSpinCount;
     124             : 
     125          10 :     ScEnhancedProtection() : mnAreserved(0), mnPasswordVerifier(0), mnSpinCount(0) {}
     126             : 
     127         144 :     bool hasSecurityDescriptor() const
     128             :     {
     129         144 :         return !maSecurityDescriptor.empty() || !maSecurityDescriptorXML.isEmpty();
     130             :     }
     131             : 
     132          24 :     bool hasPassword() const
     133             :     {
     134          24 :         return mnPasswordVerifier != 0 || !maHashValue.isEmpty();
     135             :     }
     136             : };
     137             : 
     138             : /** sheet protection state container
     139             :  *
     140             :  * This class stores sheet's protection state: 1) whether the protection
     141             :  * is on, 2) password and/or password hash, and 3) any associated
     142             :  * protection options.  This class is also used as a protection state
     143             :  * container for the undo/redo stack, in which case the password, hash and
     144             :  * the options need to be preserved even when the protection flag is
     145             :  * off. */
     146             : class SC_DLLPUBLIC ScTableProtection : public ScPassHashProtectable
     147             : {
     148             : public:
     149             :     enum Option
     150             :     {
     151             :         AUTOFILTER = 0,
     152             :         DELETE_COLUMNS,
     153             :         DELETE_ROWS,
     154             :         FORMAT_CELLS,
     155             :         FORMAT_COLUMNS,
     156             :         FORMAT_ROWS,
     157             :         INSERT_COLUMNS,
     158             :         INSERT_HYPERLINKS,
     159             :         INSERT_ROWS,
     160             :         OBJECTS,
     161             :         PIVOT_TABLES,
     162             :         SCENARIOS,
     163             :         SELECT_LOCKED_CELLS,
     164             :         SELECT_UNLOCKED_CELLS,
     165             :         SHEET,
     166             :         SORT,
     167             :         NONE        ///< last item - used to resize the vector
     168             :     };
     169             : 
     170             :     explicit ScTableProtection();
     171             :     explicit ScTableProtection(const ScTableProtection& r);
     172             :     virtual ~ScTableProtection();
     173             : 
     174             :     virtual bool isProtected() const SAL_OVERRIDE;
     175             :     virtual bool isProtectedWithPass() const SAL_OVERRIDE;
     176             :     virtual void setProtected(bool bProtected) SAL_OVERRIDE;
     177             : 
     178             :     virtual bool isPasswordEmpty() const SAL_OVERRIDE;
     179             :     virtual bool hasPasswordHash(ScPasswordHash eHash, ScPasswordHash eHash2 = PASSHASH_UNSPECIFIED) const SAL_OVERRIDE;
     180             :     virtual void setPassword(const OUString& aPassText) SAL_OVERRIDE;
     181             :     virtual ::com::sun::star::uno::Sequence<sal_Int8> getPasswordHash(
     182             :         ScPasswordHash eHash, ScPasswordHash eHash2 = PASSHASH_UNSPECIFIED) const SAL_OVERRIDE;
     183             :     virtual void setPasswordHash(
     184             :         const ::com::sun::star::uno::Sequence<sal_Int8>& aPassword,
     185             :         ScPasswordHash eHash = PASSHASH_SHA1, ScPasswordHash eHash2 = PASSHASH_UNSPECIFIED) SAL_OVERRIDE;
     186             :     virtual bool verifyPassword(const OUString& aPassText) const SAL_OVERRIDE;
     187             : 
     188             :     bool isOptionEnabled(Option eOption) const;
     189             :     void setOption(Option eOption, bool bEnabled);
     190             : 
     191             :     void setEnhancedProtection( const ::std::vector< ScEnhancedProtection > & rProt );
     192             :     const ::std::vector< ScEnhancedProtection > & getEnhancedProtection() const;
     193             :     bool updateReference( UpdateRefMode, ScDocument*, const ScRange& rWhere, SCsCOL nDx, SCsROW nDy, SCsTAB nDz );
     194             :     bool isBlockEditable( const ScRange& rRange ) const;
     195             :     bool isSelectionEditable( const ScRangeList& rRangeList ) const;
     196             : 
     197             : private:
     198             :     ::boost::scoped_ptr<ScTableProtectionImpl> mpImpl;
     199             : };
     200             : 
     201             : #endif
     202             : 
     203             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11