1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
//! ICAO 9303 Part 4 §4.4 — secondary document codes for machine readable
//! passports.
//!
//! MRZ line 1 positions 1-2 hold the document code. For an MRP the first
//! character is `P`; the second identifies the passport *type* against a table
//! Part 4 §4.4 lists in its table and Note 1:
//!
//! ```text
//! PP National/ordinary passport PT Alien/Non-citizen passport
//! PE Emergency passport PS Stateless passport
//! PD Diplomatic passport PL Laissez-passer passport
//! PO Official/service passport PM Military passport
//! PR Refugee passport PU Single-sheet document (Part 8)
//! ```
//!
//! # Why this table exists when the TD1/TD2 one deliberately does not
//!
//! `knowledge/MRZ_SEQUENCE_COMPLETENESS.md` records a decision *not* to build a
//! document-code dictionary, and that decision stands — but it was reasoned
//! about **TD1 and TD2**. Both notes leave the second character to the
//! issuer and exclude `V`. Part 6 note k excludes `AC`; Part 5 note k
//! excludes `AI` and allows `AC` for a crew member certificate. This remains
//! an open set, so there is no registry to
//! build a dictionary from, and a table assembled from observed codes would be
//! exactly the unproven heuristic this crate refuses to ship.
//!
//! Part 4 is the one format where that reasoning does not apply. §4.4 is a
//! closed normative table, quoted above, and it is already in this repository
//! at `knowledge/docs9303/Doc_9303_Part4_Specs_for_MRPs_and_TD3_MRTDs.md`.
//!
//! # Recognition, never rejection
//!
//! An unrecognised second character does not make a passport unparseable, and
//! [`parse_td3`](crate::parse_td3) still accepts any character the MRZ alphabet
//! allows. §4.4 itself is explicit that conformance is still arriving:
//!
//! > Effective 1 January 2026, MRPs issued with a secondary document code shall
//! > be in accordance with Section 4.4. Effective 1 January 2028, all MRPs shall
//! > be issued with a secondary document code in accordance with Section 4.4.
//! > MRPs issued without a harmonized secondary document code in accordance with
//! > Section 4.4 shall expire before 1 January 2038.
//!
//! So a passport reading `P<` — the filler form, by far the most common in this
//! crate's corpus — is conformant today and will remain valid for years. This
//! module reports what a code *means*; it never decides whether a document is
//! acceptable.
/// The passport type a §4.4 secondary document code designates.
///
/// MRZ line 1 positions 1-2 hold the document code. For a machine readable
/// passport the first character is `P`, and ICAO 9303 Part 4 §4.4 gives the
/// second a closed table of meanings: `PP` national, `PE` emergency,
/// `PD` diplomatic, `PO` official, `PR` refugee, `PT` alien, `PS` stateless,
/// `PL` laissez-passer, `PM` military, and `PU` for Part 8's single-sheet
/// document. TD1 and TD2 get no such table — Parts 5 and 6 leave their second
/// character to the issuer — so there is nothing to recognize there.
///
/// Obtained from [`MrzData::passport_type`](crate::MrzData::passport_type) or
/// [`passport_type`]. `None` there covers three distinct situations that
/// callers usually want to keep apart, and which this enum deliberately does
/// not merge: a non-passport format, the `P<` filler form carrying no
/// secondary code, and a second character outside the table.
///
/// # Recognition, never rejection
///
/// An unrecognised second character does not make a passport unparseable, and
/// [`parse_td3`](crate::parse_td3) still accepts any character the MRZ alphabet
/// allows. §4.4 is explicit that conformance is still arriving: from
/// 1 January 2028 every newly issued passport must carry a §4.4 code, and
/// passports issued without one remain valid until 1 January 2038. So `P<` —
/// the filler form, by far the most common in real documents today — is
/// conformant, and this type reports what a code *means* without ever deciding
/// whether a document is acceptable.
///
/// ```
/// use mrz::{passport_type, PassportType};
///
/// let t = PassportType::Diplomatic;
/// assert_eq!(t.code(), "PD");
/// assert_eq!(t.name(), "Diplomatic passport");
///
/// // Every code in the table round-trips through the lookup.
/// assert!(PassportType::ALL.iter().all(|&t| passport_type(t.code()) == Some(t)));
/// ```
/// Looks up a document code against the §4.4 table.
///
/// Accepts the code as it appears in the MRZ, trailing filler included, so both
/// `"PP"` and a already-trimmed `"P"` behave sensibly:
///
/// ```
/// use mrz::{passport_type, PassportType};
///
/// assert_eq!(passport_type("PD"), Some(PassportType::Diplomatic));
/// assert_eq!(passport_type("PP"), Some(PassportType::National));
///
/// // `P<` is the filler form: a passport with no secondary code, which is
/// // conformant today and not the same thing as an unknown code.
/// assert_eq!(passport_type("P<"), None);
/// assert_eq!(passport_type("P"), None);
///
/// // Not in the table, and not a passport at all.
/// assert_eq!(passport_type("PZ"), None);
/// assert_eq!(passport_type("ID"), None);
/// ```