diff --git a/schwifty/checksum/belgium.py b/schwifty/checksum/belgium.py index 2a37d5b..98347be 100644 --- a/schwifty/checksum/belgium.py +++ b/schwifty/checksum/belgium.py @@ -17,6 +17,8 @@ def compute(self, bban: str) -> str: spec = registry.get("iban") assert isinstance(spec, dict) checksum = int(bban[: spec["BE"]["bban_length"] - self.checksum_length]) % 97 + # Specific value in case checksum is expliclity 97 + checksum = checksum if checksum != 0 else 97 return str(checksum).zfill(self.checksum_length) def validate(self, bban: str) -> bool: diff --git a/schwifty/iban.py b/schwifty/iban.py index cfc7c4c..e8bb30a 100644 --- a/schwifty/iban.py +++ b/schwifty/iban.py @@ -179,8 +179,8 @@ def validate(self, validate_bban: bool = False) -> bool: """Validate the structural integrity of this IBAN. This function will verify the country specific format as well as the Luhn checksum in the - 3rd and 4th position of the IBAN. For some countries (currently Germany and Italy) it will - also verify the correctness of the country specific checksum within the BBAN if the + 3rd and 4th position of the IBAN. For some countries (currently Belgium, Germany and Italy) + it will also verify the correctness of the country specific checksum within the BBAN if the `validate_bban` parameter is set to `True`. For German banks it will pick the appropriate algorithm based on the bank code and verify that the account code has the correct checksum. diff --git a/tests/test_checksum.py b/tests/test_checksum.py index 82539a9..08a5d9a 100644 --- a/tests/test_checksum.py +++ b/tests/test_checksum.py @@ -97,3 +97,7 @@ def test_belgium_checksum(): def test_belgium_checksum_failure(): assert algorithms["BE:default"].validate("050000123456") is False + + +def test_belgium_checksum_checksum_edge_case(): + assert algorithms["BE:default"].validate("050000017797") is True diff --git a/tests/test_iban.py b/tests/test_iban.py index efd6e47..40749f6 100644 --- a/tests/test_iban.py +++ b/tests/test_iban.py @@ -169,6 +169,7 @@ def test_iban_properties(): (("BE", "050", "123456"), "BE45050012345689"), (("BE", "539", "0075470"), "BE68539007547034"), (("FR", "2004101005", "0500013M026"), "FR1420041010050500013M02606"), + (("BE", "050", "177"), "BE54050000017797"), ], ) def test_generate_iban(components, compact):