18
18
* SOFTWARE.
19
19
*/
20
20
21
+ declare (strict_types=1 );
22
+
21
23
namespace DarkWebDesign \PublicKeyCryptographyBundle \File ;
22
24
23
25
use DarkWebDesign \PublicKeyCryptographyBundle \Exception \PrivateKeyPassPhraseEmptyException ;
@@ -35,7 +37,7 @@ class PemFile extends CryptoFile
35
37
*
36
38
* @return bool
37
39
*/
38
- protected function validate ()
40
+ protected function validate (): bool
39
41
{
40
42
$ in = escapeshellarg ($ this ->getPathname ());
41
43
@@ -71,14 +73,14 @@ protected function validate()
71
73
* @throws \DarkWebDesign\PublicKeyCryptographyBundle\Exception\PrivateKeyPassPhraseEmptyException
72
74
* @throws \Symfony\Component\Process\Exception\ProcessFailedException
73
75
*/
74
- public function sanitize ($ passPhrase = null )
76
+ public function sanitize (string $ passPhrase = null ): PemFile
75
77
{
76
78
if ('' === $ passPhrase ) {
77
79
throw new PrivateKeyPassPhraseEmptyException ();
78
80
}
79
81
80
82
$ in = escapeshellarg ($ this ->getPathname ());
81
- $ pass = escapeshellarg ($ passPhrase );
83
+ $ pass = escapeshellarg (( string ) $ passPhrase );
82
84
83
85
if (null !== $ passPhrase ) {
84
86
$ rsaPassOut = "-passout pass: $ pass -des3 " ;
@@ -116,7 +118,7 @@ public function sanitize($passPhrase = null)
116
118
* @throws \DarkWebDesign\PublicKeyCryptographyBundle\Exception\PrivateKeyPassPhraseEmptyException
117
119
* @throws \Symfony\Component\Process\Exception\ProcessFailedException
118
120
*/
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
120
122
{
121
123
if ('' === $ privateKeyPassPhrase ) {
122
124
throw new PrivateKeyPassPhraseEmptyException ();
@@ -126,7 +128,7 @@ public static function create($path, PublicKeyFile $publicKeyFile, PrivateKeyFil
126
128
$ publicKeyInForm = escapeshellarg ($ publicKeyFile ->getFormat ());
127
129
$ privateKeyIn = escapeshellarg ($ privateKeyFile ->getPathname ());
128
130
$ privateKeyInForm = escapeshellarg ($ privateKeyFile ->getFormat ());
129
- $ privateKeyPass = escapeshellarg ($ privateKeyPassPhrase );
131
+ $ privateKeyPass = escapeshellarg (( string ) $ privateKeyPassPhrase );
130
132
131
133
if (null !== $ privateKeyPassPhrase ) {
132
134
$ rsaPassOut = "-passout pass: $ privateKeyPass -des3 " ;
@@ -157,11 +159,11 @@ public static function create($path, PublicKeyFile $publicKeyFile, PrivateKeyFil
157
159
*
158
160
* @throws \Symfony\Component\Process\Exception\ProcessFailedException
159
161
*/
160
- public function getKeystore ($ path , $ keystorePassPhrase , $ privateKeyPassPhrase = null )
162
+ public function getKeystore (string $ path , string $ keystorePassPhrase , string $ privateKeyPassPhrase = null ): KeystoreFile
161
163
{
162
164
$ in = escapeshellarg ($ this ->getPathname ());
163
165
$ keystorePass = escapeshellarg ($ keystorePassPhrase );
164
- $ privateKeyPass = escapeshellarg ($ privateKeyPassPhrase );
166
+ $ privateKeyPass = escapeshellarg (( string ) $ privateKeyPassPhrase );
165
167
166
168
$ process = new Process ("openssl pkcs12 -in $ in -passin pass: $ privateKeyPass -passout pass: $ keystorePass -export " );
167
169
$ process ->mustRun ();
@@ -181,7 +183,7 @@ public function getKeystore($path, $keystorePassPhrase, $privateKeyPassPhrase =
181
183
*
182
184
* @throws \Symfony\Component\Process\Exception\ProcessFailedException
183
185
*/
184
- public function getPublicKey ($ path )
186
+ public function getPublicKey (string $ path ): PublicKeyFile
185
187
{
186
188
$ in = escapeshellarg ($ this ->getPathname ());
187
189
@@ -209,14 +211,14 @@ public function getPublicKey($path)
209
211
* @throws \DarkWebDesign\PublicKeyCryptographyBundle\Exception\PrivateKeyPassPhraseEmptyException
210
212
* @throws \Symfony\Component\Process\Exception\ProcessFailedException
211
213
*/
212
- public function getPrivateKey ($ path , $ passPhrase = null )
214
+ public function getPrivateKey (string $ path , string $ passPhrase = null ): PrivateKeyFile
213
215
{
214
216
if ('' === $ passPhrase ) {
215
217
throw new PrivateKeyPassPhraseEmptyException ();
216
218
}
217
219
218
220
$ in = escapeshellarg ($ this ->getPathname ());
219
- $ pass = escapeshellarg ($ passPhrase );
221
+ $ pass = escapeshellarg (( string ) $ passPhrase );
220
222
221
223
if (null !== $ passPhrase ) {
222
224
$ rsaPassOut = "-passout pass: $ pass -des3 " ;
@@ -240,7 +242,7 @@ public function getPrivateKey($path, $passPhrase = null)
240
242
*
241
243
* @throws \Symfony\Component\Process\Exception\ProcessFailedException
242
244
*/
243
- public function getSubject ()
245
+ public function getSubject (): string
244
246
{
245
247
$ in = escapeshellarg ($ this ->getPathname ());
246
248
@@ -257,7 +259,7 @@ public function getSubject()
257
259
*
258
260
* @throws \Symfony\Component\Process\Exception\ProcessFailedException
259
261
*/
260
- public function getIssuer ()
262
+ public function getIssuer (): string
261
263
{
262
264
$ in = escapeshellarg ($ this ->getPathname ());
263
265
@@ -274,7 +276,7 @@ public function getIssuer()
274
276
*
275
277
* @throws \Symfony\Component\Process\Exception\ProcessFailedException
276
278
*/
277
- public function getNotBefore ()
279
+ public function getNotBefore (): \ DateTime
278
280
{
279
281
$ in = escapeshellarg ($ this ->getPathname ());
280
282
@@ -291,7 +293,7 @@ public function getNotBefore()
291
293
*
292
294
* @throws \Symfony\Component\Process\Exception\ProcessFailedException
293
295
*/
294
- public function getNotAfter ()
296
+ public function getNotAfter (): \ DateTime
295
297
{
296
298
$ in = escapeshellarg ($ this ->getPathname ());
297
299
@@ -306,7 +308,7 @@ public function getNotAfter()
306
308
*
307
309
* @return bool
308
310
*/
309
- public function hasPassPhrase ()
311
+ public function hasPassPhrase (): bool
310
312
{
311
313
$ in = escapeshellarg ($ this ->getPathname ());
312
314
@@ -329,7 +331,7 @@ public function hasPassPhrase()
329
331
*
330
332
* @return bool
331
333
*/
332
- public function verifyPassPhrase ($ passPhrase )
334
+ public function verifyPassPhrase (string $ passPhrase ): bool
333
335
{
334
336
$ in = escapeshellarg ($ this ->getPathname ());
335
337
$ pass = escapeshellarg ($ passPhrase );
@@ -353,7 +355,7 @@ public function verifyPassPhrase($passPhrase)
353
355
* @throws \DarkWebDesign\PublicKeyCryptographyBundle\Exception\PrivateKeyPassPhraseEmptyException
354
356
* @throws \Symfony\Component\Process\Exception\ProcessFailedException
355
357
*/
356
- public function addPassPhrase ($ passPhrase )
358
+ public function addPassPhrase (string $ passPhrase ): PemFile
357
359
{
358
360
if ('' === $ passPhrase ) {
359
361
throw new PrivateKeyPassPhraseEmptyException ();
@@ -384,7 +386,7 @@ public function addPassPhrase($passPhrase)
384
386
*
385
387
* @throws \Symfony\Component\Process\Exception\ProcessFailedException
386
388
*/
387
- public function removePassPhrase ($ passPhrase )
389
+ public function removePassPhrase (string $ passPhrase ): PemFile
388
390
{
389
391
$ in = escapeshellarg ($ this ->getPathname ());
390
392
$ pass = escapeshellarg ($ passPhrase );
@@ -416,7 +418,7 @@ public function removePassPhrase($passPhrase)
416
418
* @throws \DarkWebDesign\PublicKeyCryptographyBundle\Exception\PrivateKeyPassPhraseEmptyException
417
419
* @throws \Symfony\Component\Process\Exception\ProcessFailedException
418
420
*/
419
- public function changePassPhrase ($ passPhrase , $ newPassPhrase )
421
+ public function changePassPhrase (string $ passPhrase , string $ newPassPhrase ): PemFile
420
422
{
421
423
if ('' === $ newPassPhrase ) {
422
424
throw new PrivateKeyPassPhraseEmptyException ();
@@ -449,7 +451,7 @@ public function changePassPhrase($passPhrase, $newPassPhrase)
449
451
*
450
452
* @throws \Symfony\Component\HttpFoundation\File\Exception\FileException
451
453
*/
452
- public function move ($ directory , $ name = null )
454
+ public function move ($ directory , $ name = null ): PemFile
453
455
{
454
456
$ file = parent ::move ($ directory , $ name );
455
457
0 commit comments