verify: check hashes

git-svn-id: https://svn.fournier38.fr/svn/ProgSVN/trunk@3754 bf3deb0d-5f1a-0410-827f-c0cc1f45334c
This commit is contained in:
2017-06-12 18:51:10 +00:00
parent c597acea60
commit 95953579fe

View File

@@ -349,4 +349,30 @@ class verify
return true;
}
/** Return true if the provided string is a valid hash
* @param string $algo The hash algo to test
* @param string $val The value to test
*/
public function isHash ($algo, $val)
{
return \verify::IsHash ($algo, $val);
}
/** Return true if the provided string is a valid hash in static
* @param string $algo The hash algo to test
* @param string $val The value to test
*/
public static function staticIsHash ($algo, $val)
{
if (! is_string ($algo) || ! is_string ($val))
return false;
if (! in_array ($algo, hash_algos ()))
throw new \Exception ("Unknown algo provided to verify the hash", 500);
$len = strlen (hash ($algo, ""));
if (strlen ($val) !== $len)
return false;
if (\verify::staticIsAllowedChars ($val, "0123456789abcdef") === false)
return false;
return true;
}
}