Skip to content

Commit

Permalink
ext/sodium: throw exceptions instead of errors
Browse files Browse the repository at this point in the history
  • Loading branch information
jedisct1 committed Nov 28, 2017
1 parent c219991 commit c05cbd1
Showing 1 changed file with 17 additions and 15 deletions.
32 changes: 17 additions & 15 deletions ext/sodium/libsodium.c
Original file line number Diff line number Diff line change
Expand Up @@ -1853,11 +1853,13 @@ PHP_FUNCTION(sodium_crypto_pwhash)
return;
}
if (opslimit < crypto_pwhash_OPSLIMIT_MIN) {
zend_error(E_ERROR,
"number of operations for the password hashing function is too low");
zend_throw_exception(sodium_exception_ce,
"number of operations for the password hashing function is too low", 0);
return;
}
if (memlimit < crypto_pwhash_MEMLIMIT_MIN) {
zend_error(E_ERROR, "maximum memory for the password hashing function is too low");
zend_throw_exception(sodium_exception_ce,
"maximum memory for the password hashing function is too low", 0);
}
hash = zend_string_alloc((size_t) hash_len, 0);
ret = -1;
Expand Down Expand Up @@ -1916,12 +1918,12 @@ PHP_FUNCTION(sodium_crypto_pwhash_str)
zend_error(E_WARNING, "empty password");
}
if (opslimit < crypto_pwhash_OPSLIMIT_MIN) {
zend_error(E_ERROR,
"number of operations for the password hashing function is too low");
zend_throw_exception(sodium_exception_ce,
"number of operations for the password hashing function is too low", 0);
}
if (memlimit < crypto_pwhash_MEMLIMIT_MIN) {
zend_error(E_ERROR,
"maximum memory for the password hashing function is too low");
zend_throw_exception(sodium_exception_ce,
"maximum memory for the password hashing function is too low", 0);
}
hash_str = zend_string_alloc(crypto_pwhash_STRBYTES - 1, 0);
if (crypto_pwhash_str
Expand Down Expand Up @@ -2030,12 +2032,12 @@ PHP_FUNCTION(sodium_crypto_pwhash_scryptsalsa208sha256)
return;
}
if (opslimit < crypto_pwhash_scryptsalsa208sha256_OPSLIMIT_INTERACTIVE) {
zend_error(E_ERROR,
"number of operations for the scrypt function is too low");
zend_throw_exception(sodium_exception_ce,
"number of operations for the scrypt function is too low", 0);
}
if (memlimit < crypto_pwhash_scryptsalsa208sha256_MEMLIMIT_INTERACTIVE) {
zend_error(E_ERROR,
"maximum memory for the scrypt function is too low");
zend_throw_exception(sodium_exception_ce,
"maximum memory for the scrypt function is too low", 0);
}
hash = zend_string_alloc((size_t) hash_len, 0);
if (crypto_pwhash_scryptsalsa208sha256
Expand Down Expand Up @@ -2077,12 +2079,12 @@ PHP_FUNCTION(sodium_crypto_pwhash_scryptsalsa208sha256_str)
zend_error(E_WARNING, "empty password");
}
if (opslimit < crypto_pwhash_scryptsalsa208sha256_OPSLIMIT_INTERACTIVE) {
zend_error(E_ERROR,
"number of operations for the scrypt function is too low");
zend_throw_exception(sodium_exception_ce,
"number of operations for the scrypt function is too low", 0);
}
if (memlimit < crypto_pwhash_scryptsalsa208sha256_MEMLIMIT_INTERACTIVE) {
zend_error(E_ERROR,
"maximum memory for the scrypt function is too low");
zend_throw_exception(sodium_exception_ce,
"maximum memory for the scrypt function is too low", 0);
}
hash_str = zend_string_alloc
(crypto_pwhash_scryptsalsa208sha256_STRBYTES - 1, 0);
Expand Down

1 comment on commit c05cbd1

@My1
Copy link

@My1 My1 commented on c05cbd1 Nov 28, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there a way to throw along the minimum that can be used?

I am not really a user of exceptions, so I dont know, I usually fix what I can fix before executing ugly stuff.

Please sign in to comment.