From 98f052fe05dd08a71955ea377dcae8a078312334 Mon Sep 17 00:00:00 2001 From: ignace nyamagana butera Date: Tue, 12 Mar 2024 08:08:00 +0100 Subject: [PATCH] Base32 argument validation fix --- src/Base32/Base32.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/Base32/Base32.php b/src/Base32/Base32.php index 29d664c..dc7dc48 100644 --- a/src/Base32/Base32.php +++ b/src/Base32/Base32.php @@ -20,14 +20,15 @@ private function __construct(string $alphabet, string $padding) 1 !== strlen($padding) => throw new ValueError('The padding character must a single character.'), "\r" === $padding => throw new ValueError('The padding character can not be the carriage return character.'), "\n" === $padding => throw new ValueError('The padding character can not be the newline escape sequence.'), - 32 !== strlen($normalizeAlphabet) => throw new ValueError('The alphabet must be a 32 bytes long string.'), + 32 !== strlen($alphabet) => throw new ValueError('The alphabet must be a 32 bytes long string.'), + str_contains($alphabet, "\r") => throw new ValueError('The alphabet can not contain the carriage return character.'), + str_contains($alphabet, "\n") => throw new ValueError('The alphabet can not contain the newline escape sequence.'), 32 !== count(array_unique(str_split($normalizeAlphabet))) => throw new ValueError('The alphabet must contain unique characters.'), - str_contains($normalizeAlphabet, "\r") => throw new ValueError('The alphabet can not contain the carriage return character.'), str_contains($normalizeAlphabet, strtoupper($padding)) => throw new ValueError('The alphabet can not contain the padding character.'), default => [$alphabet, $padding], }; } - +"" public static function new(string $alphabet, string $padding): self { return new self($alphabet, $padding);