Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/Dflydev/Base32/Crockford/Crockford.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,14 @@ public static function encode($number)
return 0;
}

if ($number > PHP_INT_MAX){
throw new \RuntimeException("The number '{$number}' is too large for the current system. Only values up to and including '" . PHP_INT_MAX . "' are allowed.");
}

if ($number < 0){
throw new \RuntimeException("The number to be encoded must be a non negative integer.");
}

$response = array();
while ($number) {
$remainder = $number % 32;
Expand Down Expand Up @@ -118,7 +126,7 @@ public static function decodeWithChecksum($string, $errmode = self::NORMALIZE_ER
$string = substr($string, 0, strlen($string) - 1);

$value = static::internalDecode($string, $errmode);
$checksumValue = static::internalDecode($checksum, self::NORMALIZE_ERRMODE_EXCEPTION, true);
$checksumValue = static::internalDecode($checksum, $errmode, true);

if ($checksumValue !== ($value % 37)) {
throw new \RuntimeException("Checksum symbol '$checksum' is not correct value for '$string'");
Expand Down