Edit report at https://pear.php.net/bugs/bug.php?id=15346&edit=1
ID: 15346
Updated by: mike@silverorange.com
Reported By: mike at silverorange dot com
Summary: Create more specific exception for hash algorithm not
found or return a boolean
Status: Open
Type: Feature/Change Request
Package: Crypt_HMAC2
Operating System: Irrelevant
Package Version: 0.2.1
PHP Version: Irrelevant
Roadmap Versions:
New Comment:
Any progress on this feature request? The patch should be pretty
straightforward.
Previous Comments:
------------------------------------------------------------------------
[2009-06-19 06:59:46] gauthierm
Poke poke. Patch is still attached.
------------------------------------------------------------------------
[2008-12-27 20:52:43] gauthierm
Option 2 makes the most sense to me as well, and would fit with the way
I'm currently using Crypt_HMAC2.
Here's what I have currently:
try {
// try first to use SHA-256
$hmac = new Crypt_HMAC2($secretKey, 'SHA256');
} catch (Crypt_HMAC2_Exception $e) {
// if SHA-256 is not available, use SHA-1
$hmac = new Crypt_HMAC2($secretKey, 'SHA1');
}
------------------------------------------------------------------------
[2008-12-26 23:31:38] doconnor
I like option 2 best
------------------------------------------------------------------------
[2008-12-18 09:47:43] gauthierm
Description:
------------
I'd like to write code that uses SHA-256 if available and otherwise uses
SHA-1. The way the setHash() method works this is a bit cumbersome. I
can think of three ways to make it better:
1.) Create a hasHashAlgorithm() method I can use to check for SHA_256
2.) Throw a more specific exception in setHashAlgorithm() like
Crypt_HMAC2_InvalidAlgorithmException
3.) Return a boolean from setHashAlgorithm(). True on success and false
on failure.
------------------------------------------------------------------------