Skip to content

Commit 90551b1

Browse files
committed
Scrutinizer fixes
1 parent 3deecee commit 90551b1

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

src/Common/Microsoft/PasswordEncoder.php

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,9 @@ class PasswordEncoder
8282
* @see https://blogs.msdn.microsoft.com/vsod/2010/04/05/how-to-set-the-editing-restrictions-in-word-using-open-xml-sdk-2-0/
8383
*
8484
* @param string $password
85-
* @param number $algorithmSid
85+
* @param integer $algorithmSid
8686
* @param string $salt
87-
* @param number $spinCount
87+
* @param integer $spinCount
8888
* @return string
8989
*/
9090
public static function hashPassword($password, $algorithmSid = 4, $salt = null, $spinCount = 10000)
@@ -155,16 +155,17 @@ private static function getAlgorithm($sid)
155155
*/
156156
private static function buildCombinedKey($byteChars)
157157
{
158+
$byteCharsLength = count($byteChars);
158159
// Compute the high-order word
159160
// Initialize from the initial code array (see above), depending on the passwords length.
160-
$highOrderWord = self::$initialCodeArray[count($byteChars) - 1];
161+
$highOrderWord = self::$initialCodeArray[$byteCharsLength - 1];
161162

162163
// For each character in the password:
163164
// For every bit in the character, starting with the least significant and progressing to (but excluding)
164165
// the most significant, if the bit is set, XOR the key’s high-order word with the corresponding word from
165166
// the Encryption Matrix
166-
for ($i = 0; $i < count($byteChars); $i++) {
167-
$tmp = self::$passwordMaxLength - count($byteChars) + $i;
167+
for ($i = 0; $i < $byteCharsLength; $i++) {
168+
$tmp = self::$passwordMaxLength - $byteCharsLength + $i;
168169
$matrixRow = self::$encryptionMatrix[$tmp];
169170
for ($intBit = 0; $intBit < 7; $intBit++) {
170171
if (($byteChars[$i] & (0x0001 << $intBit)) != 0) {
@@ -177,12 +178,12 @@ private static function buildCombinedKey($byteChars)
177178
// Initialize with 0
178179
$lowOrderWord = 0;
179180
// For each character in the password, going backwards
180-
for ($i = count($byteChars) - 1; $i >= 0; $i--) {
181+
for ($i = $byteCharsLength - 1; $i >= 0; $i--) {
181182
// low-order word = (((low-order word SHR 14) AND 0x0001) OR (low-order word SHL 1) AND 0x7FFF)) XOR character
182183
$lowOrderWord = (((($lowOrderWord >> 14) & 0x0001) | (($lowOrderWord << 1) & 0x7FFF)) ^ $byteChars[$i]);
183184
}
184185
// Lastly, low-order word = (((low-order word SHR 14) AND 0x0001) OR (low-order word SHL 1) AND 0x7FFF)) XOR strPassword length XOR 0xCE4B.
185-
$lowOrderWord = (((($lowOrderWord >> 14) & 0x0001) | (($lowOrderWord << 1) & 0x7FFF)) ^ count($byteChars) ^ 0xCE4B);
186+
$lowOrderWord = (((($lowOrderWord >> 14) & 0x0001) | (($lowOrderWord << 1) & 0x7FFF)) ^ $byteCharsLength ^ 0xCE4B);
186187

187188
// Combine the Low and High Order Word
188189
return self::int32(($highOrderWord << 16) + $lowOrderWord);

0 commit comments

Comments
 (0)