Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
20 / 20 |
|
100.00% |
11 / 11 |
CRAP | |
100.00% |
1 / 1 |
Protection | |
100.00% |
20 / 20 |
|
100.00% |
11 / 11 |
14 | |
100.00% |
1 / 1 |
__construct | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
2 | |||
getEditing | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
setEditing | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
getPassword | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
setPassword | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
getSpinCount | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
setSpinCount | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
getAlgorithm | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
setAlgorithm | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
getSalt | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
setSalt | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
3 |
1 | <?php |
2 | /** |
3 | * This file is part of PHPWord - A pure PHP library for reading and writing |
4 | * word processing documents. |
5 | * |
6 | * PHPWord is free software distributed under the terms of the GNU Lesser |
7 | * General Public License version 3 as published by the Free Software Foundation. |
8 | * |
9 | * For the full copyright and license information, please read the LICENSE |
10 | * file that was distributed with this source code. For the full list of |
11 | * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. |
12 | * |
13 | * @see https://github.com/PHPOffice/PHPWord |
14 | * |
15 | * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 |
16 | */ |
17 | |
18 | namespace PhpOffice\PhpWord\Metadata; |
19 | |
20 | use InvalidArgumentException; |
21 | use PhpOffice\PhpWord\Shared\Microsoft\PasswordEncoder; |
22 | use PhpOffice\PhpWord\SimpleType\DocProtect; |
23 | |
24 | /** |
25 | * Document protection class. |
26 | * |
27 | * @since 0.12.0 |
28 | * @see http://www.datypic.com/sc/ooxml/t-w_CT_DocProtect.html |
29 | */ |
30 | class Protection |
31 | { |
32 | /** |
33 | * Editing restriction none|readOnly|comments|trackedChanges|forms. |
34 | * |
35 | * @var string |
36 | * |
37 | * @see http://www.datypic.com/sc/ooxml/a-w_edit-1.html |
38 | */ |
39 | private $editing; |
40 | |
41 | /** |
42 | * password. |
43 | * |
44 | * @var string |
45 | */ |
46 | private $password; |
47 | |
48 | /** |
49 | * Iterations to Run Hashing Algorithm. |
50 | * |
51 | * @var int |
52 | */ |
53 | private $spinCount = 100000; |
54 | |
55 | /** |
56 | * Cryptographic Hashing Algorithm (see constants defined in \PhpOffice\PhpWord\Shared\Microsoft\PasswordEncoder). |
57 | * |
58 | * @var string |
59 | */ |
60 | private $algorithm = PasswordEncoder::ALGORITHM_SHA_1; |
61 | |
62 | /** |
63 | * Salt for Password Verifier. |
64 | * |
65 | * @var string |
66 | */ |
67 | private $salt; |
68 | |
69 | /** |
70 | * Create a new instance. |
71 | * |
72 | * @param string $editing |
73 | */ |
74 | public function __construct($editing = null) |
75 | { |
76 | if ($editing != null) { |
77 | $this->setEditing($editing); |
78 | } |
79 | } |
80 | |
81 | /** |
82 | * Get editing protection. |
83 | * |
84 | * @return string |
85 | */ |
86 | public function getEditing() |
87 | { |
88 | return $this->editing; |
89 | } |
90 | |
91 | /** |
92 | * Set editing protection. |
93 | * |
94 | * @param string $editing Any value of \PhpOffice\PhpWord\SimpleType\DocProtect |
95 | * |
96 | * @return self |
97 | */ |
98 | public function setEditing($editing = null) |
99 | { |
100 | DocProtect::validate($editing); |
101 | $this->editing = $editing; |
102 | |
103 | return $this; |
104 | } |
105 | |
106 | /** |
107 | * Get password. |
108 | * |
109 | * @return string |
110 | */ |
111 | public function getPassword() |
112 | { |
113 | return $this->password; |
114 | } |
115 | |
116 | /** |
117 | * Set password. |
118 | * |
119 | * @param string $password |
120 | * |
121 | * @return self |
122 | */ |
123 | public function setPassword($password) |
124 | { |
125 | $this->password = $password; |
126 | |
127 | return $this; |
128 | } |
129 | |
130 | /** |
131 | * Get count for hash iterations. |
132 | * |
133 | * @return int |
134 | */ |
135 | public function getSpinCount() |
136 | { |
137 | return $this->spinCount; |
138 | } |
139 | |
140 | /** |
141 | * Set count for hash iterations. |
142 | * |
143 | * @param int $spinCount |
144 | * |
145 | * @return self |
146 | */ |
147 | public function setSpinCount($spinCount) |
148 | { |
149 | $this->spinCount = $spinCount; |
150 | |
151 | return $this; |
152 | } |
153 | |
154 | /** |
155 | * Get algorithm. |
156 | * |
157 | * @return string |
158 | */ |
159 | public function getAlgorithm() |
160 | { |
161 | return $this->algorithm; |
162 | } |
163 | |
164 | /** |
165 | * Set algorithm. |
166 | * |
167 | * @param string $algorithm |
168 | * |
169 | * @return self |
170 | */ |
171 | public function setAlgorithm($algorithm) |
172 | { |
173 | $this->algorithm = $algorithm; |
174 | |
175 | return $this; |
176 | } |
177 | |
178 | /** |
179 | * Get salt. |
180 | * |
181 | * @return string |
182 | */ |
183 | public function getSalt() |
184 | { |
185 | return $this->salt; |
186 | } |
187 | |
188 | /** |
189 | * Set salt. Salt HAS to be 16 characters, or an exception will be thrown. |
190 | * |
191 | * @param string $salt |
192 | * |
193 | * @return self |
194 | */ |
195 | public function setSalt($salt) |
196 | { |
197 | if ($salt !== null && strlen($salt) !== 16) { |
198 | throw new InvalidArgumentException('salt has to be of exactly 16 bytes length'); |
199 | } |
200 | |
201 | $this->salt = $salt; |
202 | |
203 | return $this; |
204 | } |
205 | } |