Repository navigation
Conversation
The validate() function only checked the ISO 7064 Mod 97, 10 checksum, so any string that passed the checksum was accepted, e.g. "1", an LEI with extra leading zeros or one with letters as check digits. This ensures that the number is 20 characters long, only contains letters and digits and ends with two numeric check digits.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
lei.validate()says it checks the length, format and check digits, but it only runs the ISO 7064 Mod 97, 10 check. So any string that happens to pass the checksum is accepted:An LEI (ISO 17442) is always 20 characters, letters and digits only, and the last two are the check digits. Mod 97, 10 always yields two decimal digits there. GLEIF describes the structure here: https://www.gleif.org/en/about-lei/iso-17442-the-lei-code-structure
This change makes
validate()raiseInvalidFormatfor characters outside 0-9/A-Z,InvalidLengthif the number isn't 20 characters, andInvalidFormatif the last two characters aren't digits. It doesn't touchcompact()(the upper-casing discussed in #509 stays as it is). All the real LEIs intests/test_lei.docteststill validate.I added cases to
tests/test_lei.doctest. They fail on master and pass with the change. The fullpytestrun passes with 100% coverage, andflake8 .is clean.