Expand description
Translation layer that adapts [password_rules_parser] output to the SDK’s
PasswordGeneratorRequest shape.
Reference: Apple’s password-manager-resources spec (also a WHATWG proposal).
The parsing itself is delegated to the third-party password-rules-parser crate
(maintained by 1Password). This module handles SDK-specific concerns:
- clamping length into [
MINIMUM_PASSWORD_LENGTH,MAXIMUM_PASSWORD_LENGTH]; - applying the spec’s defaults for
allowedwhenrequiredis present; - flattening the parser’s
Vec<Vec<CharacterClass>>required model into the SDK’s flat AND-of-classes model withmin_*counts; - shaping errors for WASM/UniFFI via
bitwarden_error(flat).
Structs§
- Accumulated
Classes 🔒 - The standard character classes from a single
requiredorallowedrule, flattened into the SDK’s “this class is enabled” boolean model. The parser exposesrequiredasVec<Vec<CharacterClass>>(AND of ORs), but the SDK’sPasswordGeneratorRequestonly models a flat AND of classes — so any nested OR groups are flattened by taking the union of their classes.
Enums§
- Password
Rules Error - Errors that may occur while parsing an HTML
passwordrulesattribute.
Constants§
- DEFAULT_
LENGTH 🔒 - Default password length used when no
minlength/maxlengthconstrains the choice. - MAX_
ECHOED_ 🔒VALUE_ LEN - Maximum length (in characters) of any user-supplied substring echoed back in errors. Keeps error payloads bounded as they cross the WASM/UniFFI boundary.
- UNIFFI_
META_ 🔒CONST_ BITWARDEN_ GENERATORS_ ERROR_ PASSWORDRULESERROR
Functions§
- assemble_
request 🔒 - Build the final
PasswordGeneratorRequestfrom the accumulated rule state. - parse_
error_ 🔒to_ sdk - Map the external parser’s error into the SDK’s
PasswordRulesError::Parse(String), truncating the message so the payload stays bounded across FFI. - parse_
password_ rules - Parses an HTML
passwordrulesattribute string into aPasswordGeneratorRequest. - resolve_
length 🔒 - Resolves the final password length from the (un-clamped)
min_length/max_lengthparsed from the input, applying the SDK’s[MINIMUM_PASSWORD_LENGTH, MAXIMUM_PASSWORD_LENGTH]clamp and validating thatmin_length <= max_length. - truncate_
for_ 🔒error - Trims
sand, if it exceedsMAX_ECHOED_VALUE_LENcharacters, truncates to that many characters followed by an ellipsis. Operates oncharboundaries, so it is UTF-8 safe.