diff --git a/src/Cryptography/Keys/EcdsaPrivateKey.php b/src/Cryptography/Keys/EcdsaPrivateKey.php index 5efe033..c482b2b 100644 --- a/src/Cryptography/Keys/EcdsaPrivateKey.php +++ b/src/Cryptography/Keys/EcdsaPrivateKey.php @@ -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()); } diff --git a/src/Cryptography/Keys/EcdsaPublicKey.php b/src/Cryptography/Keys/EcdsaPublicKey.php index c49584c..0e43fca 100644 --- a/src/Cryptography/Keys/EcdsaPublicKey.php +++ b/src/Cryptography/Keys/EcdsaPublicKey.php @@ -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()); } diff --git a/src/Cryptography/Keys/RsaPrivateKey.php b/src/Cryptography/Keys/RsaPrivateKey.php index 631d6d7..2c7b87b 100644 --- a/src/Cryptography/Keys/RsaPrivateKey.php +++ b/src/Cryptography/Keys/RsaPrivateKey.php @@ -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()); } diff --git a/src/Cryptography/Keys/RsaPublicKey.php b/src/Cryptography/Keys/RsaPublicKey.php index f55a4f4..92b5e8a 100644 --- a/src/Cryptography/Keys/RsaPublicKey.php +++ b/src/Cryptography/Keys/RsaPublicKey.php @@ -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() ?: ''); }