Skip to content

Remove the 2^62 length cap from RandomGenerator - #2

Merged
chrismou merged 4 commits into
mainfrom
fix/random-generator-length-cap
Dec 1, 2026
Merged

chrismou merged 4 commits into
mainfrom
fix/random-generator-length-cap

Conversation

@chrismou

@chrismou chrismou commented Dec 1, 2026 •

Copy link
Copy Markdown
Owner

Summary

RandomGenerator builds each string symbol by symbol and never needs the keyspace capacity as an integer, so the 2^62 ceiling that the Feistel permutation requires no longer limits its length.

  • RandomGenerator::generate() accepts any length, as the policy default or a per-call override. The remaining checks are >= 1 and the policy's maximumLength, which is now the only upper bound.
  • The RandomGenerator constructor accepts a default or maximum length beyond the ceiling, e.g. new LengthPolicy(24) or new LengthPolicy(8, 32).
  • RandomGenerator::generateWithAutoLengthIncrement() escalates up to maximumLength, however long, and requires one: with no keyspace ceiling to stop at, it throws InvalidLengthException when the policy has no maximum.
  • PermutationGenerator still rejects lengths whose capacity exceeds 2^62. Its generateWithAutoLengthIncrement() now throws InvalidLengthException for a start length beyond the ceiling when no maximum is set, instead of a misleading KeyspaceExhaustedException.
  • README: documents the per-strategy length limits, warns that maximumLength is the only guard on RandomGenerator lengths, and expands the capacity table to cover all four included alphabets. Docblocks updated to match.
  • CHANGELOG: entries grouped under their tagged versions (0.0.1, 0.0.2) with compare links, plus a 0.1.0 entry for this change. The breaking change to RandomGenerator::generateWithAutoLengthIncrement() makes this a minor bump.

Testing

tests/Unit/Generator/RandomGeneratorTest.php: the tests asserting that lengths beyond the ceiling are rejected, and that auto-increment falls back to the keyspace ceiling, are replaced with tests covering:

  • per-call overrides beyond the ceiling (11 and 64 characters with the 66-char alphabet)
  • a default length beyond the ceiling
  • a long maximumLength still rejecting overrides above it
  • auto-increment escalating past the ceiling up to maximumLength
  • auto-increment throwing InvalidLengthException when no maximumLength is configured

tests/Unit/Generator/PermutationGeneratorTest.php: new test for an auto-increment override beyond the keyspace ceiling throwing InvalidLengthException.

User Actions

  • After merging, tag 0.1.0 on main and push the tag
  • If the tag date differs from 2026-12-01, update the [0.1.0] heading in CHANGELOG.md

@chrismou
chrismou merged commit 4996e07 into main Dec 1, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant