Skip to content

Commit 78d1370

Browse files
v3 - require PHP 7, use strict types
1 parent 347f7bf commit 78d1370

File tree

4 files changed

+24
-15
lines changed

4 files changed

+24
-15
lines changed

CHANGELOG.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
1-
# Version 2.0.0 (not released yet)
1+
# Version 3.0.0 (2016-05-18)
22

3-
* Update `defuse/php-encryption` to `2.0.0` (not released yet either)
3+
* Set minimum PHP version to 7.0
4+
* Use strict_types
5+
6+
# Version 2.0.0 (2016-05-18)
7+
8+
* Update `defuse/php-encryption` to `2.0.0`
9+
* Use `paragonie/constant_time_encoding`
410

511
# Version 1.1.0
612

composer.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,11 @@
2828
]
2929
},
3030
"require": {
31+
"php": ">= 7.0",
3132
"defuse/php-encryption": "^2.0",
32-
"paragonie/random_compat": "^1|^2",
33-
"paragonie/constant_time_encoding": "^1|^2"
33+
"paragonie/constant_time_encoding": "^2"
3434
},
3535
"require-dev": {
36-
"defuse/php-encryption": "^2.0"
36+
"phpunit/phpunit": "^5|^6"
3737
}
3838
}

src/PasswordLock.php

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
declare(strict_types=1);
23
namespace ParagonIE\PasswordLock;
34

45
use \Defuse\Crypto\Crypto;
@@ -17,7 +18,7 @@ class PasswordLock
1718
* @return string
1819
* @throws \Exception
1920
*/
20-
public static function hashAndEncrypt($password, Key $aesKey)
21+
public static function hashAndEncrypt(string $password, Key $aesKey): string
2122
{
2223
if (!\is_string($password)) {
2324
throw new \InvalidArgumentException(
@@ -46,7 +47,7 @@ public static function hashAndEncrypt($password, Key $aesKey)
4647
* @throws \Exception
4748
* @throws \InvalidArgumentException
4849
*/
49-
public static function decryptAndVerifyLegacy($password, $ciphertext, $aesKey)
50+
public static function decryptAndVerifyLegacy(string $password, string $ciphertext, string $aesKey): bool
5051
{
5152
if (!\is_string($password)) {
5253
throw new \InvalidArgumentException(
@@ -79,7 +80,7 @@ public static function decryptAndVerifyLegacy($password, $ciphertext, $aesKey)
7980
* @throws \Exception
8081
* @throws \InvalidArgumentException
8182
*/
82-
public static function decryptAndVerify($password, $ciphertext, Key $aesKey)
83+
public static function decryptAndVerify(string $password, string $ciphertext, Key $aesKey): bool
8384
{
8485
if (!\is_string($password)) {
8586
throw new \InvalidArgumentException(
@@ -111,7 +112,7 @@ public static function decryptAndVerify($password, $ciphertext, Key $aesKey)
111112
* @param Key $newKey
112113
* @return string
113114
*/
114-
public static function rotateKey($ciphertext, Key $oldKey, Key $newKey)
115+
public static function rotateKey(string $ciphertext, Key $oldKey, Key $newKey): string
115116
{
116117
$plaintext = Crypto::decrypt($ciphertext, $oldKey);
117118
return Crypto::encrypt($plaintext, $newKey);
@@ -128,11 +129,11 @@ public static function rotateKey($ciphertext, Key $oldKey, Key $newKey)
128129
* @throws \Exception
129130
*/
130131
public static function upgradeFromVersion1(
131-
$password,
132-
$ciphertext,
133-
$oldKey,
132+
string $password,
133+
string $ciphertext,
134+
string $oldKey,
134135
Key $newKey
135-
) {
136+
): string {
136137
if (!self::decryptAndVerifyLegacy($password, $ciphertext, $oldKey)) {
137138
throw new \Exception(
138139
'The correct password is necessary for legacy migration.'

tests/PasswordLockTest.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
2+
declare(strict_types=1);
23
use \ParagonIE\PasswordLock\PasswordLock;
4+
use \Defuse\Crypto\Key;
35
/**
46
* @backupGlobals disabled
57
* @backupStaticAttributes disabled
@@ -8,7 +10,7 @@ class PasswordLockTest extends PHPUnit_Framework_TestCase
810
{
911
public function testHash()
1012
{
11-
$key = \Defuse\Crypto\Key::createNewRandomKey();
13+
$key = Key::createNewRandomKey();
1214

1315
$password = PasswordLock::hashAndEncrypt('YELLOW SUBMARINE', $key);
1416

@@ -26,7 +28,7 @@ public function testHash()
2628
*/
2729
public function testBitflip()
2830
{
29-
$key = \Defuse\Crypto\Key::createNewRandomKey();
31+
$key = Key::createNewRandomKey();
3032
$password = PasswordLock::hashAndEncrypt('YELLOW SUBMARINE', $key);
3133
$password[0] = (\ord($password[0]) === 0 ? 255 : 0);
3234

0 commit comments

Comments
 (0)