8000 Merge branch 'feature/50-import-functions' into develop · zendframework/zend-crypt@79362cc · GitHub
[go: up one dir, main page]

Skip to content
This repository was archived by the owner on Jan 29, 2020. It is now read-only.

Commit 79362cc

Browse files
committed
Merge branch 'feature/50-import-functions' into develop
Forward port #50 Conflicts: CHANGELOG.md
2 parents 40b29b5 + 9b7232f commit 79362cc

22 files changed

+352
-147
lines changed

CHANGELOG.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,32 @@ chronological order by release.
99

1010
- Nothing.
1111

12+
### Changed
13+
14+
- Nothing.
15+
16+
### Deprecated
17+
18+
- Nothing.
19+
20+
### Removed
21+
22+
- Nothing.
23+
24+
### Fixed
25+
26+
- Nothing.
27+
28+
## 3.2.2 - TBD
29+
30+
### Added
31+
32+
- Nothing.
33+
34+
### Changed
35+
36+
- [#50](https://github.com/zendframework/zend-crypt/pull/50) updates all classes to import functions and constants they use.
37+
1238
### Deprecated
1339

1440
- Nothing.

src/BlockCipher.php

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
<?php
22
/**
3-
* Zend Framework (http://framework.zend.com/)
4-
*
5-
* @link http://github.com/zendframework/zf2 for the canonical source repository
6-
* @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com)
7-
* @license http://framework.zend.com/license/new-bsd New BSD License
3+
* @see https://github.com/zendframework/zend-crypt for the canonical source repository
4+
* @copyright Copyright (c) 2005-2018 Zend Technologies USA Inc. (https://www.zend.com)
5+
* @license https://github.com/zendframework/zend-crypt/blob/master/LICENSE.md New BSD License
86
*/
97

108
namespace Zend\Crypt;
@@ -15,6 +13,19 @@
1513
use Zend\Crypt\Symmetric\SymmetricInterface;
1614
use Zend\Math\Rand;
1715

16+
use function base64_decode;
17+
use function base64_encode;
18+
use function class_exists;
19+
use function gettype;
20+
use function get_class;
21+
use function in_array;
22+
use function is_array;
23+
use function is_object;
24+
use function is_string;
25+
use function is_subclass_of;
26+
use function mb_substr;
27+
use function sprintf;
28+
1829
/**
1930
* Encrypt using a symmetric cipher then authenticate using HMAC (SHA-256)
2031
*/
@@ -131,7 +142,7 @@ public static function getSymmetricPluginManager()
131142
public static function setSymmetricPluginManager($plugins)
132143
{
133144
if (is_string($plugins)) {
134-
if (!class_exists($plugins) || ! is_subclass_of($plugins, ContainerInterface::class)) {
145+
if (! class_exists($plugins) || ! is_subclass_of($plugins, ContainerInterface::class)) {
135146
throw new Exception\InvalidArgumentException(sprintf(
136147
'Unable to locate symmetric cipher plugins using class "%s"; '
137148
. 'class does not exist or does not implement ContainerInterface',
@@ -140,10 +151,10 @@ public static function setSymmetricPluginManager($plugins)
140151
}
141152
$plugins = new $plugins();
142153
}
143-
if (!$plugins instanceof ContainerInterface) {
154+
if (! $plugins instanceof ContainerInterface) {
144155
throw new Exception\InvalidArgumentException(sprintf(
145156
'Symmetric plugin must implements Interop\Container\ContainerInterface;; received "%s"',
146-
(is_object($plugins) ? get_class($plugins) : gettype($plugins))
157+
is_object($plugins) ? get_class($plugins) : gettype($plugins)
147158
));
148159
}
149160
static::$symmetricPlugins = $plugins;
@@ -398,7 +409,7 @@ public function encrypt($data)
398409
}
399410

400411
// Cast to string prior to encrypting
401-
if (!is_string($data)) {
412+
if (! is_string($data)) {
402413
$data = (string) $data;
403414
}
404415

@@ -444,7 +455,7 @@ public function encrypt($data)
444455
*/
445456
public function decrypt($data)
446457
{
447-
if (!is_string($data)) {
458+
if (! is_string($data)) {
448459
throw new Exception\InvalidArgumentException('The data to decrypt must be a string');
449460
}
450461
if ('' === $data) {

src/FileCipher.php

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,27 @@
11
<?php
22
/**
3-
* Zend Framework (http://framework.zend.com/)
4-
*
5-
* @link http://github.com/zendframework/zf2 for the canonical source repository
6-
* @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com)
7-
* @license http://framework.zend.com/license/new-bsd New BSD License
3+
* @see https://github.com/zendframework/zend-crypt for the canonical source repository
4+
* @copyright Copyright (c) 2005-2018 Zend Technologies USA Inc. (https://www.zend.com)
5+
* @license https://github.com/zendframework/zend-crypt/blob/master/LICENSE.md New BSD License
86
*/
97

108
namespace Zend\Crypt;
119

1210
use Zend\Crypt\Key\Derivation\Pbkdf2;
1311
use Zend\Math\Rand;
1412

13+
use function fclose;
14+
use function filesize;
15+
use function file_exists;
16+
use function fopen;
17+
use function fread;
18+
use function fseek;
19+
use function fwrite;
20+
use function mb_strlen;
21+
use function mb_substr;
22+
use function sprintf;
23+
use function str_repeat;
24+
1525
/**
1626
* Encrypt/decrypt a file using a symmetric cipher in CBC mode
1727
* then authenticate using HMAC
@@ -170,7 +180,7 @@ public function getCipherSupportedAlgorithms()
170180
*/
171181
public function setHashAlgorithm($hash)
172182
{
173-
if (!Hash::isSupported($hash)) {
183+
if (! Hash::isSupported($hash)) {
174184
throw new Exception\InvalidArgumentException(
175185
"The specified hash algorithm '{$hash}' is not supported by Zend\Crypt\Hash"
176186
);
@@ -196,7 +206,7 @@ public function getHashAlgorithm()
196206
*/
197207
public function setPbkdf2HashAlgorithm($hash)
198208
{
199-
if (!Hash::isSupported($hash)) {
209+
if (! Hash::isSupported($hash)) {
200210
throw new Exception\InvalidArgumentException(
201211
"The specified hash algorithm '{$hash}' is not supported by Zend\Crypt\Hash"
202212
);
@@ -369,7 +379,7 @@ public function decrypt($fileIn, $fileOut)
369379
*/
370380
protected function checkFileInOut($fileIn, $fileOut)
371381
{
372-
if (!file_exists($fileIn)) {
382+
if (! file_exists($fileIn)) {
373383
throw new Exception\InvalidArgumentException(sprintf(
374384
'I cannot open the %s file',
375385
$fileIn

src/Hash.php

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
<?php
22
/**
3-
* Zend Framework (http://framework.zend.com/)
4-
*
5-
* @link http://github.com/zendframework/zf2 for the canonical source repository
6-
* @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com)
7-
* @license http://framework.zend.com/license/new-bsd New BSD License
3+
* @see https://github.com/zendframework/zend-crypt for the canonical source repository
4+
* @copyright Copyright (c) 2005-2018 Zend Technologies USA Inc. (https://www.zend.com)
5+
* @license https://github.com/zendframework/zend-crypt/blob/master/LICENSE.md New BSD License
86
*/
97

108
namespace Zend\Crypt;
119

10+
use function hash;
11+
use function hash_algos;
12+
use function in_array;
13+
use function mb_strlen;
14+
use function strtolower;
15+
1216
class Hash
1317
{
1418
const OUTPUT_STRING = false;
@@ -30,7 +34,7 @@ class Hash
3034
*/
3135
public static function compute($hash, $data, $output = self::OUTPUT_STRING)
3236
{
33-
if (!$hash || ($hash !== static::$lastAlgorithmSupported && !static::isSupported($hash))) {
37+
if (! $hash || ($hash !== static::$lastAlgorithmSupported && ! static::isSupported($hash))) {
3438
throw new Exception\InvalidArgumentException(
3539
'Hash algorithm provided is not supported on this PHP installation'
3640
);

src/Hmac.php

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
<?php
22
/**
3-
* Zend Framework (http://framework.zend.com/)
4-
*
5-
* @link http://github.com/zendframework/zf2 for the canonical source repository
6-
* @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com)
7-
* @license http://framework.zend.com/license/new-bsd New BSD License
3+
* @see https://github.com/zendframework/zend-crypt for the canonical source repository
4+
* @copyright Copyright (c) 2005-2018 Zend Technologies USA Inc. (https://www.zend.com)
5+
* @license https://github.com/zendframework/zend-crypt/blob/master/LICENSE.md New BSD License
86
*/
97

108
namespace Zend\Crypt;
119

10+
use function hash_algos;
11+
use function hash_hmac;
12+
use function in_array;
13+
use function mb_strlen;
14+
use function strtolower;
15+
1216
/**
1317
* PHP implementation of the RFC 2104 Hash based Message Authentication Code
1418
*/
@@ -42,7 +46,7 @@ public static function compute($key, $hash, $data, $output = self::OUTPUT_STRING
4246
throw new Exception\InvalidArgumentException('Provided key is null or empty');
4347
}
4448

45-
if (!$hash || ($hash !== static::$lastAlgorithmSupported && !static::isSupported($hash))) {
49+
if (! $hash || ($hash !== static::$lastAlgorithmSupported && ! static::isSupported($hash))) {
4650
throw new Exception\InvalidArgumentException(
4751
"Hash algorithm is not supported on this PHP installation; provided '{$hash}'"
4852
);

src/Hybrid.php

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
<?php
22
/**
3-
* Zend Framework (http://framework.zend.com/)
4-
*
5-
* @link http://github.com/zendframework/zf2 for the canonical source repository
6-
* @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com)
7-
* @license http://framework.zend.com/license/new-bsd New BSD License
3+
* @see https://github.com/zendframework/zend-crypt for the canonical source repository
4+
* @copyright Copyright (c) 2005-2018 Zend Technologies USA Inc. (https://www.zend.com)
5+
* @license https://github.com/zendframework/zend-crypt/blob/master/LICENSE.md New BSD License
86
*/
97

108
namespace Zend\Crypt;
@@ -13,6 +11,14 @@
1311
use Zend\Crypt\PublicKey\Rsa\PublicKey as PubKey;
1412
use Zend\Crypt\PublicKey\Rsa\PrivateKey;
1513

14+
use function array_search;
15+
use function base64_decode;
16+
use function base64_encode;
17+
use function explode;
18+
use function is_array;
19+
use function is_string;
20+
use function sprintf;
21+
1622
/**
1723
* Hybrid encryption (OpenPGP like)
1824
*
@@ -109,7 +115,7 @@ public function decrypt($msg, $privateKey = null, $passPhrase = null, $id = null
109115
}
110116

111117
if (! $privateKey instanceof PrivateKey && ! is_string($privateKey)) {
112-
throw new Exception\RuntimeException(sprintf(
118+
throw new Exception\RuntimeException(\sprintf(
113119
"The private key must be a string in PEM format or an instance of %s",
114120
PrivateKey::class
115121
));

src/Key/Derivation/Pbkdf2.php

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
11
<?php
22
/**
3-
* Zend Framework (http://framework.zend.com/)
4-
*
5-
* @link http://github.com/zendframework/zf2 for the canonical source repository
6-
* @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com)
7-
* @license http://framework.zend.com/license/new-bsd New BSD License
3+
* @see https://github.com/zendframework/zend-crypt for the canonical source repository
4+
* @copyright Copyright (c) 2005-2018 Zend Technologies USA Inc. (https://www.zend.com)
5+
* @license https://github.com/zendframework/zend-crypt/blob/master/LICENSE.md New BSD License
86
*/
97

108
namespace Zend\Crypt\Key\Derivation;
119

1210
use Zend\Crypt\Hmac;
1311

12+
use function ceil;
13+
use function hash_hmac;
14+
use function mb_substr;
15+
use function pack;
16+
1417
/**
1518
* PKCS #5 v2.0 standard RFC 2898
1619
*/
@@ -29,7 +32,7 @@ class Pbkdf2
2932
*/
3033
public static function calc($hash, $password, $salt, $iterations, $length)
3134
{
32-
if (!Hmac::isSupported($hash)) {
35+
if (! Hmac::isSupported($hash)) {
3336
throw new Exception\InvalidArgumentException("The hash algorithm $hash is not supported by " . __CLASS__);
3437
}
3538

src/Key/Derivation/SaltedS2k.php

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
<?php
22
/**
3-
* Zend Framework (http://framework.zend.com/)
4-
*
5-
* @link http://github.com/zendframework/zf2 for the canonical source repository
6-
* @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com)
7-
* @license http://framework.zend.com/license/new-bsd New BSD License
3+
* @see https://github.com/zendframework/zend-crypt for the canonical source repository
4+
* @copyright Copyright (c) 2005-2018 Zend Technologies USA Inc. (https://www.zend.com)
5+
* @license https://github.com/zendframework/zend-crypt/blob/master/LICENSE.md New BSD License
86
*/
97

108
namespace Zend\Crypt\Key\Derivation;
119

10+
use function array_keys;
11+
use function in_array;
12+
use function mb_strlen;
13+
use function mhash_keygen_s2k;
14+
1215
/**
1316
* Salted S2K key generation (OpenPGP document, RFC 2440)
1417
*/
@@ -61,7 +64,7 @@ class SaltedS2k
6164
*/
6265
public static function calc($hash, $password, $salt, $bytes)
6366
{
64-
if (!in_array($hash, array_keys(static::$supportedMhashAlgos))) {
67+
if (! in_array($hash, array_keys(static::$supportedMhashAlgos))) {
6568
throw new Exception\InvalidArgumentException("The hash algorithm $hash is not supported by " . __CLASS__);
6669
}
6770
if (mb_strlen($salt, '8bit') < 8) {

src/Key/Derivation/Scrypt.php

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,22 @@
11
<?php
22
/**
3-
* Zend Framework (http://framework.zend.com/)
4-
*
5-
* @link http://github.com/zendframework/zf2 for the canonical source repository
6-
* @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com)
7-
* @license http://framework.zend.com/license/new-bsd New BSD License
3+
* @see https://github.com/zendframework/zend-crypt for the canonical source repository
4+
* @copyright Copyright (c) 2005-2018 Zend Technologies USA Inc. (https://www.zend.com)
5+
* @license https://github.com/zendframework/zend-crypt/blob/master/LICENSE.md New BSD License
86
*/
97

108
namespace Zend\Crypt\Key\Derivation;
119

10+
use const PHP_INT_MAX;
11+
use const PHP_INT_SIZE;
12+
13+
use function extension_loaded;
14+
use function hex2bin;
15+
use function mb_substr;
16+
use function pack;
17+
use function scrypt;
18+
use function unpack;
19+
1220
/**
1321
* Scrypt key derivation function
1422
*

0 commit comments

Comments
 (0)
0