Skip to content

Commit 8562668

Browse files
author
Walter Stanish
committed
Minor fixes, removed Tunisia (TN) checksum support; v2.4.13
1 parent ceead58 commit 8562668

2 files changed

Lines changed: 34 additions & 50 deletions

File tree

README.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ Then just add the following to your `composer.json` file:
140140
// composer.json
141141
{
142142
"require": {
143-
"globalcitizen/php-iban": "2.4.12"
143+
"globalcitizen/php-iban": "2.4.13"
144144
}
145145
}
146146
```
@@ -236,7 +236,7 @@ The following table compares __php-iban__ to other PHP projects offering IBAN-re
236236

237237
| Project | Lic. | Proc | OO | Began | Latest | Star | Watch | Fork | Installs | Home culture | Deps |
238238
| ---------------------------------------------------------- | ---- | ---- | --- | ------ | ------ | ---- | ----- | ---- | -------- | ------------ | ------- |
239-
| __php-iban__ | LGPL ||| 2009 | 2.4.12 | 27 | 11 | 13 | 10k+* | Global* | *none* |
239+
| __php-iban__ | LGPL ||| 2009 | 2.4.13 | 27 | 11 | 13 | 10k+* | Global* | *none* |
240240
| [Iban](https://github.com/jschaedl/Iban) | MIT ||| 2013 | 1.1.6 | 38 | 10 | 14 | 52k | German | lots |
241241
| [IsoCodes](https://github.com/ronanguilloux/IsoCodes) | GPL3 ||| 2012 | 2.0.0 | 241 | 14 | 28 | 36k | French | lots |
242242
| [SepaUtil's](https://github.com/AbcAeffchen/SepaUtilities) | GPL3 ||| 2014 | 1.1.2 | 4 | 3 | 3 | 1.4k | German | phpunit |
@@ -293,6 +293,13 @@ Your Help Wanted
293293
News: February 2016
294294
-------------------
295295

296+
__[Version 2.4.13](https://github.com/globalcitizen/php-iban/releases/tag/v2.4.13)__ has been released.
297+
* This release is mostly about bugfixes, after spending a lot of time gathering IBANs online and using them for further testing.
298+
* Tunisia (TN) national checksum support has been removed, after additional testing with IBAN gathered from the internet it was found not to be correct. Perils of reverse-engineering!
299+
* A couple of other bugfixes:
300+
* The function `iban_mistranscription_suggestions()` now behaves correctly when passed loosely formatted IBAN-like strings
301+
* The checksum algorithm `_verhoeff()` which supports certain national checksum implementations now behaves correctly when passed invalid input
302+
296303
__[Version 2.4.12](https://github.com/globalcitizen/php-iban/releases/tag/v2.4.12)__ has been released.
297304
* Tunisia (TN) national checksum support has been added.
298305

php-iban.php

Lines changed: 25 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,9 @@ function iban_countries() {
388388
# mistranscriptions.
389389
function iban_mistranscription_suggestions($incorrect_iban) {
390390

391+
# remove funky characters
392+
$incorrect_iban = iban_to_machine_format($incorrect_iban);
393+
391394
# abort on ridiculous length input (but be liberal)
392395
$length = strlen($incorrect_iban);
393396
if($length<5 || $length>34) { return array('(supplied iban length insane)'); }
@@ -601,27 +604,6 @@ function _iban_nationalchecksum_set($iban,$nationalchecksum) {
601604
return $fixed_iban;
602605
}
603606

604-
# Internal proxy function to access national checksum implementations
605-
# $iban = IBAN to work with (length and country must be valid, IBAN checksum and national checksum may be incorrect)
606-
# $mode = 'find', 'set', or 'verify'
607-
# - In 'find' mode, the correct national checksum for $iban is returned.
608-
# - In 'set' mode, a (possibly) modified version of $iban with the national checksum corrected is returned.
609-
# - In 'verify' mode, the checksum within $iban is compared to correctly calculated value, and true or false is returned.
610-
# If a national checksum algorithm does not exist or remains unimplemented for this country, or the supplied $iban or $mode is invalid, '' is returned.
611-
# (NOTE: We cannot collapse 'verify' mode and implement here via simple string comparison between 'find' mode output and the nationalchecksum part,
612-
# because some countries have systems which do not map to this approach, for example the Netherlands has no checksum part yet an algorithm exists)
613-
function _iban_nationalchecksum_implementation($iban,$mode) {
614-
if($mode != 'set' && $mode != 'find' && $mode != 'verify') { return ''; } # blank value on return to distinguish from correct execution
615-
$iban = iban_to_machine_format($iban);
616-
$country = iban_get_country_part($iban);
617-
if(strlen($iban)!=iban_country_get_iban_length($country)) { return ''; }
618-
$function_name = '_iban_nationalchecksum_implementation_' . strtolower($country);
619-
if(function_exists($function_name)) {
620-
return $function_name($iban,$mode);
621-
}
622-
return '';
623-
}
624-
625607
# Currently unused but may be useful for Norway.
626608
# ISO7064 MOD11-2
627609
# Adapted from https://gist.github.com/andreCatita/5714353 by Andrew Catita
@@ -672,24 +654,6 @@ function _iso7064_mod97_10($str) {
672654
return (98-($check%97));
673655
}
674656

675-
# Implement the national checksum for an Albania (AL) IBAN
676-
# (NOTE: Reverse engineered, may be incorrect, but seems logical due to placement (after subject), works fine on demo IBAN)
677-
function _iban_nationalchecksum_implementation_al($iban,$mode) {
678-
if($mode != 'set' && $mode != 'find' && $mode != 'verify') { return ''; } # blank value on return to distinguish from correct execution
679-
$nationalchecksum = iban_get_nationalchecksum_part($iban);
680-
$bankbranch = iban_get_bank_part($iban) . iban_get_branch_part($iban);
681-
$expected_nationalchecksum = _luhn($bankbranch);
682-
if($mode=='find') {
683-
return $expected_nationalchecksum;
684-
}
685-
elseif($mode=='set') {
686-
return _iban_nationalchecksum_set($iban,$expected_nationalchecksum);
687-
}
688-
elseif($mode=='verify') {
689-
return ($nationalchecksum == $expected_nationalchecksum);
690-
}
691-
}
692-
693657
# Implement the national checksum for an Bosnia (BA) IBAN
694658
# (NOTE: Reverse engineered, may be incorrect, but seems to work fine on demo IBAN, uses entire BBAN less checksum characters as input)
695659
function _iban_nationalchecksum_implementation_ba($iban,$mode) {
@@ -1135,13 +1099,6 @@ function _iban_nationalchecksum_implementation_tl($iban,$mode) {
11351099
}
11361100
}
11371101

1138-
# Implement the national checksum for an Tunisia (TN) IBAN
1139-
# (NOTE: Reverse engineered)
1140-
function _iban_nationalchecksum_implementation_tn($iban,$mode) {
1141-
return _iban_nationalchecksum_implementation_fr($iban,$mode);
1142-
}
1143-
1144-
11451102
# Luhn Check
11461103
# (Credit: Adapted from @gajus' https://gist.github.com/troelskn/1287893#gistcomment-857491)
11471104
function _luhn($string) {
@@ -1155,7 +1112,7 @@ function _luhn($string) {
11551112
# Verhoeff checksum
11561113
# (Credit: Adapted from Semyon Velichko's code at https://en.wikibooks.org/wiki/Algorithm_Implementation/Checksums/Verhoeff_Algorithm#PHP)
11571114
function _verhoeff($input) {
1158-
if(preg_match('/[^0-9]/',$input)) { return ''; } # reject non-numeric input
1115+
if($input == '' || preg_match('/[^0-9]/',$input)) { return ''; } # reject non-numeric input
11591116
$d = array(
11601117
array(0,1,2,3,4,5,6,7,8,9),
11611118
array(1,2,3,4,0,6,7,8,9,5),
@@ -1206,10 +1163,30 @@ function _damm($input) {
12061163
$checksum = 0;
12071164
for ($i=0; $i<strlen($input); $i++) {
12081165
$character = substr($input,$i,1);
1209-
#print "(checksum = \$matrix['" . $checksum . "']['" . $character . "'] ... )\n";
12101166
$checksum = $matrix[$checksum][$character];
12111167
}
12121168
return $checksum;
12131169
}
12141170

1171+
# Internal proxy function to access national checksum implementations
1172+
# $iban = IBAN to work with (length and country must be valid, IBAN checksum and national checksum may be incorrect)
1173+
# $mode = 'find', 'set', or 'verify'
1174+
# - In 'find' mode, the correct national checksum for $iban is returned.
1175+
# - In 'set' mode, a (possibly) modified version of $iban with the national checksum corrected is returned.
1176+
# - In 'verify' mode, the checksum within $iban is compared to correctly calculated value, and true or false is returned.
1177+
# If a national checksum algorithm does not exist or remains unimplemented for this country, or the supplied $iban or $mode is invalid, '' is returned.
1178+
# (NOTE: We cannot collapse 'verify' mode and implement here via simple string comparison between 'find' mode output and the nationalchecksum part,
1179+
# because some countries have systems which do not map to this approach, for example the Netherlands has no checksum part yet an algorithm exists)
1180+
function _iban_nationalchecksum_implementation($iban,$mode) {
1181+
if($mode != 'set' && $mode != 'find' && $mode != 'verify') { return ''; } # blank value on return to distinguish from correct execution
1182+
$iban = iban_to_machine_format($iban);
1183+
$country = iban_get_country_part($iban);
1184+
if(strlen($iban)!=iban_country_get_iban_length($country)) { return ''; }
1185+
$function_name = '_iban_nationalchecksum_implementation_' . strtolower($country);
1186+
if(function_exists($function_name)) {
1187+
return $function_name($iban,$mode);
1188+
}
1189+
return '';
1190+
}
1191+
12151192
?>

0 commit comments

Comments
 (0)