Skip to content

Commit

Permalink
remove unnecessary catches
Browse files Browse the repository at this point in the history
  • Loading branch information
miladrahimi committed May 31, 2024
1 parent dca652d commit 83a4e54
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 24 deletions.
8 changes: 2 additions & 6 deletions src/Cryptography/Keys/EcdsaPrivateKey.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,9 @@ class EcdsaPrivateKey
*/
public function __construct(string $key, string $passphrase = '', ?string $id = null)
{
try {
$content = file_exists($key) ? file_get_contents($key) : $key;
$this->resource = openssl_pkey_get_private($content, $passphrase);
} catch (Throwable $e) {
throw new InvalidKeyException('Failed to read the key.', 0, $e);
}
$content = file_exists($key) ? file_get_contents($key) : $key;

$this->resource = openssl_pkey_get_private($content, $passphrase);
if ($this->resource === false) {
throw new InvalidKeyException(openssl_error_string());
}
Expand Down
8 changes: 2 additions & 6 deletions src/Cryptography/Keys/EcdsaPublicKey.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,9 @@ class EcdsaPublicKey
*/
public function __construct(string $key, ?string $id = null)
{
try {
$content = file_exists($key) ? file_get_contents($key) : $key;
$this->resource = openssl_pkey_get_public($content);
} catch (Throwable $e) {
throw new InvalidKeyException('Failed to read the key.', 0, $e);
}
$content = file_exists($key) ? file_get_contents($key) : $key;

$this->resource = openssl_pkey_get_public($content);
if ($this->resource === false) {
throw new InvalidKeyException(openssl_error_string());
}
Expand Down
8 changes: 2 additions & 6 deletions src/Cryptography/Keys/RsaPrivateKey.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,9 @@ class RsaPrivateKey
*/
public function __construct(string $key, string $passphrase = '', ?string $id = null)
{
try {
$content = file_exists($key) ? file_get_contents($key) : $key;
$this->resource = openssl_pkey_get_private($content, $passphrase);
} catch (Throwable $e) {
throw new InvalidKeyException('Cannot load the private key.', 0, $e);
}
$content = file_exists($key) ? file_get_contents($key) : $key;

$this->resource = openssl_pkey_get_private($content, $passphrase);
if ($this->resource === false) {
throw new InvalidKeyException(openssl_error_string());
}
Expand Down
8 changes: 2 additions & 6 deletions src/Cryptography/Keys/RsaPublicKey.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,9 @@ class RsaPublicKey
*/
public function __construct(string $key, ?string $id = null)
{
try {
$content = file_exists($key) ? file_get_contents($key) : $key;
$this->resource = openssl_pkey_get_public($content);
} catch (Throwable $e) {
throw new InvalidKeyException('Failed to read the key.', 0, $e);
}
$content = file_exists($key) ? file_get_contents($key) : $key;

$this->resource = openssl_pkey_get_public($content);
if ($this->resource === false) {
throw new InvalidKeyException(openssl_error_string() ?: '');
}
Expand Down

0 comments on commit 83a4e54

Please sign in to comment.