1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #ifndef INCLUDED_SC_INC_TABPROTECTION_HXX
21 #define INCLUDED_SC_INC_TABPROTECTION_HXX
23 #include <sal/types.h>
24 #include <com/sun/star/uno/Sequence.hxx>
27 #include "rangelst.hxx"
28 #include <boost/scoped_ptr.hpp>
31 class ScTableProtectionImpl
;
40 namespace ScPassHashHelper
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
46 bool needsPassHashRegen(const ScDocument
& rDoc
, ScPasswordHash eHash1
, ScPasswordHash eHash2
= PASSHASH_UNSPECIFIED
);
48 OUString
getHashURI(ScPasswordHash eHash
);
50 ScPasswordHash
getHashTypeFromURI(const OUString
& rURI
);
53 class SAL_NO_VTABLE ScPassHashProtectable
56 virtual ~ScPassHashProtectable() = 0;
58 virtual bool isProtected() const = 0;
59 virtual bool isProtectedWithPass() const = 0;
60 virtual void setProtected(bool bProtected
) = 0;
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;
73 class SC_DLLPUBLIC ScDocProtection
: public ScPassHashProtectable
81 NONE
///< last item - used to resize the vector
84 explicit ScDocProtection();
85 explicit ScDocProtection(const ScDocProtection
& r
);
86 virtual ~ScDocProtection();
88 virtual bool isProtected() const SAL_OVERRIDE
;
89 virtual bool isProtectedWithPass() const SAL_OVERRIDE
;
90 virtual void setProtected(bool bProtected
) SAL_OVERRIDE
;
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
;
102 bool isOptionEnabled(Option eOption
) const;
103 void setOption(Option eOption
, bool bEnabled
);
106 ::boost::scoped_ptr
<ScTableProtectionImpl
> mpImpl
;
109 /** Container for the Excel EnhancedProtection feature.
111 struct ScEnhancedProtection
113 ScRangeListRef maRangeList
;
114 sal_uInt32 mnAreserved
;
115 sal_uInt32 mnPasswordVerifier
;
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
;
125 ScEnhancedProtection() : mnAreserved(0), mnPasswordVerifier(0), mnSpinCount(0) {}
127 bool hasSecurityDescriptor() const
129 return !maSecurityDescriptor
.empty() || !maSecurityDescriptorXML
.isEmpty();
132 bool hasPassword() const
134 return mnPasswordVerifier
!= 0 || !maHashValue
.isEmpty();
138 /** sheet protection state container
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
146 class SC_DLLPUBLIC ScTableProtection
: public ScPassHashProtectable
164 SELECT_UNLOCKED_CELLS
,
167 NONE
///< last item - used to resize the vector
170 explicit ScTableProtection();
171 explicit ScTableProtection(const ScTableProtection
& r
);
172 virtual ~ScTableProtection();
174 virtual bool isProtected() const SAL_OVERRIDE
;
175 virtual bool isProtectedWithPass() const SAL_OVERRIDE
;
176 virtual void setProtected(bool bProtected
) SAL_OVERRIDE
;
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
;
188 bool isOptionEnabled(Option eOption
) const;
189 void setOption(Option eOption
, bool bEnabled
);
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;
198 ::boost::scoped_ptr
<ScTableProtectionImpl
> mpImpl
;
203 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */