Skip to content

Implement the aba, verhoeff, and damm identifier validators #87

Description

@jzonthemtn

Description

The redaction policy schema names eleven validators for the custom identifier filter.
phileas/filters/identifier_validators/__init__.py registers eight: luhn, mod11, mod97,
mod23_letter, es_cif, de_steuerid, de_personalausweis and bic_structural. A policy naming
aba, verhoeff or damm raises at load, from resolve_validator in
phileas/filters/validators.py:90.

The spec describes them as:

Validator Description
aba ABA routing transit number checksum (weights 3-7-1 mod 10).
verhoeff Verhoeff check digit (dihedral-group scheme).
damm Damm check digit (quasigroup scheme).

All three ports had this gap. philterd/phileas-dotnet#89 closes it for .NET and is a working
reference; philterd/phileas#391 tracks it for Java.

Notes from implementing it in .NET

The tables and the tests are language-independent, so most of the work transfers:

  • Published vectors that exercise each scheme. Verhoeff accepts 2363, 123451 and 758722 and
    rejects 12345. Damm accepts 5724 and 112946, rejects 5727 and 112949. ABA accepts
    021000021.
  • Two structural properties worth asserting, because a transcribed lookup table can be subtly
    wrong and still look plausible. For any body exactly one appended digit may validate; and neither
    scheme may accept a value with two adjacent digits transposed, which is the property that
    distinguishes them from a plain modulus check. Assert both across a range of values, not on single
    examples.
  • ABA should require exactly nine digits and reject a tenth rather than letting the weights wrap.

Two things specific to this port:

  • \d is Unicode-aware here, as it is in .NET. re.fullmatch(r"\d{9}", "021000021")
    matches, so a routing number written in fullwidth digits would pass a naive \d-based check. Use
    [0-9], or re.ASCII. Java does not have this problem, so its implementation will not show it.
  • The module docstring claims the validators "are parity ports: for the same input they return the
    same result as the Java implementation."
    Java does not have these three yet
    (philterd/phileas#391). If this lands first, that sentence needs qualifying rather than leaving a
    claim that is no longer true.

Registration is a register_validator(name, factory) call in a new module under
phileas/filters/identifier_validators/, plus one import line in that package's __init__.py.

Acceptance criteria

  • aba, verhoeff and damm are implemented and registered, so a policy naming one loads.
  • The message raised for an unknown name lists all eleven.
  • Each validator has unit tests covering a value the checksum accepts and one it rejects.
  • A test asserts that for any body exactly one appended check digit validates, for verhoeff and
    damm.
  • A test asserts neither scheme accepts a value with two adjacent digits transposed.
  • aba requires exactly nine digits, ignoring separators, and rejects both eight and ten.
  • Digits are matched as ASCII, so a value written in fullwidth or other Unicode digits is not
    accepted.
  • A test runs each validator through a policy on the custom identifier filter, so the check is
    shown to run during filtering rather than only to resolve by name.
  • The validator documentation lists the three, alongside the eight already documented, and the
    parity claim in the package docstring is still accurate afterwards.

Related

  • philterd/phileas-dotnet#89 closes the same gap for the .NET port, with a working implementation.
  • philterd/phileas#391 tracks it for Java.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    documentationImprovements or additions to documentationenhancementNew feature or requestphisqlCloses a gap against the PhiSQL specification

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions