pub fn parse_it_cf(s: &str) -> Option<String>Expand description
Parse an Italy Codice Fiscale (CF).
The CF is a 16-character alphanumeric identifier issued by the Italian tax authority and used as the de-facto national healthcare identifier. It encodes a coded form of the holder’s name, date of birth, sex, and commune of birth, followed by a Mod-26 check character.
Check-character algorithm:
- For each of the first 15 characters, compute a numeric value using two lookup tables — “odd” positions (1, 3, 5, …, 15; 1-indexed) use the scattered table; “even” positions (2, 4, …, 14) map digits and letters to their natural value.
- Sum the 15 values, take mod 26.
- Map
0..=25toA..=Z. The result MUST equal the 16th character.
Whitespace is stripped and letters are uppercased before parsing. The canonical form is the 16-character uppercase string.
§Examples
use worker_matcher::identifiers::parse_it_cf;
// Synthetic CF with verified check character (sum 122, mod 26 = 18, 18→'S').
assert_eq!(
parse_it_cf("RSSMRA85T10A562S"),
Some("RSSMRA85T10A562S".to_string()),
);
// Lowercase and whitespace tolerated:
assert_eq!(
parse_it_cf("rss mra 85t 10a 562s"),
Some("RSSMRA85T10A562S".to_string()),
);
// Wrong check character:
assert_eq!(parse_it_cf("RSSMRA85T10A562X"), None);
// Wrong length:
assert_eq!(parse_it_cf("RSSMRA85T10A562"), None);
assert_eq!(parse_it_cf("RSSMRA85T10A562SS"), None);
// Non-alphanumeric content:
assert_eq!(parse_it_cf("RSSMRA85T10A562!"), None);
assert_eq!(parse_it_cf(""), None);