88use PhpCfdi \Credentials \Internal \Key ;
99use PhpCfdi \Credentials \Internal \LocalFileOpenTrait ;
1010use RuntimeException ;
11+ use const PHP_VERSION_ID ;
1112
1213class PublicKey extends Key
1314{
@@ -59,13 +60,17 @@ function ($publicKey) use ($data, $signature, $algorithm): bool {
5960 * This method id created to wrap and mock openssl_verify
6061 * @param string $data
6162 * @param string $signature
62- * @param resource $publicKey
63+ * @param mixed $publicKey
6364 * @param int $algorithm
6465 * @return int
6566 */
6667 protected function openSslVerify (string $ data , string $ signature , $ publicKey , int $ algorithm ): int
6768 {
68- return openssl_verify ($ data , $ signature , $ publicKey , $ algorithm );
69+ $ verify = openssl_verify ($ data , $ signature , $ publicKey , $ algorithm );
70+ if (false === $ verify ) {
71+ return -1 ;
72+ }
73+ return $ verify ;
6974 }
7075
7176 /**
@@ -88,13 +93,15 @@ public function callOnPublicKey(Closure $function)
8893 private static function callOnPublicKeyWithContents (Closure $ function , string $ publicKeyContents )
8994 {
9095 $ pubKey = openssl_get_publickey ($ publicKeyContents );
91- if (! is_resource ( $ pubKey) ) {
96+ if (false === $ pubKey ) {
9297 throw new RuntimeException ('Cannot open public key: ' . openssl_error_string ());
9398 }
9499 try {
95100 return call_user_func ($ function , $ pubKey );
96101 } finally {
97- openssl_free_key ($ pubKey );
102+ if (PHP_VERSION_ID < 80000 ) {
103+ openssl_free_key ($ pubKey );
104+ }
98105 }
99106 }
100107}
0 commit comments