taler-rust

GNU Taler code in Rust. Largely core banking integrations.
Log | Files | Refs | Submodules | README | LICENSE

commit c15fe83abd8f5ce43ab3fab83bab94c2aff6c94b
parent bbe790f8a6dad8b65c9e439d7e9a764b70336240
Author: Antoine A <>
Date:   Thu, 19 Nov 2026 17:38:40 +0100

common: sync IBAN registry

Diffstat:
Mcommon/taler-common/src/types/iban/registry.rs | 64++++++++++++++++++++++++----------------------------------------
1 file changed, 24 insertions(+), 40 deletions(-)

diff --git a/common/taler-common/src/types/iban/registry.rs b/common/taler-common/src/types/iban/registry.rs @@ -32,25 +32,15 @@ pub enum IbanC { } impl IbanC { - /// Check if a valid IBAN slice follow a specific characters rules + /// Check whether every byte matches this IBAN character rule pub fn check(self, iban_ascii: &[u8]) -> bool { - // IBAN are made of ASCII digits and uppercase - debug_assert!( - iban_ascii + match self { + Self::N => iban_ascii.iter().all(u8::is_ascii_digit), + Self::A => iban_ascii.iter().all(u8::is_ascii_uppercase), + Self::C => iban_ascii .iter() - .all(|b| b.is_ascii_uppercase() || b.is_ascii_digit()) - ); - // As all characters are ASCII digits or uppercase - // we can use simple masks to check the character kind - const MASK_IS_UPPERCASE: u8 = 0b0100_0000; - const MASK_IS_DIGIT: u8 = 0b0010_0000; - - let mask = match self { - Self::N => MASK_IS_UPPERCASE, - Self::A => MASK_IS_DIGIT, - Self::C => return true, - }; - iban_ascii.iter().all(|b| (*b & mask) == 0) + .all(|b| b.is_ascii_digit() || b.is_ascii_uppercase()), + } } } @@ -580,7 +570,7 @@ impl Country { IQ => 0..4, IS => 0..2, IT => 1..6, - JO => 4..8, + JO => 0..4, KW => 0..4, KZ => 0..3, LB => 0..4, @@ -603,7 +593,7 @@ impl Country { NO => 0..4, OM => 0..3, PK => 0..4, - PL => 0..0, + PL => 0..8, PS => 0..4, PT => 0..4, QA => 0..4, @@ -697,9 +687,9 @@ impl Country { NO => 0..0, OM => 0..0, PK => 0..0, - PL => 0..8, + PL => 0..0, PS => 0..0, - PT => 4..8, + PT => 0..0, QA => 0..0, RO => 0..0, RS => 0..0, @@ -737,7 +727,7 @@ impl Country { BG => &[(4, A), (6, N), (8, C)], BH => &[(4, A), (14, C)], BI => &[(23, N)], - BR => &[(23, N), (1, A), (1, C)], + BR => &[(8, C), (15, N), (2, C)], BY => &[(4, C), (4, N), (16, C)], CH => &[(5, N), (12, C)], CR => &[(18, N)], @@ -831,7 +821,7 @@ impl Country { BG => &[(4, A)], BH => &[(4, A)], BI => &[(5, N)], - BR => &[(8, N)], + BR => &[(8, C)], BY => &[(4, C)], CH => &[(5, N)], CR => &[(4, N)], @@ -862,10 +852,10 @@ impl Country { IQ => &[(4, A)], IS => &[(2, N)], IT => &[(5, N)], - JO => &[(4, N)], + JO => &[(4, A)], KW => &[(4, A)], KZ => &[(3, N)], - LB => &[(4, A)], + LB => &[(4, N)], LC => &[(4, A)], LI => &[(5, N)], LT => &[(5, N)], @@ -879,13 +869,13 @@ impl Country { MN => &[(4, N)], MR => &[(5, N)], MT => &[(4, A)], - MU => &[(6, C)], + MU => &[(4, A), (2, N)], NI => &[(4, A)], NL => &[(4, A)], NO => &[(4, N)], OM => &[(3, N)], PK => &[(4, A)], - PL => &[], + PL => &[(8, N)], PS => &[(4, A)], PT => &[(4, N)], QA => &[(4, A)], @@ -979,9 +969,9 @@ impl Country { NO => &[], OM => &[], PK => &[], - PL => &[(8, N)], + PL => &[], PS => &[], - PT => &[(4, N)], + PT => &[], QA => &[], RO => &[], RS => &[], @@ -1039,15 +1029,9 @@ pub fn rng_pattern(out: &mut [u8], pattern: Pattern) { } } -/// Valid an IBAN slice against a pattern +/// Validate an IBAN slice against a pattern pub fn check_pattern(iban_ascii: &[u8], pattern: Pattern) -> Result<(), PatternErr> { - // IBAN are made of ASCII digits and uppercase - debug_assert!( - iban_ascii - .iter() - .all(|b| b.is_ascii_uppercase() || b.is_ascii_digit()) - ); - let pattern_len: u8 = pattern.iter().map(|(len, _)| *len).sum(); + let pattern_len: u8 = pattern.iter().map(|(len, _)| *len as u8).sum(); if iban_ascii.len() != pattern_len as usize { return Err(PatternErr::Len(pattern_len, iban_ascii.len())); } @@ -1083,8 +1067,8 @@ pub const VALID_IBAN: [(&str, Option<&str>); 89] = [ Some("10000100010000332045181"), ), ( - "BR1800360305000010009795493C1", - Some("00360305000010009795493C1"), + "BR6699999A03000010009795493C1", + Some("99999A03000010009795493C1"), ), ( "BY13NBRB3600900000002Z00AB00", @@ -1113,7 +1097,7 @@ pub const VALID_IBAN: [(&str, Option<&str>); 89] = [ Some("0019000500000000263180002"), ), ("ES9121000418450200051332", Some("21000418450200051332")), - ("FI2112345600000785", None), + ("FI2112345600000785", Some("12345600000785")), ("FK88SC123456789012", Some("SC123456789012")), ("FO6264600001631634", Some("64600001631634")), (