Skip to content

Commit

Permalink
Base32 argument validation fix
Browse files Browse the repository at this point in the history
  • Loading branch information
nyamsprod committed Mar 12, 2024
1 parent 2b67fdd commit 98f052f
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/Base32/Base32.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 98f052f

Please sign in to comment.