Changeset View
Changeset View
Standalone View
Standalone View
src/infrastructure/util/PhabricatorHash.php
Show First 20 Lines • Show All 191 Lines • ▼ Show 20 Lines | if (!is_string($message)) { | ||||
pht('HMAC-SHA256 can only digest strings.')); | pht('HMAC-SHA256 can only digest strings.')); | ||||
} | } | ||||
if (!is_string($key)) { | if (!is_string($key)) { | ||||
throw new Exception( | throw new Exception( | ||||
pht('HMAC-SHA256 keys must be strings.')); | pht('HMAC-SHA256 keys must be strings.')); | ||||
} | } | ||||
if (!strlen($key)) { | if (!phutil_nonempty_string($key)) { | ||||
throw new Exception( | throw new Exception( | ||||
pht('HMAC-SHA256 requires a nonempty key.')); | pht('HMAC-SHA256 requires a nonempty key.')); | ||||
} | } | ||||
$result = hash_hmac('sha256', $message, $key, $raw_output = false); | $result = hash_hmac('sha256', $message, $key, $raw_output = false); | ||||
// Although "hash_hmac()" is documented as returning `false` when it fails, | // Although "hash_hmac()" is documented as returning `false` when it fails, | ||||
// it can also return `null` if you pass an object as the "$message". | // it can also return `null` if you pass an object as the "$message". | ||||
▲ Show 20 Lines • Show All 73 Lines • Show Last 20 Lines |
Content licensed under Creative Commons Attribution-ShareAlike 4.0 (CC-BY-SA) unless otherwise noted; code licensed under Apache 2.0 or other open source licenses. · CC BY-SA 4.0 · Apache 2.0