diff --git a/secp256k1/secp256k1.c b/secp256k1/secp256k1.c index a0c5cee9..3b9ac575 100755 --- a/secp256k1/secp256k1.c +++ b/secp256k1/secp256k1.c @@ -179,10 +179,14 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO(arginfo_secp256k1_ec_pubkey_negate, IS_LONG ZEND_ARG_TYPE_INFO(1, ecPublicKey, IS_RESOURCE, 0) ZEND_END_ARG_INFO(); -ZEND_BEGIN_ARG_INFO(arginfo_secp256k1_ec_privkey_tweak_add, 0) +#if (PHP_VERSION_ID >= 70000 && PHP_VERSION_ID <= 70200) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO(arginfo_secp256k1_ec_privkey_tweak_add, IS_LONG, NULL, 0) +#else +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO(arginfo_secp256k1_ec_privkey_tweak_add, IS_LONG, 0) +#endif ZEND_ARG_TYPE_INFO(0, context, IS_RESOURCE, 0) - ZEND_ARG_INFO(1, seckey) - ZEND_ARG_INFO(0, tweak32) + ZEND_ARG_TYPE_INFO(1, seckey, IS_STRING, 0) + ZEND_ARG_TYPE_INFO(0, tweak32, IS_STRING, 0) ZEND_END_ARG_INFO(); ZEND_BEGIN_ARG_INFO(arginfo_secp256k1_ec_pubkey_tweak_add, 0) @@ -191,10 +195,14 @@ ZEND_BEGIN_ARG_INFO(arginfo_secp256k1_ec_pubkey_tweak_add, 0) ZEND_ARG_INFO(0, tweak32) ZEND_END_ARG_INFO(); -ZEND_BEGIN_ARG_INFO(arginfo_secp256k1_ec_privkey_tweak_mul, 0) +#if (PHP_VERSION_ID >= 70000 && PHP_VERSION_ID <= 70200) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO(arginfo_secp256k1_ec_privkey_tweak_mul, IS_LONG, NULL, 0) +#else +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO(arginfo_secp256k1_ec_privkey_tweak_mul, IS_LONG, 0) +#endif ZEND_ARG_TYPE_INFO(0, context, IS_RESOURCE, 0) - ZEND_ARG_INFO(1, seckey) - ZEND_ARG_INFO(0, tweak32) + ZEND_ARG_TYPE_INFO(1, seckey, IS_STRING, 0) + ZEND_ARG_TYPE_INFO(0, tweak32, IS_STRING, 0) ZEND_END_ARG_INFO(); ZEND_BEGIN_ARG_INFO(arginfo_secp256k1_ec_pubkey_tweak_mul, 0) @@ -999,11 +1007,11 @@ PHP_FUNCTION(secp256k1_ec_privkey_tweak_add) int result = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rz/S", &zCtx, &zSecKey, &zTweak) == FAILURE) { - RETURN_FALSE; + RETURN_LONG(result); } if ((ctx = php_get_secp256k1_context(zCtx)) == NULL) { - RETURN_FALSE; + RETURN_LONG(result); } if (Z_TYPE_P(zSecKey) != IS_STRING) { @@ -1074,11 +1082,11 @@ PHP_FUNCTION(secp256k1_ec_privkey_tweak_mul) int result = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rz/S", &zCtx, &zSecKey, &zTweak) == FAILURE) { - RETURN_FALSE; + RETURN_LONG(result); } if ((ctx = php_get_secp256k1_context(zCtx)) == NULL) { - RETURN_FALSE; + RETURN_LONG(result); } if (Z_TYPE_P(zSecKey) != IS_STRING) { diff --git a/secp256k1/tests/secp256k1_ec_privkey_tweak_add_error2.phpt b/secp256k1/tests/secp256k1_ec_privkey_tweak_add_error2.phpt index c871685c..60afe7d9 100644 --- a/secp256k1/tests/secp256k1_ec_privkey_tweak_add_error2.phpt +++ b/secp256k1/tests/secp256k1_ec_privkey_tweak_add_error2.phpt @@ -14,11 +14,9 @@ $keyTweak = str_repeat("A", 32); $context = tmpfile(); $result = secp256k1_ec_privkey_tweak_add($context, $key, $keyTweak); -echo gettype($result) . PHP_EOL; -echo ($result ? "true" : "false") . PHP_EOL; +echo $result . PHP_EOL; ?> --EXPECT-- secp256k1_ec_privkey_tweak_add(): supplied resource is not a valid secp256k1_context resource -boolean -false \ No newline at end of file +0 \ No newline at end of file diff --git a/secp256k1/tests/secp256k1_ec_privkey_tweak_add_error3.phpt b/secp256k1/tests/secp256k1_ec_privkey_tweak_add_error3.phpt index 87206333..057fa42b 100644 --- a/secp256k1/tests/secp256k1_ec_privkey_tweak_add_error3.phpt +++ b/secp256k1/tests/secp256k1_ec_privkey_tweak_add_error3.phpt @@ -13,11 +13,9 @@ $key = str_repeat("A", 32); $keyTweak = str_repeat("A", 32); $result = secp256k1_ec_privkey_tweak_add(); -echo gettype($result) . PHP_EOL; -echo ($result ? "true" : "false") . PHP_EOL; +echo $result . PHP_EOL; ?> --EXPECT-- secp256k1_ec_privkey_tweak_add() expects exactly 3 parameters, 0 given -boolean -false \ No newline at end of file +0 \ No newline at end of file diff --git a/secp256k1/tests/secp256k1_ec_privkey_tweak_add_error4.phpt b/secp256k1/tests/secp256k1_ec_privkey_tweak_add_error4.phpt index 4abccb8c..9457c0d6 100644 --- a/secp256k1/tests/secp256k1_ec_privkey_tweak_add_error4.phpt +++ b/secp256k1/tests/secp256k1_ec_privkey_tweak_add_error4.phpt @@ -22,4 +22,4 @@ try { ?> --EXPECT-- -secp256k1_ec_privkey_tweak_add(): Parameter 2 should be string \ No newline at end of file +secp256k1_ec_privkey_tweak_add(): Parameter 2 should be 32 bytes \ No newline at end of file diff --git a/secp256k1/tests/secp256k1_ec_privkey_tweak_mul_error2.phpt b/secp256k1/tests/secp256k1_ec_privkey_tweak_mul_error2.phpt index a91ed720..909ed21b 100644 --- a/secp256k1/tests/secp256k1_ec_privkey_tweak_mul_error2.phpt +++ b/secp256k1/tests/secp256k1_ec_privkey_tweak_mul_error2.phpt @@ -14,11 +14,8 @@ $keyTweak = str_repeat("A", 32); $context = tmpfile(); $result = secp256k1_ec_privkey_tweak_mul($context, $key, $keyTweak); -echo gettype($result) . PHP_EOL; -echo ($result ? "true" : "false") . PHP_EOL; - +echo $result . PHP_EOL; ?> --EXPECT-- secp256k1_ec_privkey_tweak_mul(): supplied resource is not a valid secp256k1_context resource -boolean -false \ No newline at end of file +0 \ No newline at end of file diff --git a/secp256k1/tests/secp256k1_ec_privkey_tweak_mul_error3.phpt b/secp256k1/tests/secp256k1_ec_privkey_tweak_mul_error3.phpt index a1fe1825..40dd2ef1 100644 --- a/secp256k1/tests/secp256k1_ec_privkey_tweak_mul_error3.phpt +++ b/secp256k1/tests/secp256k1_ec_privkey_tweak_mul_error3.phpt @@ -10,11 +10,9 @@ if (!extension_loaded("secp256k1")) print "skip extension not loaded"; set_error_handler(function($code, $str) { echo $str . PHP_EOL; }); $result = secp256k1_ec_privkey_tweak_mul(); -echo gettype($result) . PHP_EOL; -echo ($result ? "true" : "false") . PHP_EOL; +echo $result . PHP_EOL; ?> --EXPECT-- secp256k1_ec_privkey_tweak_mul() expects exactly 3 parameters, 0 given -boolean -false \ No newline at end of file +0 \ No newline at end of file diff --git a/secp256k1/tests/secp256k1_ec_privkey_tweak_mul_error4.phpt b/secp256k1/tests/secp256k1_ec_privkey_tweak_mul_error4.phpt index d4969c60..770c8f04 100644 --- a/secp256k1/tests/secp256k1_ec_privkey_tweak_mul_error4.phpt +++ b/secp256k1/tests/secp256k1_ec_privkey_tweak_mul_error4.phpt @@ -7,8 +7,6 @@ if (!extension_loaded("secp256k1")) print "skip extension not loaded"; --FILE-- --EXPECT-- -secp256k1_ec_privkey_tweak_mul(): Parameter 2 should be string \ No newline at end of file +secp256k1_ec_privkey_tweak_mul(): Parameter 2 should be 32 bytes \ No newline at end of file diff --git a/tests/Secp256k1PrivkeyTweakAddTest.php b/tests/Secp256k1PrivkeyTweakAddTest.php index 1f8d397a..22133c05 100644 --- a/tests/Secp256k1PrivkeyTweakAddTest.php +++ b/tests/Secp256k1PrivkeyTweakAddTest.php @@ -37,40 +37,4 @@ public function testTweaksPrivateKeyAdd($context, $privkey, $tweak, $expectedTwe $this->assertEquals($privkey, $expectedTweaked); } - - public function getErroneousTypeVectors() - { - $context = TestCase::getContext(); - $tweak = $this->pack('0af79b2b747548d59a4a765fb73a72bc4208d00b43d0606c13d332d5c284b0ef'); - $privateKey = $this->pack('0af79b2b747548d59a4a765fb73a72bc4208d00b43d0606c13d332d5c284b0ef'); - - $array = array(); - $class = new self; - $resource = openssl_pkey_new(); - - return array( - array($context, $privateKey, $array), - array($context, $privateKey, $resource), - array($context, $privateKey, $class) - ); - } - - /** - * @dataProvider getErroneousTypeVectors - * @expectedException \PHPUnit\Framework\Error\Warning - */ - public function testErroneousTypes($context, $seckey, $tweak) - { - $r = \secp256k1_ec_privkey_tweak_add($context, $seckey, $tweak); - }/**/ - - /** - * @expectedException \Exception - */ - public function testEnforceZvalString() - { - $tweak = $this->pack('0af79b2b747548d59a4a765fb73a72bc4208d00b43d0606c13d332d5c284b0ef'); - $privateKey = array(); - \secp256k1_ec_privkey_tweak_add(TestCase::getContext(), $privateKey, $tweak); - } } diff --git a/tests/Secp256k1PrivkeyTweakMulTest.php b/tests/Secp256k1PrivkeyTweakMulTest.php index fb1cfc9f..7022614c 100644 --- a/tests/Secp256k1PrivkeyTweakMulTest.php +++ b/tests/Secp256k1PrivkeyTweakMulTest.php @@ -34,40 +34,5 @@ public function testTweaksPrivatekeyMul($context, $privkey, $tweak, $expectedTwe $result = secp256k1_ec_privkey_tweak_mul($context, $privkey, $tweak); $this->assertEquals(1, $result); $this->assertEquals($privkey, $expectedTweaked); - - } - - - public function getErroneousTypeVectors() - { - $context = TestCase::getContext(); - $tweak = $this->pack('0af79b2b747548d59a4a765fb73a72bc4208d00b43d0606c13d332d5c284b0ef'); - $privateKey = $this->pack('0af79b2b747548d59a4a765fb73a72bc4208d00b43d0606c13d332d5c284b0ef'); - $array = array(); - $class = new self; - $resource = openssl_pkey_new(); - return array( - // We only test the second parameter here, first is a Zval - array($context, $privateKey, $array), - array($context, $privateKey, $resource), - array($context, $privateKey, $class) - ); - } - /** - * @dataProvider getErroneousTypeVectors - * @expectedException \PHPUnit\Framework\Error\Warning - */ - public function testErroneousTypes($context, $seckey, $tweak) - { - $r = \secp256k1_ec_privkey_tweak_mul($context, $seckey, $tweak); - }/**/ - /** - * @expectedException \Exception - */ - public function testEnforceZvalString() - { - $tweak = $this->pack('0af79b2b747548d59a4a765fb73a72bc4208d00b43d0606c13d332d5c284b0ef'); - $privateKey = array(); - \secp256k1_ec_privkey_tweak_mul(TestCase::getContext(), $privateKey, $tweak); } }