Skip to content

Commit 9f9cf63

Browse files
committed
Use assertion instead of returning null for string out-of-bounds
1 parent 801ed71 commit 9f9cf63

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

src/Key/PublicKey.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
namespace SimpleSAML\XMLSecurity\Key;
66

7+
use Webmozart\Assert\Assert;
8+
79
use function base64_encode;
810
use function chr;
911
use function chunk_split;
@@ -86,16 +88,16 @@ protected static function makeASN1Segment(int $type, string $string): ?string
8688
}
8789

8890
$length = strlen($string);
91+
Assert::lessThan($length, self::ASN1_SIZE_65535);
8992

9093
if ($length < self::ASN1_SIZE_128) {
9194
$output = sprintf("%c%c%s", $type, $length, $string);
9295
} elseif ($length < self::ASN1_SIZE_256) {
9396
$output = sprintf("%c%c%c%s", $type, self::ASN1_SIZE_128 + 1, $length, $string);
94-
} elseif ($length < self::ASN1_SIZE_65535) {
97+
} else { // ($length < self::ASN1_SIZE_65535)
9598
$output = sprintf("%c%c%c%c%s", $type, self::ASN1_SIZE_128 +2, $length / 0x0100, $length % 0x0100, $string);
96-
} else {
97-
$output = null;
9899
}
100+
99101
return $output;
100102
}
101103

0 commit comments

Comments
 (0)