Skip to content

Commit c05cbd1

Browse files
committed
ext/sodium: throw exceptions instead of errors
1 parent c219991 commit c05cbd1

File tree

1 file changed

+17
-15
lines changed

1 file changed

+17
-15
lines changed

ext/sodium/libsodium.c

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1853,11 +1853,13 @@ PHP_FUNCTION(sodium_crypto_pwhash)
18531853
return;
18541854
}
18551855
if (opslimit < crypto_pwhash_OPSLIMIT_MIN) {
1856-
zend_error(E_ERROR,
1857-
"number of operations for the password hashing function is too low");
1856+
zend_throw_exception(sodium_exception_ce,
1857+
"number of operations for the password hashing function is too low", 0);
1858+
return;
18581859
}
18591860
if (memlimit < crypto_pwhash_MEMLIMIT_MIN) {
1860-
zend_error(E_ERROR, "maximum memory for the password hashing function is too low");
1861+
zend_throw_exception(sodium_exception_ce,
1862+
"maximum memory for the password hashing function is too low", 0);
18611863
}
18621864
hash = zend_string_alloc((size_t) hash_len, 0);
18631865
ret = -1;
@@ -1916,12 +1918,12 @@ PHP_FUNCTION(sodium_crypto_pwhash_str)
19161918
zend_error(E_WARNING, "empty password");
19171919
}
19181920
if (opslimit < crypto_pwhash_OPSLIMIT_MIN) {
1919-
zend_error(E_ERROR,
1920-
"number of operations for the password hashing function is too low");
1921+
zend_throw_exception(sodium_exception_ce,
1922+
"number of operations for the password hashing function is too low", 0);
19211923
}
19221924
if (memlimit < crypto_pwhash_MEMLIMIT_MIN) {
1923-
zend_error(E_ERROR,
1924-
"maximum memory for the password hashing function is too low");
1925+
zend_throw_exception(sodium_exception_ce,
1926+
"maximum memory for the password hashing function is too low", 0);
19251927
}
19261928
hash_str = zend_string_alloc(crypto_pwhash_STRBYTES - 1, 0);
19271929
if (crypto_pwhash_str
@@ -2030,12 +2032,12 @@ PHP_FUNCTION(sodium_crypto_pwhash_scryptsalsa208sha256)
20302032
return;
20312033
}
20322034
if (opslimit < crypto_pwhash_scryptsalsa208sha256_OPSLIMIT_INTERACTIVE) {
2033-
zend_error(E_ERROR,
2034-
"number of operations for the scrypt function is too low");
2035+
zend_throw_exception(sodium_exception_ce,
2036+
"number of operations for the scrypt function is too low", 0);
20352037
}
20362038
if (memlimit < crypto_pwhash_scryptsalsa208sha256_MEMLIMIT_INTERACTIVE) {
2037-
zend_error(E_ERROR,
2038-
"maximum memory for the scrypt function is too low");
2039+
zend_throw_exception(sodium_exception_ce,
2040+
"maximum memory for the scrypt function is too low", 0);
20392041
}
20402042
hash = zend_string_alloc((size_t) hash_len, 0);
20412043
if (crypto_pwhash_scryptsalsa208sha256
@@ -2077,12 +2079,12 @@ PHP_FUNCTION(sodium_crypto_pwhash_scryptsalsa208sha256_str)
20772079
zend_error(E_WARNING, "empty password");
20782080
}
20792081
if (opslimit < crypto_pwhash_scryptsalsa208sha256_OPSLIMIT_INTERACTIVE) {
2080-
zend_error(E_ERROR,
2081-
"number of operations for the scrypt function is too low");
2082+
zend_throw_exception(sodium_exception_ce,
2083+
"number of operations for the scrypt function is too low", 0);
20822084
}
20832085
if (memlimit < crypto_pwhash_scryptsalsa208sha256_MEMLIMIT_INTERACTIVE) {
2084-
zend_error(E_ERROR,
2085-
"maximum memory for the scrypt function is too low");
2086+
zend_throw_exception(sodium_exception_ce,
2087+
"maximum memory for the scrypt function is too low", 0);
20862088
}
20872089
hash_str = zend_string_alloc
20882090
(crypto_pwhash_scryptsalsa208sha256_STRBYTES - 1, 0);

0 commit comments

Comments
 (0)