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