Skip to main content

Module passwordrules

Module passwordrules 

Source
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 allowed when required is present;
  • flattening the parser’s Vec<Vec<CharacterClass>> required model into the SDK’s flat AND-of-classes model with min_* counts;
  • shaping errors for WASM/UniFFI via bitwarden_error(flat).

Structs§

AccumulatedClasses 🔒
The standard character classes from a single required or allowed rule, flattened into the SDK’s “this class is enabled” boolean model. The parser exposes required as Vec<Vec<CharacterClass>> (AND of ORs), but the SDK’s PasswordGeneratorRequest only models a flat AND of classes — so any nested OR groups are flattened by taking the union of their classes.

Enums§

PasswordRulesError
Errors that may occur while parsing an HTML passwordrules attribute.

Constants§

DEFAULT_LENGTH 🔒
Default password length used when no minlength/maxlength constrains 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 PasswordGeneratorRequest from 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 passwordrules attribute string into a PasswordGeneratorRequest.
resolve_length 🔒
Resolves the final password length from the (un-clamped) min_length/max_length parsed from the input, applying the SDK’s [MINIMUM_PASSWORD_LENGTH, MAXIMUM_PASSWORD_LENGTH] clamp and validating that min_length <= max_length.
truncate_for_error 🔒
Trims s and, if it exceeds MAX_ECHOED_VALUE_LEN characters, truncates to that many characters followed by an ellipsis. Operates on char boundaries, so it is UTF-8 safe.