@@ -35,6 +35,10 @@ public static function loadKeyFromCertificateFile(string $file): array
3535
3636 public static function loadKeyFromCertificate (string $ certificate ): array
3737 {
38+ if (!\extension_loaded ('openssl ' )) {
39+ throw new RuntimeException ('Please install the OpenSSL extension ' );
40+ }
41+
3842 try {
3943 $ res = openssl_x509_read ($ certificate );
4044 if (false === $ res ) {
@@ -59,6 +63,9 @@ public static function loadKeyFromCertificate(string $certificate): array
5963 */
6064 public static function loadKeyFromX509Resource ($ res ): array
6165 {
66+ if (!\extension_loaded ('openssl ' )) {
67+ throw new RuntimeException ('Please install the OpenSSL extension ' );
68+ }
6269 $ key = openssl_get_publickey ($ res );
6370 if (false === $ key ) {
6471 throw new InvalidArgumentException ('Unable to load the certificate. ' );
@@ -110,6 +117,10 @@ public static function loadFromX5C(array $x5c): array
110117 if (0 === \count ($ x5c )) {
111118 throw new InvalidArgumentException ('The certificate chain is empty ' );
112119 }
120+
121+ if (!\extension_loaded ('openssl ' )) {
122+ throw new RuntimeException ('Please install the OpenSSL extension ' );
123+ }
113124 $ certificate = null ;
114125 $ last_issuer = null ;
115126 $ last_subject = null ;
@@ -157,6 +168,9 @@ private static function loadKeyFromPEM(string $pem, ?string $password = null): a
157168 $ pem = self ::decodePem ($ pem , $ matches , $ password );
158169 }
159170
171+ if (!\extension_loaded ('openssl ' )) {
172+ throw new RuntimeException ('Please install the OpenSSL extension ' );
173+ }
160174 self ::sanitizePEM ($ pem );
161175 $ res = openssl_pkey_get_private ($ pem );
162176 if (false === $ res ) {
0 commit comments