Skip to content

Commit 6f890e2

Browse files
Merge pull request #30 from darkwebdesign/ISSUE-18
ISSUE-18: Update code to PHP 7.1
2 parents 01fd8ce + 5c91221 commit 6f890e2

17 files changed

+201
-159
lines changed

Exception/FileNotValidException.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
* SOFTWARE.
1919
*/
2020

21+
declare(strict_types=1);
22+
2123
namespace DarkWebDesign\PublicKeyCryptographyBundle\Exception;
2224

2325
use Symfony\Component\HttpFoundation\File\Exception\FileException;

Exception/FormatNotValidException.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
* SOFTWARE.
1919
*/
2020

21+
declare(strict_types=1);
22+
2123
namespace DarkWebDesign\PublicKeyCryptographyBundle\Exception;
2224

2325
/**

Exception/PrivateKeyPassPhraseEmptyException.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
* SOFTWARE.
1919
*/
2020

21+
declare(strict_types=1);
22+
2123
namespace DarkWebDesign\PublicKeyCryptographyBundle\Exception;
2224

2325
/**

File/CryptoFile.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
* SOFTWARE.
1919
*/
2020

21+
declare(strict_types=1);
22+
2123
namespace DarkWebDesign\PublicKeyCryptographyBundle\File;
2224

2325
use DarkWebDesign\PublicKeyCryptographyBundle\Exception\FileNotValidException;
@@ -39,7 +41,7 @@ abstract class CryptoFile extends File
3941
* @throws \DarkWebDesign\PublicKeyCryptographyBundle\Exception\FileNotValidException
4042
* @throws \Symfony\Component\HttpFoundation\File\Exception\FileNotFoundException
4143
*/
42-
public function __construct($path)
44+
public function __construct(string $path)
4345
{
4446
parent::__construct($path);
4547

@@ -53,14 +55,14 @@ public function __construct($path)
5355
*
5456
* @return bool
5557
*/
56-
abstract protected function validate();
58+
abstract protected function validate(): bool;
5759

5860
/**
5961
* Checks if the file is binary.
6062
*
6163
* @return bool
6264
*/
63-
protected function isBinary()
65+
protected function isBinary(): bool
6466
{
6567
$command = sprintf(
6668
'file --brief --mime-encoding %1$s | grep binary',

File/KeystoreFile.php

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
* SOFTWARE.
1919
*/
2020

21+
declare(strict_types=1);
22+
2123
namespace DarkWebDesign\PublicKeyCryptographyBundle\File;
2224

2325
use Symfony\Component\Process\Process;
@@ -34,7 +36,7 @@ class KeystoreFile extends CryptoFile
3436
*
3537
* @return bool
3638
*/
37-
protected function validate()
39+
protected function validate(): bool
3840
{
3941
$in = escapeshellarg($this->getPathname());
4042

@@ -67,14 +69,14 @@ protected function validate()
6769
*
6870
* @throws \Symfony\Component\Process\Exception\ProcessFailedException
6971
*/
70-
public static function create($path, $passPhrase, PublicKeyFile $publicKeyFile, PrivateKeyFile $privateKeyFile, $privateKeyPassPhrase = null)
72+
public static function create(string $path, string $passPhrase, PublicKeyFile $publicKeyFile, PrivateKeyFile $privateKeyFile, string $privateKeyPassPhrase = null): KeystoreFile
7173
{
7274
$pass = escapeshellarg($passPhrase);
7375
$publicKeyIn = escapeshellarg($publicKeyFile->getPathname());
7476
$publicKeyInForm = escapeshellarg($publicKeyFile->getFormat());
7577
$privateKeyIn = escapeshellarg($privateKeyFile->getPathname());
7678
$privateKeyInForm = escapeshellarg($privateKeyFile->getFormat());
77-
$privateKeyPass = escapeshellarg($privateKeyPassPhrase);
79+
$privateKeyPass = escapeshellarg((string) $privateKeyPassPhrase);
7880

7981
$process1 = new Process("openssl rsa -in $privateKeyIn -inform $privateKeyInForm -passin pass:$privateKeyPass -passout pass:pipe -des3");
8082
$process1->mustRun();
@@ -102,7 +104,7 @@ public static function create($path, $passPhrase, PublicKeyFile $publicKeyFile,
102104
*
103105
* @throws \Symfony\Component\Process\Exception\ProcessFailedException
104106
*/
105-
public function getPem($path, $passPhrase)
107+
public function getPem(string $path, string $passPhrase): PemFile
106108
{
107109
$in = escapeshellarg($this->getPathname());
108110
$pass = escapeshellarg($passPhrase);
@@ -144,7 +146,7 @@ public function getPem($path, $passPhrase)
144146
*
145147
* @throws \Symfony\Component\Process\Exception\ProcessFailedException
146148
*/
147-
public function getPublicKey($path, $passPhrase)
149+
public function getPublicKey(string $path, string $passPhrase): PublicKeyFile
148150
{
149151
$in = escapeshellarg($this->getPathname());
150152
$pass = escapeshellarg($passPhrase);
@@ -175,7 +177,7 @@ public function getPublicKey($path, $passPhrase)
175177
*
176178
* @throws \Symfony\Component\Process\Exception\ProcessFailedException
177179
*/
178-
public function getPrivateKey($path, $passPhrase)
180+
public function getPrivateKey(string $path, string $passPhrase): PrivateKeyFile
179181
{
180182
$in = escapeshellarg($this->getPathname());
181183
$pass = escapeshellarg($passPhrase);
@@ -209,7 +211,7 @@ public function getPrivateKey($path, $passPhrase)
209211
*
210212
* @throws \Symfony\Component\Process\Exception\ProcessFailedException
211213
*/
212-
public function getSubject($passPhrase)
214+
public function getSubject(string $passPhrase): string
213215
{
214216
$in = escapeshellarg($this->getPathname());
215217
$pass = escapeshellarg($passPhrase);
@@ -233,7 +235,7 @@ public function getSubject($passPhrase)
233235
*
234236
* @throws \Symfony\Component\Process\Exception\ProcessFailedException
235237
*/
236-
public function getIssuer($passPhrase)
238+
public function getIssuer(string $passPhrase): string
237239
{
238240
$in = escapeshellarg($this->getPathname());
239241
$pass = escapeshellarg($passPhrase);
@@ -257,7 +259,7 @@ public function getIssuer($passPhrase)
257259
*
258260
* @throws \Symfony\Component\Process\Exception\ProcessFailedException
259261
*/
260-
public function getNotBefore($passPhrase)
262+
public function getNotBefore(string $passPhrase): \DateTime
261263
{
262264
$in = escapeshellarg($this->getPathname());
263265
$pass = escapeshellarg($passPhrase);
@@ -281,7 +283,7 @@ public function getNotBefore($passPhrase)
281283
*
282284
* @throws \Symfony\Component\Process\Exception\ProcessFailedException
283285
*/
284-
public function getNotAfter($passPhrase)
286+
public function getNotAfter(string $passPhrase): \DateTime
285287
{
286288
$in = escapeshellarg($this->getPathname());
287289
$pass = escapeshellarg($passPhrase);
@@ -303,7 +305,7 @@ public function getNotAfter($passPhrase)
303305
*
304306
* @return bool
305307
*/
306-
public function verifyPassPhrase($passPhrase)
308+
public function verifyPassPhrase(string $passPhrase): bool
307309
{
308310
$in = escapeshellarg($this->getPathname());
309311
$pass = escapeshellarg($passPhrase);
@@ -324,7 +326,7 @@ public function verifyPassPhrase($passPhrase)
324326
*
325327
* @throws \Symfony\Component\Process\Exception\ProcessFailedException
326328
*/
327-
public function changePassPhrase($passPhrase, $newPassPhrase)
329+
public function changePassPhrase(string $passPhrase, string $newPassPhrase): KeystoreFile
328330
{
329331
$in = escapeshellarg($this->getPathname());
330332
$pass = escapeshellarg($passPhrase);
@@ -365,7 +367,7 @@ public function changePassPhrase($passPhrase, $newPassPhrase)
365367
*
366368
* @throws \Symfony\Component\HttpFoundation\File\Exception\FileException
367369
*/
368-
public function move($directory, $name = null)
370+
public function move($directory, $name = null): KeystoreFile
369371
{
370372
$file = parent::move($directory, $name);
371373

File/PemFile.php

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
* SOFTWARE.
1919
*/
2020

21+
declare(strict_types=1);
22+
2123
namespace DarkWebDesign\PublicKeyCryptographyBundle\File;
2224

2325
use DarkWebDesign\PublicKeyCryptographyBundle\Exception\PrivateKeyPassPhraseEmptyException;
@@ -35,7 +37,7 @@ class PemFile extends CryptoFile
3537
*
3638
* @return bool
3739
*/
38-
protected function validate()
40+
protected function validate(): bool
3941
{
4042
$in = escapeshellarg($this->getPathname());
4143

@@ -71,14 +73,14 @@ protected function validate()
7173
* @throws \DarkWebDesign\PublicKeyCryptographyBundle\Exception\PrivateKeyPassPhraseEmptyException
7274
* @throws \Symfony\Component\Process\Exception\ProcessFailedException
7375
*/
74-
public function sanitize($passPhrase = null)
76+
public function sanitize(string $passPhrase = null): PemFile
7577
{
7678
if ('' === $passPhrase) {
7779
throw new PrivateKeyPassPhraseEmptyException();
7880
}
7981

8082
$in = escapeshellarg($this->getPathname());
81-
$pass = escapeshellarg($passPhrase);
83+
$pass = escapeshellarg((string) $passPhrase);
8284

8385
if (null !== $passPhrase) {
8486
$rsaPassOut = "-passout pass:$pass -des3";
@@ -116,7 +118,7 @@ public function sanitize($passPhrase = null)
116118
* @throws \DarkWebDesign\PublicKeyCryptographyBundle\Exception\PrivateKeyPassPhraseEmptyException
117119
* @throws \Symfony\Component\Process\Exception\ProcessFailedException
118120
*/
119-
public static function create($path, PublicKeyFile $publicKeyFile, PrivateKeyFile $privateKeyFile, $privateKeyPassPhrase = null)
121+
public static function create(string $path, PublicKeyFile $publicKeyFile, PrivateKeyFile $privateKeyFile, string $privateKeyPassPhrase = null): PemFile
120122
{
121123
if ('' === $privateKeyPassPhrase) {
122124
throw new PrivateKeyPassPhraseEmptyException();
@@ -126,7 +128,7 @@ public static function create($path, PublicKeyFile $publicKeyFile, PrivateKeyFil
126128
$publicKeyInForm = escapeshellarg($publicKeyFile->getFormat());
127129
$privateKeyIn = escapeshellarg($privateKeyFile->getPathname());
128130
$privateKeyInForm = escapeshellarg($privateKeyFile->getFormat());
129-
$privateKeyPass = escapeshellarg($privateKeyPassPhrase);
131+
$privateKeyPass = escapeshellarg((string) $privateKeyPassPhrase);
130132

131133
if (null !== $privateKeyPassPhrase) {
132134
$rsaPassOut = "-passout pass:$privateKeyPass -des3";
@@ -157,11 +159,11 @@ public static function create($path, PublicKeyFile $publicKeyFile, PrivateKeyFil
157159
*
158160
* @throws \Symfony\Component\Process\Exception\ProcessFailedException
159161
*/
160-
public function getKeystore($path, $keystorePassPhrase, $privateKeyPassPhrase = null)
162+
public function getKeystore(string $path, string $keystorePassPhrase, string $privateKeyPassPhrase = null): KeystoreFile
161163
{
162164
$in = escapeshellarg($this->getPathname());
163165
$keystorePass = escapeshellarg($keystorePassPhrase);
164-
$privateKeyPass = escapeshellarg($privateKeyPassPhrase);
166+
$privateKeyPass = escapeshellarg((string) $privateKeyPassPhrase);
165167

166168
$process = new Process("openssl pkcs12 -in $in -passin pass:$privateKeyPass -passout pass:$keystorePass -export");
167169
$process->mustRun();
@@ -181,7 +183,7 @@ public function getKeystore($path, $keystorePassPhrase, $privateKeyPassPhrase =
181183
*
182184
* @throws \Symfony\Component\Process\Exception\ProcessFailedException
183185
*/
184-
public function getPublicKey($path)
186+
public function getPublicKey(string $path): PublicKeyFile
185187
{
186188
$in = escapeshellarg($this->getPathname());
187189

@@ -209,14 +211,14 @@ public function getPublicKey($path)
209211
* @throws \DarkWebDesign\PublicKeyCryptographyBundle\Exception\PrivateKeyPassPhraseEmptyException
210212
* @throws \Symfony\Component\Process\Exception\ProcessFailedException
211213
*/
212-
public function getPrivateKey($path, $passPhrase = null)
214+
public function getPrivateKey(string $path, string $passPhrase = null): PrivateKeyFile
213215
{
214216
if ('' === $passPhrase) {
215217
throw new PrivateKeyPassPhraseEmptyException();
216218
}
217219

218220
$in = escapeshellarg($this->getPathname());
219-
$pass = escapeshellarg($passPhrase);
221+
$pass = escapeshellarg((string) $passPhrase);
220222

221223
if (null !== $passPhrase) {
222224
$rsaPassOut = "-passout pass:$pass -des3";
@@ -240,7 +242,7 @@ public function getPrivateKey($path, $passPhrase = null)
240242
*
241243
* @throws \Symfony\Component\Process\Exception\ProcessFailedException
242244
*/
243-
public function getSubject()
245+
public function getSubject(): string
244246
{
245247
$in = escapeshellarg($this->getPathname());
246248

@@ -257,7 +259,7 @@ public function getSubject()
257259
*
258260
* @throws \Symfony\Component\Process\Exception\ProcessFailedException
259261
*/
260-
public function getIssuer()
262+
public function getIssuer(): string
261263
{
262264
$in = escapeshellarg($this->getPathname());
263265

@@ -274,7 +276,7 @@ public function getIssuer()
274276
*
275277
* @throws \Symfony\Component\Process\Exception\ProcessFailedException
276278
*/
277-
public function getNotBefore()
279+
public function getNotBefore(): \DateTime
278280
{
279281
$in = escapeshellarg($this->getPathname());
280282

@@ -291,7 +293,7 @@ public function getNotBefore()
291293
*
292294
* @throws \Symfony\Component\Process\Exception\ProcessFailedException
293295
*/
294-
public function getNotAfter()
296+
public function getNotAfter(): \DateTime
295297
{
296298
$in = escapeshellarg($this->getPathname());
297299

@@ -306,7 +308,7 @@ public function getNotAfter()
306308
*
307309
* @return bool
308310
*/
309-
public function hasPassPhrase()
311+
public function hasPassPhrase(): bool
310312
{
311313
$in = escapeshellarg($this->getPathname());
312314

@@ -329,7 +331,7 @@ public function hasPassPhrase()
329331
*
330332
* @return bool
331333
*/
332-
public function verifyPassPhrase($passPhrase)
334+
public function verifyPassPhrase(string $passPhrase): bool
333335
{
334336
$in = escapeshellarg($this->getPathname());
335337
$pass = escapeshellarg($passPhrase);
@@ -353,7 +355,7 @@ public function verifyPassPhrase($passPhrase)
353355
* @throws \DarkWebDesign\PublicKeyCryptographyBundle\Exception\PrivateKeyPassPhraseEmptyException
354356
* @throws \Symfony\Component\Process\Exception\ProcessFailedException
355357
*/
356-
public function addPassPhrase($passPhrase)
358+
public function addPassPhrase(string $passPhrase): PemFile
357359
{
358360
if ('' === $passPhrase) {
359361
throw new PrivateKeyPassPhraseEmptyException();
@@ -384,7 +386,7 @@ public function addPassPhrase($passPhrase)
384386
*
385387
* @throws \Symfony\Component\Process\Exception\ProcessFailedException
386388
*/
387-
public function removePassPhrase($passPhrase)
389+
public function removePassPhrase(string $passPhrase): PemFile
388390
{
389391
$in = escapeshellarg($this->getPathname());
390392
$pass = escapeshellarg($passPhrase);
@@ -416,7 +418,7 @@ public function removePassPhrase($passPhrase)
416418
* @throws \DarkWebDesign\PublicKeyCryptographyBundle\Exception\PrivateKeyPassPhraseEmptyException
417419
* @throws \Symfony\Component\Process\Exception\ProcessFailedException
418420
*/
419-
public function changePassPhrase($passPhrase, $newPassPhrase)
421+
public function changePassPhrase(string $passPhrase, string $newPassPhrase): PemFile
420422
{
421423
if ('' === $newPassPhrase) {
422424
throw new PrivateKeyPassPhraseEmptyException();
@@ -449,7 +451,7 @@ public function changePassPhrase($passPhrase, $newPassPhrase)
449451
*
450452
* @throws \Symfony\Component\HttpFoundation\File\Exception\FileException
451453
*/
452-
public function move($directory, $name = null)
454+
public function move($directory, $name = null): PemFile
453455
{
454456
$file = parent::move($directory, $name);
455457

0 commit comments

Comments
 (0)