@@ -150,6 +150,9 @@ |
||
150 | 150 | return "-----BEGIN {$type}-----\n{$pem}-----END {$type}-----\n"; |
151 | 151 | } |
152 | 152 | |
153 | + /** |
|
154 | + * @param \Closure $callable |
|
155 | + */ |
|
153 | 156 | protected function guardAgainstUserErrorsFromPhpSeclib($callable) |
154 | 157 | { |
155 | 158 | set_error_handler(function ($errno, $errstr, $errfile, $errline) { |
@@ -2,10 +2,10 @@ |
||
2 | 2 | |
3 | 3 | namespace Spatie\CertificateChain; |
4 | 4 | |
5 | +use Spatie\CertificateChain\Exceptions\CouldNotCreateCertificate; |
|
6 | +use Spatie\CertificateChain\Exceptions\CouldNotLoadCertificate; |
|
5 | 7 | use phpseclib\File\ASN1; |
6 | 8 | use phpseclib\File\X509; |
7 | -use Spatie\CertificateChain\Exceptions\CouldNotLoadCertificate; |
|
8 | -use Spatie\CertificateChain\Exceptions\CouldNotCreateCertificate; |
|
9 | 9 | |
10 | 10 | class Certificate |
11 | 11 | { |
@@ -45,7 +45,7 @@ discard block |
||
45 | 45 | $certificate = $contents; |
46 | 46 | |
47 | 47 | // If we are missing the pem certificate header, try to convert it to a pem format first |
48 | - if (! empty($contents) && strpos($contents, '-----BEGIN CERTIFICATE-----') === false) { |
|
48 | + if (!empty($contents) && strpos($contents, '-----BEGIN CERTIFICATE-----') === false) { |
|
49 | 49 | // Extract from either a PKCS#7 format or DER formatted contents |
50 | 50 | $certificate = self::convertPkcs72Pem($contents) ?? self::convertDer2Pem($contents); |
51 | 51 | } |
@@ -88,21 +88,21 @@ discard block |
||
88 | 88 | |
89 | 89 | public function hasParentInTrustChain(): bool |
90 | 90 | { |
91 | - return ! $this->getParentCertificateUrl() == ''; |
|
91 | + return !$this->getParentCertificateUrl() == ''; |
|
92 | 92 | } |
93 | 93 | |
94 | 94 | public function getContents(): string |
95 | 95 | { |
96 | - return $this->guardAgainstUserErrorsFromPhpSeclib(function () { |
|
96 | + return $this->guardAgainstUserErrorsFromPhpSeclib(function() { |
|
97 | 97 | $x509 = new X509(); |
98 | 98 | |
99 | - return $x509->saveX509($x509->loadX509($this->contents)) . PHP_EOL; |
|
99 | + return $x509->saveX509($x509->loadX509($this->contents)).PHP_EOL; |
|
100 | 100 | }); |
101 | 101 | } |
102 | 102 | |
103 | 103 | protected function guardAgainstInvalidContents(string $content, string $original) |
104 | 104 | { |
105 | - if (! (new X509())->loadX509($content)) { |
|
105 | + if (!(new X509())->loadX509($content)) { |
|
106 | 106 | throw CouldNotCreateCertificate::invalidContent($original); |
107 | 107 | } |
108 | 108 | } |
@@ -152,7 +152,7 @@ discard block |
||
152 | 152 | |
153 | 153 | protected function guardAgainstUserErrorsFromPhpSeclib($callable) |
154 | 154 | { |
155 | - set_error_handler(function ($errno, $errstr, $errfile, $errline) { |
|
155 | + set_error_handler(function($errno, $errstr, $errfile, $errline) { |
|
156 | 156 | /* ignore user errors from phpseclib */ |
157 | 157 | }, E_USER_NOTICE); |
158 | 158 |