Skip to content

Commit

Permalink
Merge pull request #47 from ThomasdenH/update-registry
Browse files Browse the repository at this point in the history
Update registry to Release 98
  • Loading branch information
ThomasdenH authored Oct 28, 2024
2 parents 9e6c9b8 + 6cd31cc commit dc9ba5a
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 14 deletions.
29 changes: 25 additions & 4 deletions iban_validate/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,12 +148,14 @@ impl Iban {
"CY" => Some(0..3),
"CZ" => Some(0..4),
"DE" => Some(0..8),
"DJ" => Some(0..5),
"DK" => Some(0..4),
"DO" => Some(0..4),
"EE" => Some(0..2),
"EG" => Some(0..4),
"ES" => Some(0..4),
"FI" => Some(0..3),
"FK" => Some(0..2),
"FO" => Some(0..4),
"FR" => Some(0..5),
"GB" => Some(0..4),
Expand Down Expand Up @@ -184,25 +186,29 @@ impl Iban {
"MD" => Some(0..2),
"ME" => Some(0..3),
"MK" => Some(0..3),
"MN" => Some(0..4),
"MR" => Some(0..5),
"MT" => Some(0..4),
"MU" => Some(0..6),
"NI" => Some(0..4),
"NL" => Some(0..4),
"NO" => Some(0..4),
"PK" => Some(0..4),
"OM" => Some(0..3),
"PL" => None,
"PS" => Some(0..4),
"PT" => Some(0..4),
"QA" => Some(0..4),
"RO" => Some(0..4),
"RS" => Some(0..3),
"RU" => Some(0..9),
"SA" => Some(0..2),
"SC" => Some(0..6),
"SD" => Some(0..2),
"SE" => Some(0..3),
"SI" => Some(0..5),
"SK" => Some(0..4),
"SM" => Some(1..6),
"SO" => Some(0..4),
"ST" => Some(0..4),
"SV" => Some(0..4),
"TL" => Some(0..3),
Expand All @@ -212,6 +218,7 @@ impl Iban {
"VA" => Some(0..3),
"VG" => Some(0..4),
"XK" => Some(0..2),
"YE" => Some(0..4),
_ => panic!(
"Unknown country! Please file an issue at \
https://github.com/ThomasdenH/iban_validate."
Expand Down Expand Up @@ -252,12 +259,14 @@ impl Iban {
"CY" => Some(3..8),
"CZ" => None,
"DE" => None,
"DJ" => Some(5..10),
"DK" => None,
"DO" => None,
"EE" => None,
"EG" => Some(4..8),
"ES" => Some(4..8),
"FI" => None,
"FK" => None,
"FO" => None,
"FR" => None,
"GB" => Some(4..10),
Expand Down Expand Up @@ -288,25 +297,29 @@ impl Iban {
"MD" => None,
"ME" => None,
"MK" => None,
"MN" => None,
"MR" => Some(5..10),
"MT" => Some(4..9),
"MU" => Some(6..8),
"NI" => None,
"NL" => None,
"NO" => None,
"PK" => None,
"OM" => None,
"PL" => Some(0..8),
"PS" => None,
"PT" => None,
"PT" => Some(4..8),
"QA" => None,
"RO" => None,
"RS" => None,
"RU" => Some(9..14),
"SA" => None,
"SC" => Some(6..8),
"SD" => None,
"SE" => None,
"SI" => None,
"SK" => None,
"SM" => Some(6..11),
"SO" => Some(4..7),
"ST" => Some(4..8),
"SV" => None,
"TL" => None,
Expand All @@ -316,6 +329,7 @@ impl Iban {
"VA" => None,
"VG" => None,
"XK" => Some(2..4),
"YE" => Some(4..8),
_ => panic!(
"Unknown country! Please file an issue at \
https://github.com/ThomasdenH/iban_validate."
Expand Down Expand Up @@ -490,12 +504,14 @@ impl TryFrom<BaseIban> for Iban {
"CY" => Some([(3, N), (5, N), (16, C)].borrow()),
"CZ" => Some([(4, N), (6, N), (10, N)].borrow()),
"DE" => Some([(8, N), (10, N)].borrow()),
"DJ" => Some([(5, N), (5, N), (11, N), (2, N)].borrow()),
"DK" => Some([(4, N), (9, N), (1, N)].borrow()),
"DO" => Some([(4, C), (20, N)].borrow()),
"EE" => Some([(2, N), (2, N), (11, N), (1, N)].borrow()),
"EG" => Some([(4, N), (4, N), (17, N)].borrow()),
"ES" => Some([(4, N), (4, N), (1, N), (1, N), (10, N)].borrow()),
"FI" => Some([(3, N), (11, N)].borrow()),
"FK" => Some([(2, A), (12, N)].borrow()),
"FO" => Some([(4, N), (9, N), (1, N)].borrow()),
"FR" => Some([(5, N), (5, N), (11, C), (2, N)].borrow()),
"GB" => Some([(4, A), (6, N), (8, N)].borrow()),
Expand Down Expand Up @@ -525,25 +541,29 @@ impl TryFrom<BaseIban> for Iban {
"MD" => Some([(2, C), (18, C)].borrow()),
"ME" => Some([(3, N), (13, N), (2, N)].borrow()),
"MK" => Some([(3, N), (10, C), (2, N)].borrow()),
"MN" => Some([(4, N), (12, N)].borrow()),
"MR" => Some([(5, N), (5, N), (11, N), (2, N)].borrow()),
"MT" => Some([(4, A), (5, N), (18, C)].borrow()),
"MU" => Some([(4, A), (2, N), (2, N), (12, N), (3, N), (3, A)].borrow()),
"NI" => Some([(4, A), (20, N)].borrow()),
"NL" => Some([(4, A), (10, N)].borrow()),
"NO" => Some([(4, N), (6, N), (1, N)].borrow()),
"PK" => Some([(4, A), (16, C)].borrow()),
"OM" => Some([(3, N), (16, C)].borrow()),
"PL" => Some([(8, N), (16, N)].borrow()),
"PS" => Some([(4, A), (21, C)].borrow()),
"PT" => Some([(4, N), (4, N), (11, N), (2, N)].borrow()),
"QA" => Some([(4, A), (21, C)].borrow()),
"RO" => Some([(4, A), (16, C)].borrow()),
"RS" => Some([(3, N), (13, N), (2, N)].borrow()),
"RU" => Some([(9, N), (5, N), (15, C)].borrow()),
"SA" => Some([(2, N), (18, C)].borrow()),
"SC" => Some([(4, A), (2, N), (2, N), (16, N), (3, A)].borrow()),
"SD" => Some([(2, N), (12, N)].borrow()),
"SE" => Some([(3, N), (16, N), (1, N)].borrow()),
"SI" => Some([(5, N), (8, N), (2, N)].borrow()),
"SK" => Some([(4, N), (6, N), (10, N)].borrow()),
"SM" => Some([(1, A), (5, N), (5, N), (12, C)].borrow()),
"SO" => Some([(4, N), (3, N), (12, N)].borrow()),
"ST" => Some([(4, N), (4, N), (11, N), (2, N)].borrow()),
"SV" => Some([(4, A), (20, N)].borrow()),
"TL" => Some([(3, N), (14, N), (2, N)].borrow()),
Expand All @@ -553,6 +573,7 @@ impl TryFrom<BaseIban> for Iban {
"VA" => Some([(3, N), (15, N)].borrow()),
"VG" => Some([(4, A), (16, N)].borrow()),
"XK" => Some([(4, N), (10, N), (2, N)].borrow()),
"YE" => Some([(4, A), (4, N), (18, C)].borrow()),
_ => None,
})
.ok_or(ParseIbanError::UnknownCountry(base_iban))
Expand Down
73 changes: 64 additions & 9 deletions iban_validate/tests/registry_examples.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ struct RegistryExample<'a> {

#[test]
fn test_registry_examples() -> Result<(), ParseIbanError> {
//
let examples: &[RegistryExample] = &[
RegistryExample {
country_code: "AD",
Expand Down Expand Up @@ -151,6 +150,14 @@ fn test_registry_examples() -> Result<(), ParseIbanError> {
iban_electronic: "DE89370400440532013000",
iban_print: "DE89 3704 0044 0532 0130 00",
},
RegistryExample {
country_code: "DJ",
bank_identifier: Some("00010"),
branch_identifier: Some("00000"),
bban: "00010000000154000100186",
iban_electronic: "DJ2100010000000154000100186",
iban_print: "DJ21 0001 0000 0001 5400 0100 186",
},
RegistryExample {
country_code: "DK",
bank_identifier: Some("0040"),
Expand Down Expand Up @@ -199,6 +206,14 @@ fn test_registry_examples() -> Result<(), ParseIbanError> {
iban_electronic: "FI2112345600000785",
iban_print: "FI21 1234 5600 0007 85",
},
RegistryExample {
country_code: "FK",
bank_identifier: Some("SC"),
branch_identifier: None,
bban: "SC123456789012",
iban_electronic: "FK88SC123456789012",
iban_print: "FK88 SC12 3456 7890 12",
},
RegistryExample {
country_code: "FO",
bank_identifier: Some("6460"),
Expand Down Expand Up @@ -431,6 +446,14 @@ fn test_registry_examples() -> Result<(), ParseIbanError> {
iban_electronic: "MK07250120000058984",
iban_print: "MK07 2501 2000 0058 984",
},
RegistryExample {
country_code: "MN",
bank_identifier: Some("1234"),
branch_identifier: None,
bban: "1234123456789123",
iban_electronic: "MN121234123456789123",
iban_print: "MN12 1234 1234 5678 9123",
},
RegistryExample {
country_code: "MR",
bank_identifier: Some("00020"),
Expand All @@ -455,6 +478,14 @@ fn test_registry_examples() -> Result<(), ParseIbanError> {
iban_electronic: "MU17BOMM0101101030300200000MUR",
iban_print: "MU17 BOMM 0101 1010 3030 0200 000M UR",
},
RegistryExample {
country_code: "NI",
bank_identifier: Some("BAPR"),
branch_identifier: None,
bban: "BAPR00000013000003558124",
iban_electronic: "NI04BAPR00000013000003558124",
iban_print: "NI04 BAPR 0000 0013 0000 0355 8124",
},
RegistryExample {
country_code: "NL",
bank_identifier: Some("ABNA"),
Expand All @@ -472,12 +503,12 @@ fn test_registry_examples() -> Result<(), ParseIbanError> {
iban_print: "NO93 8601 1117 947",
},
RegistryExample {
country_code: "PK",
bank_identifier: Some("SCBL"),
country_code: "OM",
bank_identifier: Some("018"),
branch_identifier: None,
bban: "SCBL0000001123456702",
iban_electronic: "PK36SCBL0000001123456702",
iban_print: "PK36 SCBL 0000 0011 2345 6702",
bban: "0180000001299123456",
iban_electronic: "OM810180000001299123456",
iban_print: "OM81 0180 0000 0129 9123 456",
},
RegistryExample {
country_code: "PL",
Expand All @@ -498,7 +529,7 @@ fn test_registry_examples() -> Result<(), ParseIbanError> {
RegistryExample {
country_code: "PT",
bank_identifier: Some("0002"),
branch_identifier: None,
branch_identifier: Some("0123"),
bban: "000201231234567890154",
iban_electronic: "PT50000201231234567890154",
iban_print: "PT50 0002 0123 1234 5678 9015 4",
Expand Down Expand Up @@ -527,6 +558,14 @@ fn test_registry_examples() -> Result<(), ParseIbanError> {
iban_electronic: "RS35260005601001611379",
iban_print: "RS35 2600 0560 1001 6113 79",
},
RegistryExample {
country_code: "RU",
bank_identifier: Some("044525225"),
branch_identifier: Some("40817"),
bban: "044525225 40817 810 5 3809 1310419",
iban_electronic: "RU1704452522540817810538091310419",
iban_print: "RU17 0445 2522 5408 1781 0538 0913 1041 9",
},
RegistryExample {
country_code: "SA",
bank_identifier: Some("80"),
Expand Down Expand Up @@ -583,6 +622,14 @@ fn test_registry_examples() -> Result<(), ParseIbanError> {
iban_electronic: "SM86U0322509800000000270100",
iban_print: "SM86 U032 2509 8000 0000 0270 100",
},
RegistryExample {
country_code: "SO",
bank_identifier: Some("1000"),
branch_identifier: Some("001"),
bban: "1000001001000100141",
iban_electronic: "SO211000001001000100141",
iban_print: "SO21 1000 0010 0100 0100 141",
},
RegistryExample {
country_code: "ST",
bank_identifier: Some("0001"),
Expand Down Expand Up @@ -655,6 +702,14 @@ fn test_registry_examples() -> Result<(), ParseIbanError> {
iban_electronic: "XK051212012345678906",
iban_print: "XK05 1212 0123 4567 8906",
},
RegistryExample {
country_code: "YE",
bank_identifier: Some("CBYE"),
branch_identifier: Some("0001"),
bban: "CBYE0001018861234567891234",
iban_electronic: "YE15CBYE0001018861234567891234",
iban_print: "YE15 CBYE 0001 0188 6123 4567 8912 34",
},
];

for RegistryExample {
Expand All @@ -666,8 +721,8 @@ fn test_registry_examples() -> Result<(), ParseIbanError> {
iban_print,
} in examples
{
if *country_code == "ST" {
// Incredibly, the IBAN for ST actually has an incorrect checksum. Yes, the example of a correct IBAN is incorrect.
if matches!(*country_code, "NI" | "RU" | "ST") {
// For these country codes, the provided IBAN is actually invalid. We will just ignore them.
continue;
}

Expand Down
1 change: 0 additions & 1 deletion iban_validate/tests/validate_country.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ fn test_valid_countries() -> Result<(), ParseIbanError> {
"MU17BOMM0101101030300200000MUR",
"NL91ABNA0417164300",
"NO9386011117947",
"PK36SCBL0000001123456702",
"PL61109010140000071219812874",
"PS92PALS000000000400123456702",
"PT50000201231234567890154",
Expand Down

0 comments on commit dc9ba5a

Please sign in to comment.