LibreOffice Module sc (master)  1
tabprotection.hxx
Go to the documentation of this file.
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 
25 #include "global.hxx"
26 #include "rangelst.hxx"
27 #include <memory>
28 
29 class ScDocument;
31 
33 {
35  PASSHASH_SHA1_UTF8, // tdf#115483 this is UTF8, previous one is wrong UTF16
39 };
40 
43 {
44  OUString maAlgorithmName;
45  OUString maHashValue;
46  OUString maSaltValue;
47  sal_uInt32 mnSpinCount;
48 
49  ScOoxPasswordHash() : mnSpinCount(0) {}
50  bool hasPassword() const { return !maHashValue.isEmpty(); }
51  void clear()
52  {
53  // Keep algorithm and spin count.
54  maHashValue.clear();
55  maSaltValue.clear();
56  }
57  bool verifyPassword( const OUString& aPassText ) const;
58 };
59 
61 {
67 
68  OUString getHashURI(ScPasswordHash eHash);
69 
70  ScPasswordHash getHashTypeFromURI(const OUString& rURI);
71 }
72 
74 {
75 public:
76  virtual ~ScPassHashProtectable() = 0;
77 
78  virtual bool isProtected() const = 0;
79  virtual bool isProtectedWithPass() const = 0;
80  virtual void setProtected(bool bProtected) = 0;
81 
82  virtual bool isPasswordEmpty() const = 0;
83  virtual bool hasPasswordHash(ScPasswordHash eHash, ScPasswordHash eHash2 = PASSHASH_UNSPECIFIED) const = 0;
84  virtual void setPassword(const OUString& aPassText) = 0;
85  virtual css::uno::Sequence<sal_Int8> getPasswordHash(
86  ScPasswordHash eHash, ScPasswordHash eHas2 = PASSHASH_UNSPECIFIED) const = 0;
87  virtual const ScOoxPasswordHash& getPasswordHash() const = 0;
88  virtual void setPasswordHash(
89  const css::uno::Sequence<sal_Int8>& aPassword,
91  virtual void setPasswordHash( const OUString& rAlgorithmName, const OUString& rHashValue,
92  const OUString& rSaltValue, sal_uInt32 nSpinCount ) = 0;
93  virtual bool verifyPassword(const OUString& aPassText) const = 0;
94 };
95 
97 {
98 public:
99  enum Option
100  {
101  STRUCTURE = 0,
104  };
105 
106  explicit ScDocProtection();
107  explicit ScDocProtection(const ScDocProtection& r);
108  virtual ~ScDocProtection() override;
109 
110  virtual bool isProtected() const override;
111  virtual bool isProtectedWithPass() const override;
112  virtual void setProtected(bool bProtected) override;
113 
114  virtual bool isPasswordEmpty() const override;
115  virtual bool hasPasswordHash(ScPasswordHash eHash, ScPasswordHash eHash2 = PASSHASH_UNSPECIFIED) const override;
116  virtual void setPassword(const OUString& aPassText) override;
117  virtual css::uno::Sequence<sal_Int8> getPasswordHash(
118  ScPasswordHash eHash, ScPasswordHash eHash2 = PASSHASH_UNSPECIFIED) const override;
119  virtual const ScOoxPasswordHash& getPasswordHash() const override;
120  virtual void setPasswordHash(
121  const css::uno::Sequence<sal_Int8>& aPassword,
122  ScPasswordHash eHash, ScPasswordHash eHash2 = PASSHASH_UNSPECIFIED) override;
123  virtual void setPasswordHash( const OUString& rAlgorithmName, const OUString& rHashValue,
124  const OUString& rSaltValue, sal_uInt32 nSpinCount ) override;
125  virtual bool verifyPassword(const OUString& aPassText) const override;
126 
127  bool isOptionEnabled(Option eOption) const;
128  void setOption(Option eOption, bool bEnabled);
129 
130 private:
131  std::unique_ptr<ScTableProtectionImpl> mpImpl;
132 };
133 
137 {
139  sal_uInt32 mnAreserved;
140  sal_uInt32 mnPasswordVerifier;
141  OUString maTitle;
142  ::std::vector< sal_uInt8 > maSecurityDescriptor; // imported as raw BIFF data
143  OUString maSecurityDescriptorXML; // imported from OOXML
145 
146  ScEnhancedProtection() : mnAreserved(0), mnPasswordVerifier(0) {}
147 
149  {
150  return !maSecurityDescriptor.empty() || !maSecurityDescriptorXML.isEmpty();
151  }
152 
153  bool hasPassword() const
154  {
155  return mnPasswordVerifier != 0 || maPasswordHash.hasPassword();
156  }
157 };
158 
168 {
169 public:
170  enum Option
171  {
172  AUTOFILTER = 0,
188  };
189 
190  explicit ScTableProtection();
191  explicit ScTableProtection(const ScTableProtection& r);
192  virtual ~ScTableProtection() override;
193 
194  virtual bool isProtected() const override;
195  virtual bool isProtectedWithPass() const override;
196  virtual void setProtected(bool bProtected) override;
197 
198  virtual bool isPasswordEmpty() const override;
199  virtual bool hasPasswordHash(ScPasswordHash eHash, ScPasswordHash eHash2 = PASSHASH_UNSPECIFIED) const override;
200  virtual void setPassword(const OUString& aPassText) override;
201  virtual css::uno::Sequence<sal_Int8> getPasswordHash(
202  ScPasswordHash eHash, ScPasswordHash eHash2 = PASSHASH_UNSPECIFIED) const override;
203  virtual const ScOoxPasswordHash& getPasswordHash() const override;
204  virtual void setPasswordHash(
205  const css::uno::Sequence<sal_Int8>& aPassword,
206  ScPasswordHash eHash, ScPasswordHash eHash2 = PASSHASH_UNSPECIFIED) override;
207  virtual void setPasswordHash( const OUString& rAlgorithmName, const OUString& rHashValue,
208  const OUString& rSaltValue, sal_uInt32 nSpinCount ) override;
209  virtual bool verifyPassword(const OUString& aPassText) const override;
210 
211  bool isOptionEnabled(Option eOption) const;
212  void setOption(Option eOption, bool bEnabled);
213 
214  void setEnhancedProtection( const ::std::vector< ScEnhancedProtection > & rProt );
215  const ::std::vector< ScEnhancedProtection > & getEnhancedProtection() const;
216  bool updateReference( UpdateRefMode, const ScDocument&, const ScRange& rWhere, SCCOL nDx, SCROW nDy, SCTAB nDz );
217  bool isBlockEditable( const ScRange& rRange ) const;
218  bool isSelectionEditable( const ScRangeList& rRangeList ) const;
219 
220 private:
221  std::unique_ptr<ScTableProtectionImpl> mpImpl;
222 };
223 
224 #endif
225 
226 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual bool isPasswordEmpty() const =0
bool verifyPassword(const OUString &aPassText) const
ScRangeListRef maRangeList
ScOoxPasswordHash()
spin count, iteration runs
virtual bool isProtected() const =0
sheet protection state container
virtual bool isProtectedWithPass() const =0
OUString maSaltValue
base64 encoded hash value
OOX_DLLPUBLIC sal_uInt16 getPasswordHash(const AttributeList &rAttribs, sal_Int32 nElement)
OUString maHashValue
"SHA-512", ...
NONE
virtual const ScOoxPasswordHash & getPasswordHash() const =0
OUString maAlgorithmName
bool hasSecurityDescriptor() const
OOXML password definitions: algorithmName, hashValue, saltValue, spinCount.
ScPasswordHash
OUString maSecurityDescriptorXML
ScPasswordHash getHashTypeFromURI(const OUString &rURI)
virtual void setProtected(bool bProtected)=0
SQLUSMALLINT Option
virtual bool verifyPassword(const OUString &aPassText) const =0
OUString getHashURI(ScPasswordHash eHash)
std::unique_ptr< ScTableProtectionImpl > mpImpl
sal_Int16 SCCOL
Definition: types.hxx:22
bool hasPassword() const
Container for the Excel EnhancedProtection feature.
UpdateRefMode
Definition: global.hxx:311
sal_Int32 SCROW
Definition: types.hxx:18
std::unique_ptr< ScTableProtectionImpl > mpImpl
virtual void setPasswordHash(const css::uno::Sequence< sal_Int8 > &aPassword, ScPasswordHash eHash, ScPasswordHash eHash2=PASSHASH_UNSPECIFIED)=0
virtual bool hasPasswordHash(ScPasswordHash eHash, ScPasswordHash eHash2=PASSHASH_UNSPECIFIED) const =0
sal_uInt32 mnPasswordVerifier
bool hasPassword() const
::std::vector< sal_uInt8 > maSecurityDescriptor
virtual void setPassword(const OUString &aPassText)=0
bool needsPassHashRegen(const ScDocument &rDoc, ScPasswordHash eHash1, ScPasswordHash eHash2=PASSHASH_UNSPECIFIED)
Check for the compatibility of all password hashes.
#define SAL_NO_VTABLE
ScOoxPasswordHash maPasswordHash
sal_uInt32 mnSpinCount
base64 encoded salt value
#define SC_DLLPUBLIC
Definition: scdllapi.h:28
sal_Int16 SCTAB
Definition: types.hxx:23