password-rules-parser icon indicating copy to clipboard operation
password-rules-parser copied to clipboard

Design Proposal for 2.0: updated output struct

Open Lucretiel opened this issue 5 years ago • 0 comments

This issue proposes to replace the uses of CharacterClass and Vec<CharacterClass> with a flag- or set-oriented approach, since only a fixed amount is ever needed for these constraint types. The popular bitvec crate provides an efficient array of bools that only uses 1 bit per item, which means that a bitarray<128> would only take 16 bytes and would be sufficient to fully* encode the same information currently stored in a Vec<CharacterClass>. This would also entirely remove the need to perform canonicalization, since there would only ever be a single representation for any given constraint set.

This would be extremely efficient for checking membership of a given ascii character, or iterating over all valid characters. The actual computation of the individual sets (lower, upper, digit) would have to be done on the fly, but in practice this is basically only necessary when serializing a PasswordRules back into string form. It would still be very efficient, since it can be computed with basic bitwise binary operations with a mask for each category (also supported by bitvec).

This would obviously be wildly incompatible with 1.0, but I think it's a better design overall, since it'll require significantly less storage and should respond to queries much faster.

* the only exception here is that we lose the ability to distinguish between unicode and ascii constraints, but currently this trait treats the two classes as identical for all purposes. If it's important, we could simply add an extra bool (or use an enum) to indicate if the input was unicode.

Lucretiel avatar Nov 10 '20 06:11 Lucretiel