Skip to content

Commit

Permalink
Use binary-safe functions consistently.
Browse files Browse the repository at this point in the history
  • Loading branch information
paragonie-scott committed Nov 18, 2016
1 parent 540c667 commit 8f967f8
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions src/SeedSpring.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,7 @@ final class SeedSpring
*/
public function __construct($seed = '', $counter = 0)
{
if (\function_exists('\\mb_strlen')) {
if (\mb_strlen($seed, '8bit') !== 16) {
throw new \InvalidArgumentException('Seed must be 16 bytes');
}
} elseif (Binary::safeStrlen($seed) !== 16) {
if (Binary::safeStrlen($seed) !== 16) {
throw new \InvalidArgumentException('Seed must be 16 bytes');
}
$this->seed('set', $seed);
Expand Down Expand Up @@ -106,6 +102,8 @@ public function getBytes($numBytes)
* @param int $min
* @param int $max
* @return int
* @throws \Error
* @throws \Exception
*/
public function getInt($min, $max)
{
Expand Down Expand Up @@ -243,7 +241,7 @@ protected function getNonce($increment = 0)
$incr = (int) \ceil(($increment + ($increment % 16)) / 16);
$this->counter += $incr;
while ($ctr > 0) {
$nonce = \chr($ctr & 0xFF) . $nonce;
$nonce = \pack('C', $ctr & 0xFF) . $nonce;
$ctr >>= 8;
}
return \str_pad($nonce, 16, "\0", STR_PAD_LEFT);
Expand Down

0 comments on commit 8f967f8

Please sign in to comment.