summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--libsodium-php7.patch674
-rw-r--r--php-pecl-libsodium.spec7
2 files changed, 680 insertions, 1 deletions
diff --git a/libsodium-php7.patch b/libsodium-php7.patch
new file mode 100644
index 0000000..cf2ee34
--- /dev/null
+++ b/libsodium-php7.patch
@@ -0,0 +1,674 @@
+From ffcea7064a37e03ed8c0497a23580936bf0ebd3d Mon Sep 17 00:00:00 2001
+From: Remi Collet <fedora@famillecollet.com>
+Date: Thu, 2 Apr 2015 18:40:41 +0200
+Subject: [PATCH 1/2] fix PHP 7 compatibility
+
+---
+ libsodium.c | 224 +++++++++++++++++++++++++++++---------------------------
+ package.xml | 1 -
+ php_libsodium.h | 12 +++
+ run-tests.php | 25 ++++---
+ 4 files changed, 143 insertions(+), 119 deletions(-)
+
+diff --git a/libsodium.c b/libsodium.c
+index 7480404..6da5245 100644
+--- a/libsodium.c
++++ b/libsodium.c
+@@ -274,7 +274,7 @@ PHP_MINFO_FUNCTION(libsodium)
+
+ PHP_METHOD(Sodium, sodium_version_string)
+ {
+- RETURN_STRING(sodium_version_string(), 1);
++ _RETURN_STRING(sodium_version_string());
+ }
+
+ PHP_METHOD(Sodium, sodium_library_version_major)
+@@ -291,12 +291,18 @@ PHP_METHOD(Sodium, sodium_memzero)
+ {
+ zval *zv;
+ char *buf;
+- int len;
++ strsize_t len;
+
+- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
+- "z", &zv) == FAILURE ||
+- Z_TYPE_P(zv) != IS_STRING) {
+- zend_error(E_ERROR, "sodium_memzero: a PHP string is required");
++ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &zv) == FAILURE) {
++ return;
++ }
++#if PHP_MAJOR_VERSION >= 7
++ if (Z_TYPE_P(zv) == IS_REFERENCE) {
++ ZVAL_DEREF(zv);
++ }
++#endif
++ if (Z_TYPE_P(zv) != IS_STRING) {
++ zend_error(E_ERROR, "sodium_memzero: a PHP string is required") ;
+ }
+ buf = Z_STRVAL(*zv);
+ len = Z_STRLEN(*zv);
+@@ -310,8 +316,8 @@ PHP_METHOD(Sodium, sodium_memcmp)
+ {
+ char *buf1;
+ char *buf2;
+- int len1;
+- int len2;
++ strsize_t len1;
++ strsize_t len2;
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss",
+ &buf1, &len1,
+@@ -330,7 +336,7 @@ PHP_METHOD(Sodium, sodium_memcmp)
+ PHP_METHOD(Sodium, randombytes_buf)
+ {
+ char *buf;
+- long len;
++ zend_long len;
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l",
+ &len) == FAILURE ||
+@@ -341,7 +347,7 @@ PHP_METHOD(Sodium, randombytes_buf)
+ randombytes_buf(buf, (size_t) len);
+ buf[len] = 0U;
+
+- RETURN_STRINGL(buf, (int) len, 0);
++ _RETURN_STRINGL(buf, (int) len);
+ }
+
+ PHP_METHOD(Sodium, randombytes_random16)
+@@ -351,7 +357,7 @@ PHP_METHOD(Sodium, randombytes_random16)
+
+ PHP_METHOD(Sodium, randombytes_uniform)
+ {
+- long upper_bound;
++ zend_long upper_bound;
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l",
+ &upper_bound) == FAILURE ||
+@@ -366,8 +372,8 @@ PHP_METHOD(Sodium, crypto_shorthash)
+ unsigned char *hash;
+ unsigned char *key;
+ unsigned char *msg;
+- int key_len;
+- int msg_len;
++ strsize_t key_len;
++ strsize_t msg_len;
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss",
+ &msg, &msg_len,
+@@ -386,7 +392,7 @@ PHP_METHOD(Sodium, crypto_shorthash)
+ }
+ hash[crypto_shorthash_BYTES] = 0U;
+
+- RETURN_STRINGL((char *) hash, crypto_shorthash_BYTES, 0);
++ _RETURN_STRINGL((char *) hash, crypto_shorthash_BYTES);
+ }
+
+ PHP_METHOD(Sodium, crypto_secretbox)
+@@ -395,9 +401,9 @@ PHP_METHOD(Sodium, crypto_secretbox)
+ unsigned char *key;
+ unsigned char *msg;
+ unsigned char *nonce;
+- int key_len;
+- int msg_len;
+- int nonce_len;
++ strsize_t key_len;
++ strsize_t msg_len;
++ strsize_t nonce_len;
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sss",
+ &msg, &msg_len,
+@@ -427,7 +433,7 @@ PHP_METHOD(Sodium, crypto_secretbox)
+ }
+ ciphertext[msg_len + crypto_secretbox_MACBYTES] = 0U;
+
+- RETURN_STRINGL((char *) ciphertext, msg_len + crypto_secretbox_MACBYTES, 0);
++ _RETURN_STRINGL((char *) ciphertext, msg_len + crypto_secretbox_MACBYTES);
+ }
+
+ PHP_METHOD(Sodium, crypto_secretbox_open)
+@@ -436,9 +442,9 @@ PHP_METHOD(Sodium, crypto_secretbox_open)
+ unsigned char *ciphertext;
+ unsigned char *msg;
+ unsigned char *nonce;
+- int key_len;
+- int ciphertext_len;
+- int nonce_len;
++ strsize_t key_len;
++ strsize_t ciphertext_len;
++ strsize_t nonce_len;
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sss",
+ &ciphertext, &ciphertext_len,
+@@ -469,8 +475,8 @@ PHP_METHOD(Sodium, crypto_secretbox_open)
+ RETURN_FALSE;
+ } else {
+ msg[ciphertext_len - crypto_secretbox_MACBYTES] = 0U;
+- RETURN_STRINGL((char *) msg,
+- ciphertext_len - crypto_secretbox_MACBYTES, 0);
++ _RETURN_STRINGL((char *) msg,
++ ciphertext_len - crypto_secretbox_MACBYTES);
+ }
+ }
+
+@@ -479,9 +485,9 @@ PHP_METHOD(Sodium, crypto_generichash)
+ unsigned char *hash;
+ unsigned char *key = NULL;
+ unsigned char *msg;
+- long hash_len = crypto_generichash_BYTES;
+- int key_len = 0;
+- int msg_len;
++ zend_long hash_len = crypto_generichash_BYTES;
++ strsize_t key_len = 0;
++ strsize_t msg_len;
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|sl",
+ &msg, &msg_len,
+@@ -507,7 +513,7 @@ PHP_METHOD(Sodium, crypto_generichash)
+ }
+ hash[hash_len] = 0U;
+
+- RETURN_STRINGL((char *) hash, (int) hash_len, 0);
++ _RETURN_STRINGL((char *) hash, (int) hash_len);
+ }
+
+ PHP_METHOD(Sodium, crypto_box_keypair)
+@@ -524,7 +530,7 @@ PHP_METHOD(Sodium, crypto_box_keypair)
+ }
+ keypair[keypair_len] = 0U;
+
+- RETURN_STRINGL((char *) keypair, (int) keypair_len, 0);
++ _RETURN_STRINGL((char *) keypair, (int) keypair_len);
+ }
+
+ PHP_METHOD(Sodium, crypto_box_keypair_from_secretkey_and_publickey)
+@@ -533,8 +539,8 @@ PHP_METHOD(Sodium, crypto_box_keypair_from_secretkey_and_publickey)
+ char *publickey;
+ char *secretkey;
+ size_t keypair_len;
+- int publickey_len;
+- int secretkey_len;
++ strsize_t publickey_len;
++ strsize_t secretkey_len;
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss",
+ &secretkey, &secretkey_len,
+@@ -558,14 +564,14 @@ PHP_METHOD(Sodium, crypto_box_keypair_from_secretkey_and_publickey)
+ crypto_box_PUBLICKEYBYTES);
+ keypair[keypair_len] = 0U;
+
+- RETURN_STRINGL(keypair, (int) keypair_len, 0);
++ _RETURN_STRINGL(keypair, (int) keypair_len);
+ }
+
+ PHP_METHOD(Sodium, crypto_box_secretkey)
+ {
+ unsigned char *keypair;
+ char *secretkey;
+- int keypair_len;
++ strsize_t keypair_len;
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s",
+ &keypair, &keypair_len) == FAILURE) {
+@@ -581,14 +587,14 @@ PHP_METHOD(Sodium, crypto_box_secretkey)
+ memcpy(secretkey, keypair, crypto_box_SECRETKEYBYTES);
+ secretkey[crypto_box_SECRETKEYBYTES] = 0U;
+
+- RETURN_STRINGL((char *) secretkey, crypto_box_SECRETKEYBYTES, 0);
++ _RETURN_STRINGL((char *) secretkey, crypto_box_SECRETKEYBYTES);
+ }
+
+ PHP_METHOD(Sodium, crypto_box_publickey)
+ {
+ unsigned char *keypair;
+ char *publickey;
+- int keypair_len;
++ strsize_t keypair_len;
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s",
+ &keypair, &keypair_len) == FAILURE) {
+@@ -605,14 +611,14 @@ PHP_METHOD(Sodium, crypto_box_publickey)
+ crypto_box_PUBLICKEYBYTES);
+ publickey[crypto_box_PUBLICKEYBYTES] = 0U;
+
+- RETURN_STRINGL((char *) publickey, crypto_box_PUBLICKEYBYTES, 0);
++ _RETURN_STRINGL((char *) publickey, crypto_box_PUBLICKEYBYTES);
+ }
+
+ PHP_METHOD(Sodium, crypto_box_publickey_from_secretkey)
+ {
+ unsigned char *publickey;
+ unsigned char *secretkey;
+- int secretkey_len;
++ strsize_t secretkey_len;
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s",
+ &secretkey, &secretkey_len) == FAILURE) {
+@@ -631,7 +637,7 @@ PHP_METHOD(Sodium, crypto_box_publickey_from_secretkey)
+ crypto_scalarmult_base(publickey, secretkey);
+ publickey[crypto_box_PUBLICKEYBYTES] = 0U;
+
+- RETURN_STRINGL((char *) publickey, crypto_box_PUBLICKEYBYTES, 0);
++ _RETURN_STRINGL((char *) publickey, crypto_box_PUBLICKEYBYTES);
+ }
+
+ PHP_METHOD(Sodium, crypto_box)
+@@ -642,9 +648,9 @@ PHP_METHOD(Sodium, crypto_box)
+ unsigned char *nonce;
+ unsigned char *publickey;
+ unsigned char *secretkey;
+- int keypair_len;
+- int msg_len;
+- int nonce_len;
++ strsize_t keypair_len;
++ strsize_t msg_len;
++ strsize_t nonce_len;
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sss",
+ &msg, &msg_len,
+@@ -675,7 +681,7 @@ PHP_METHOD(Sodium, crypto_box)
+ }
+ ciphertext[msg_len + crypto_box_MACBYTES] = 0U;
+
+- RETURN_STRINGL((char *) ciphertext, msg_len + crypto_box_MACBYTES, 0);
++ _RETURN_STRINGL((char *) ciphertext, msg_len + crypto_box_MACBYTES);
+ }
+
+ PHP_METHOD(Sodium, crypto_box_open)
+@@ -686,9 +692,9 @@ PHP_METHOD(Sodium, crypto_box_open)
+ unsigned char *nonce;
+ unsigned char *publickey;
+ unsigned char *secretkey;
+- int ciphertext_len;
+- int keypair_len;
+- int nonce_len;
++ strsize_t ciphertext_len;
++ strsize_t keypair_len;
++ strsize_t nonce_len;
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sss",
+ &ciphertext, &ciphertext_len,
+@@ -721,8 +727,8 @@ PHP_METHOD(Sodium, crypto_box_open)
+ RETURN_FALSE;
+ } else {
+ msg[ciphertext_len - crypto_box_MACBYTES] = 0U;
+- RETURN_STRINGL((char *) msg,
+- ciphertext_len - crypto_box_MACBYTES, 0);
++ _RETURN_STRINGL((char *) msg,
++ ciphertext_len - crypto_box_MACBYTES);
+ }
+ }
+
+@@ -740,7 +746,7 @@ PHP_METHOD(Sodium, crypto_sign_keypair)
+ }
+ keypair[keypair_len] = 0U;
+
+- RETURN_STRINGL((char *) keypair, keypair_len, 0);
++ _RETURN_STRINGL((char *) keypair, keypair_len);
+ }
+
+ PHP_METHOD(Sodium, crypto_sign_seed_keypair)
+@@ -748,7 +754,7 @@ PHP_METHOD(Sodium, crypto_sign_seed_keypair)
+ unsigned char *keypair;
+ unsigned char *seed;
+ size_t keypair_len;
+- int seed_len;
++ strsize_t seed_len;
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s",
+ &seed, &seed_len) == FAILURE) {
+@@ -768,7 +774,7 @@ PHP_METHOD(Sodium, crypto_sign_seed_keypair)
+ }
+ keypair[keypair_len] = 0U;
+
+- RETURN_STRINGL((char *) keypair, keypair_len, 0);
++ _RETURN_STRINGL((char *) keypair, keypair_len);
+ }
+
+ PHP_METHOD(Sodium, crypto_sign_keypair_from_secretkey_and_publickey)
+@@ -777,8 +783,8 @@ PHP_METHOD(Sodium, crypto_sign_keypair_from_secretkey_and_publickey)
+ char *publickey;
+ char *secretkey;
+ size_t keypair_len;
+- int publickey_len;
+- int secretkey_len;
++ strsize_t publickey_len;
++ strsize_t secretkey_len;
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss",
+ &secretkey, &secretkey_len,
+@@ -802,14 +808,14 @@ PHP_METHOD(Sodium, crypto_sign_keypair_from_secretkey_and_publickey)
+ crypto_sign_PUBLICKEYBYTES);
+ keypair[keypair_len] = 0U;
+
+- RETURN_STRINGL(keypair, keypair_len, 0);
++ _RETURN_STRINGL(keypair, keypair_len);
+ }
+
+ PHP_METHOD(Sodium, crypto_sign_secretkey)
+ {
+ unsigned char *keypair;
+ char *secretkey;
+- int keypair_len;
++ strsize_t keypair_len;
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s",
+ &keypair, &keypair_len) == FAILURE) {
+@@ -825,14 +831,14 @@ PHP_METHOD(Sodium, crypto_sign_secretkey)
+ memcpy(secretkey, keypair, crypto_sign_SECRETKEYBYTES);
+ secretkey[crypto_sign_SECRETKEYBYTES] = 0U;
+
+- RETURN_STRINGL((char *) secretkey, crypto_sign_SECRETKEYBYTES, 0);
++ _RETURN_STRINGL((char *) secretkey, crypto_sign_SECRETKEYBYTES);
+ }
+
+ PHP_METHOD(Sodium, crypto_sign_publickey)
+ {
+ unsigned char *keypair;
+ char *publickey;
+- int keypair_len;
++ strsize_t keypair_len;
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s",
+ &keypair, &keypair_len) == FAILURE) {
+@@ -849,7 +855,7 @@ PHP_METHOD(Sodium, crypto_sign_publickey)
+ crypto_sign_PUBLICKEYBYTES);
+ publickey[crypto_sign_PUBLICKEYBYTES] = 0U;
+
+- RETURN_STRINGL((char *) publickey, crypto_sign_PUBLICKEYBYTES, 0);
++ _RETURN_STRINGL((char *) publickey, crypto_sign_PUBLICKEYBYTES);
+ }
+
+ PHP_METHOD(Sodium, crypto_sign)
+@@ -858,9 +864,9 @@ PHP_METHOD(Sodium, crypto_sign)
+ unsigned char *msg_signed;
+ unsigned char *secretkey;
+ unsigned long long msg_signed_real_len;
+- int msg_len;
+- int msg_signed_len;
+- int secretkey_len;
++ strsize_t msg_len;
++ strsize_t msg_signed_len;
++ strsize_t secretkey_len;
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss",
+ &msg, &msg_len,
+@@ -889,7 +895,7 @@ PHP_METHOD(Sodium, crypto_sign)
+ }
+ msg_signed[msg_signed_real_len] = 0U;
+
+- RETURN_STRINGL((char *) msg_signed, (int) msg_signed_real_len, 0);
++ _RETURN_STRINGL((char *) msg_signed, (int) msg_signed_real_len);
+ }
+
+ PHP_METHOD(Sodium, crypto_sign_open)
+@@ -898,9 +904,9 @@ PHP_METHOD(Sodium, crypto_sign_open)
+ unsigned char *msg_signed;
+ unsigned char *publickey;
+ unsigned long long msg_real_len;
+- int msg_len;
+- int msg_signed_len;
+- int publickey_len;
++ strsize_t msg_len;
++ strsize_t msg_signed_len;
++ strsize_t publickey_len;
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss",
+ &msg_signed, &msg_signed_len,
+@@ -930,7 +936,7 @@ PHP_METHOD(Sodium, crypto_sign_open)
+ }
+ msg[msg_real_len] = 0U;
+
+- RETURN_STRINGL((char *) msg, (int) msg_real_len, 0);
++ _RETURN_STRINGL((char *) msg, (int) msg_real_len);
+ }
+
+ PHP_METHOD(Sodium, crypto_sign_detached)
+@@ -939,8 +945,8 @@ PHP_METHOD(Sodium, crypto_sign_detached)
+ unsigned char *signature;
+ unsigned char *secretkey;
+ unsigned long long signature_real_len;
+- int msg_len;
+- int secretkey_len;
++ strsize_t msg_len;
++ strsize_t secretkey_len;
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss",
+ &msg, &msg_len,
+@@ -964,7 +970,7 @@ PHP_METHOD(Sodium, crypto_sign_detached)
+ }
+ signature[signature_real_len] = 0U;
+
+- RETURN_STRINGL((char *) signature, (int) signature_real_len, 0);
++ _RETURN_STRINGL((char *) signature, (int) signature_real_len);
+ }
+
+ PHP_METHOD(Sodium, crypto_sign_verify_detached)
+@@ -972,9 +978,9 @@ PHP_METHOD(Sodium, crypto_sign_verify_detached)
+ unsigned char *msg;
+ unsigned char *publickey;
+ unsigned char *signature;
+- int msg_len;
+- int publickey_len;
+- int signature_len;
++ strsize_t msg_len;
++ strsize_t publickey_len;
++ strsize_t signature_len;
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sss",
+ &signature, &signature_len,
+@@ -1005,9 +1011,9 @@ PHP_METHOD(Sodium, crypto_stream)
+ unsigned char *ciphertext;
+ unsigned char *key;
+ unsigned char *nonce;
+- long ciphertext_len;
+- int key_len;
+- int nonce_len;
++ zend_long ciphertext_len;
++ strsize_t key_len;
++ strsize_t nonce_len;
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lss",
+ &ciphertext_len,
+@@ -1032,7 +1038,7 @@ PHP_METHOD(Sodium, crypto_stream)
+ }
+ ciphertext[ciphertext_len] = 0U;
+
+- RETURN_STRINGL((char *) ciphertext, ciphertext_len, 0);
++ _RETURN_STRINGL((char *) ciphertext, ciphertext_len);
+ }
+
+ PHP_METHOD(Sodium, crypto_stream_xor)
+@@ -1041,9 +1047,9 @@ PHP_METHOD(Sodium, crypto_stream_xor)
+ unsigned char *key;
+ unsigned char *msg;
+ unsigned char *nonce;
+- int key_len;
+- int msg_len;
+- int nonce_len;
++ strsize_t key_len;
++ strsize_t msg_len;
++ strsize_t nonce_len;
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sss",
+ &msg, &msg_len,
+@@ -1065,7 +1071,7 @@ PHP_METHOD(Sodium, crypto_stream_xor)
+ }
+ ciphertext[msg_len] = 0U;
+
+- RETURN_STRINGL((char *) ciphertext, msg_len, 0);
++ _RETURN_STRINGL((char *) ciphertext, msg_len);
+ }
+
+ PHP_METHOD(Sodium, crypto_pwhash_scryptsalsa208sha256)
+@@ -1073,11 +1079,11 @@ PHP_METHOD(Sodium, crypto_pwhash_scryptsalsa208sha256)
+ unsigned char *hash;
+ unsigned char *salt;
+ char *passwd;
+- long hash_len;
+- long memlimit;
+- long opslimit;
+- int passwd_len;
+- int salt_len;
++ zend_long hash_len;
++ zend_long memlimit;
++ zend_long opslimit;
++ strsize_t passwd_len;
++ strsize_t salt_len;
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lssll",
+ &hash_len,
+@@ -1113,16 +1119,16 @@ PHP_METHOD(Sodium, crypto_pwhash_scryptsalsa208sha256)
+ }
+ hash[hash_len] = 0U;
+
+- RETURN_STRINGL((char *) hash, hash_len, 0);
++ _RETURN_STRINGL((char *) hash, hash_len);
+ }
+
+ PHP_METHOD(Sodium, crypto_pwhash_scryptsalsa208sha256_str)
+ {
+ char *hash_str;
+ char *passwd;
+- long memlimit;
+- long opslimit;
+- int passwd_len;
++ zend_long memlimit;
++ zend_long opslimit;
++ strsize_t passwd_len;
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sll",
+ &passwd, &passwd_len,
+@@ -1152,16 +1158,16 @@ PHP_METHOD(Sodium, crypto_pwhash_scryptsalsa208sha256_str)
+ }
+ hash_str[crypto_pwhash_scryptsalsa208sha256_STRBYTES] = 0U;
+
+- RETURN_STRINGL((char *) hash_str,
+- crypto_pwhash_scryptsalsa208sha256_STRBYTES - 1, 0);
++ _RETURN_STRINGL((char *) hash_str,
++ crypto_pwhash_scryptsalsa208sha256_STRBYTES - 1);
+ }
+
+ PHP_METHOD(Sodium, crypto_pwhash_scryptsalsa208sha256_str_verify)
+ {
+ char *hash_str;
+ char *passwd;
+- int hash_str_len;
+- int passwd_len;
++ strsize_t hash_str_len;
++ strsize_t passwd_len;
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss",
+ &hash_str, &hash_str_len,
+@@ -1191,11 +1197,11 @@ PHP_METHOD(Sodium, crypto_aead_chacha20poly1305_encrypt)
+ unsigned char *npub;
+ unsigned char *secretkey;
+ unsigned long long ciphertext_real_len;
+- int ad_len;
+- int ciphertext_len;
+- int msg_len;
+- int npub_len;
+- int secretkey_len;
++ strsize_t ad_len;
++ strsize_t ciphertext_len;
++ strsize_t msg_len;
++ strsize_t npub_len;
++ strsize_t secretkey_len;
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ssss",
+ &msg, &msg_len,
+@@ -1234,7 +1240,7 @@ PHP_METHOD(Sodium, crypto_aead_chacha20poly1305_encrypt)
+ }
+ ciphertext[ciphertext_real_len] = 0U;
+
+- RETURN_STRINGL((char *) ciphertext, (int) ciphertext_real_len, 0);
++ _RETURN_STRINGL((char *) ciphertext, (int) ciphertext_real_len);
+ }
+
+ PHP_METHOD(Sodium, crypto_aead_chacha20poly1305_decrypt)
+@@ -1245,11 +1251,11 @@ PHP_METHOD(Sodium, crypto_aead_chacha20poly1305_decrypt)
+ unsigned char *npub;
+ unsigned char *secretkey;
+ unsigned long long msg_real_len;
+- int ad_len;
+- int ciphertext_len;
+- int msg_len;
+- int npub_len;
+- int secretkey_len;
++ strsize_t ad_len;
++ strsize_t ciphertext_len;
++ strsize_t msg_len;
++ strsize_t npub_len;
++ strsize_t secretkey_len;
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ssss",
+ &ciphertext, &ciphertext_len,
+@@ -1288,15 +1294,15 @@ PHP_METHOD(Sodium, crypto_aead_chacha20poly1305_decrypt)
+ }
+ msg[msg_real_len] = 0U;
+
+- RETURN_STRINGL((char *) msg, (int) msg_real_len, 0);
++ _RETURN_STRINGL((char *) msg, (int) msg_real_len);
+ }
+
+ PHP_METHOD(Sodium, sodium_bin2hex)
+ {
+ unsigned char *bin;
+ char *hex;
+- int bin_len;
+- int hex_len;
++ strsize_t bin_len;
++ strsize_t hex_len;
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s",
+ &bin, &bin_len) == FAILURE) {
+@@ -1309,7 +1315,7 @@ PHP_METHOD(Sodium, sodium_bin2hex)
+ hex = safe_emalloc((size_t) hex_len + 1U, 1U, 0U);
+ sodium_bin2hex(hex, hex_len + 1U, bin, bin_len);
+
+- RETURN_STRINGL(hex, hex_len, 0);
++ _RETURN_STRINGL(hex, hex_len);
+ }
+
+ PHP_METHOD(Sodium, sodium_hex2bin)
+@@ -1319,8 +1325,8 @@ PHP_METHOD(Sodium, sodium_hex2bin)
+ char *ignore = NULL;
+ size_t bin_real_len;
+ size_t bin_len;
+- int hex_len;
+- int ignore_len = 0;
++ strsize_t hex_len;
++ strsize_t ignore_len = 0;
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|s",
+ &hex, &hex_len,
+@@ -1336,5 +1342,5 @@ PHP_METHOD(Sodium, sodium_hex2bin)
+ }
+ bin[bin_real_len] = 0U;
+
+- RETURN_STRINGL((char *) bin, (int) bin_real_len, 0);
++ _RETURN_STRINGL((char *) bin, (int) bin_real_len);
+ }
+diff --git a/php_libsodium.h b/php_libsodium.h
+index 4038dfd..ae4f9b6 100644
+--- a/php_libsodium.h
++++ b/php_libsodium.h
+@@ -69,6 +69,18 @@ PHP_METHOD(Sodium, sodium_version_string);
+ #define LIBSODIUM_G(v) (libsodium_globals.v)
+ #endif
+
++#if PHP_MAJOR_VERSION < 7
++typedef long zend_long;
++typedef int strsize_t;
++#define _RETURN_STRING(a) RETURN_STRING(a,1)
++#define _RETURN_STRINGL(a,l) RETURN_STRINGL(a,l,0)
++#else
++typedef size_t strsize_t;
++#define TSRMLS_CC
++#define _RETURN_STRING(a) RETURN_STRING(a)
++#define _RETURN_STRINGL(a,l) { RETVAL_STRINGL(a, l); efree(a); return; }
++#endif
++
+ #endif /* PHP_LIBSODIUM_H */
+
+ /*
diff --git a/php-pecl-libsodium.spec b/php-pecl-libsodium.spec
index 9485218..96cb0f3 100644
--- a/php-pecl-libsodium.spec
+++ b/php-pecl-libsodium.spec
@@ -30,6 +30,7 @@ URL: http://pecl.php.net/package/%{pecl_name}
Source0: http://pecl.php.net/get/%{pecl_name}-%{version}.tgz
Patch0: %{pecl_name}-build.patch
+Patch1: %{pecl_name}-php7.patch
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
%if "%{?vendor}" == "Remi Collet"
@@ -89,6 +90,9 @@ sed -e '/role="test"/d' -i package.xml
cd NTS
%patch0 -p1 -b .fix
+%if "%{php_version}" > "7"
+%patch1 -p1 -b .php7
+%endif
# Sanity check, really often broken
extver=$(sed -n '/#define PHP_LIBSODIUM_VERSION/{s/.* "//;s/".*$//;p}' php_libsodium.h)
@@ -224,7 +228,8 @@ rm -rf %{buildroot}
* Thu Apr 02 2015 Remi Collet <remi@fedoraproject.org> - 0.1.2-1
- Update to 0.1.2
- drop runtime dependency on pear, new scriptlets
-- open https://github.com/jedisct1/libsodium-php/pull/22
+- open https://github.com/jedisct1/libsodium-php/pull/22 - build
+- open https://github.com/jedisct1/libsodium-php/pull/23 - php 7
* Wed Dec 24 2014 Remi Collet <remi@fedoraproject.org> - 0.1.1-1.1
- Fedora 21 SCL mass rebuild