镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

VALIDATOR-481: Add LEIValidator and Modulus97CheckDigit (ISO/IEC 7064 MOD 97-10) - #444

Open
karlkauc wants to merge 1 commit into
apache:masterfrom
karlkauc:VALIDATOR-481-LEI
Open

karlkauc wants to merge 1 commit into
apache:masterfrom
karlkauc:VALIDATOR-481-LEI

Conversation

@karlkauc

Copy link
Copy Markdown

Jira: https://issues.apache.org/jira/browse/VALIDATOR-481

What

  • Modulus97CheckDigit: a generic check digit routine for the pure system ISO/IEC 7064, MOD 97-10 with the two numeric check digits at the end of the code. IBANCheckDigit uses the same algorithm, but IBAN check digits sit at positions 3–4 and the code is rearranged first; this class does not rearrange anything, so it works for all MOD 97-10 codes with trailing check digits (LEI, German Leitweg-ID, …). Check values 00, 01 and 99 are rejected, as the calculation can only produce 02–98.
  • LEIValidator: validation of Legal Entity Identifiers (ISO 17442), built on CodeValidator with the regex [A-Z0-9]{18}[0-9]{2}, length 20 and the new check digit routine. Same structure as ISINValidator (singleton getInstance(), isValid(), validate()). Characters 5–6 are no longer required to be 00 since ISO 17442-1:2020, so this is not enforced.
  • Tests for both classes (Modulus97CheckDigitTest extends AbstractCheckDigitTest), a new section 4.6 "LEI validation" in package-info.java, and a changes.xml entry.

Why

Commons Validator has no LEI support. LEIs are mandatory identifiers in financial regulatory reporting (MiFID II, EMIR, Solvency II, FundsXML, …), and the check digit scheme is a well-defined ISO standard with a single authoritative source (GLEIF), comparable to IBAN and ISIN which are already covered.

Scope

This PR is intentionally small. It picks up the LEI part of the withdrawn #61 and follows the feedback in #271, where the maintainers said that generic, standardised CheckDigit implementations are welcome while country-specific validators with many moving parts are not. No Leitweg-ID or VAT validators are included; the Leitweg-ID example is only used as a test case to show the routine is not LEI-specific.

Differences to the Modulus97CheckDigit proposed in #61: calculate() follows the CheckDigit contract and takes the code without check digits; the validator reuses CodeValidator instead of a custom wrapper; null is checked before trimming; Javadoc documents the standard and the test data sources.

Testing

  • The default Maven goal (mvn: verify, apache-rat, japicmp, checkstyle, spotbugs, pmd, javadoc) passes with 3,314 tests.
  • Test LEIs come from public GLEIF data (https://search.gleif.org/, including GLEIF's own LEI 5493001KJTIIGC8Y1R12), plus the ISO/IEC 7064 example 794 → 79444 and the Leitweg-ID example 04011000-1234512345-06.
  • The routine was additionally cross-checked against IBANCheckDigit (by moving the last four characters to the front) on 10,473 distinct real-world LEIs from FundsXML fund reports: identical results, 10,471 valid, 2 placeholders correctly rejected.

References

… MOD 97-10)

Add a generic check digit routine for the pure system ISO/IEC 7064,
MOD 97-10 with the two numeric check digits at the end of the code,
and an LEIValidator (Legal Entity Identifier, ISO 17442) built on
CodeValidator with this routine, following the ISINValidator pattern.

IBANCheckDigit uses the same algorithm, but IBAN check digits are at
positions 3 and 4 and the code is rearranged first; Modulus97CheckDigit
does not rearrange the code, so it can be used for all MOD 97-10 codes
with trailing check digits (LEI, German Leitweg-ID, ...).

The LEI validator checks format and check digits only; whether an LEI
has been issued or is active is only known to GLEIF.

Test data: LEIs from public GLEIF data (https://search.gleif.org/),
the ISO/IEC 7064 example "794" -> "79444", and the Leitweg-ID example
"04011000-1234512345-06". The check digit routine was cross-checked
against IBANCheckDigit on 10,473 distinct real-world LEIs with
identical results.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
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