#[non_exhaustive]pub struct Checks {
pub document_number: Option<bool>,
pub date_of_birth: Option<bool>,
pub date_of_expiry: Option<bool>,
pub personal_number: Option<bool>,
pub composite: Option<bool>,
}Expand description
Per-field check-digit verification results.
#[non_exhaustive]: a future MRZ format may carry a check digit these five
fields don’t name, and adding it should not be a breaking change. Construct
one from a parse_* function rather than by literal.
Some(true) means the printed check digit verified, Some(false) means it
failed, and None means the format does not print that check digit.
// The ICAO specimen with its date of birth altered: 740812 → 750812.
let doc = mrz::parse_td3(
"P<UTOERIKSSON<<ANNA<MARIA<<<<<<<<<<<<<<<<<<<",
"L898902C36UTO7508122F1204159ZE184226B<<<<<10",
)
.unwrap();
// The damage is located, not merely detected.
assert_eq!(doc.checks.document_number, Some(true));
assert_eq!(doc.checks.date_of_birth, Some(false));
assert_eq!(doc.checks.date_of_expiry, Some(true));
assert_eq!(doc.checks.composite, Some(false)); // the composite covers the date of birth tooFields (Non-exhaustive)§
This struct is marked as non-exhaustive
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.document_number: Option<bool>The primary document-number field (or, for a number too long for it,
the reassembled number — see MrzData::full_document_number).
date_of_birth: Option<bool>The date-of-birth field.
date_of_expiry: Option<bool>The date-of-expiry field.
personal_number: Option<bool>TD3’s personal-number field; absent on the other four formats.
composite: Option<bool>The composite check digit over the zone; absent on MRV-A and MRV-B.
Implementations§
Source§impl Checks
impl Checks
Sourcepub fn all_valid(&self) -> bool
pub fn all_valid(&self) -> bool
Every check digit this format prints agrees with the candidate.
This is checksum consistency, and it is deterministic. It is not
byte-identity with the printed zone: crate::Blindspot gives the
substitutions the arithmetic cannot see, and a field no digit covers
— on TD2 and TD3 that is all of line 1 — is not constrained at all.
let doc = mrz::parse_td2(
"I<UTOERIKSSON<<ANNA<MARIA<<<<<<<<<<<",
"D231458907UTO7408122F1204159<<<<<<<6",
)
.unwrap();
assert!(doc.checks.all_valid());
// TD2 prints no personal-number check digit, so it is explicitly absent.
assert_eq!(doc.checks.personal_number, None);Source§impl Checks
impl Checks
Sourcepub fn applicable(&self) -> u8
pub fn applicable(&self) -> u8
Number of check digits this format prints. A zero-applicable Checks
is never valid: there is no check-digit evidence to establish a read.
use mrz::{parse_td3, Field};
let line1 = "P<UTOERIKSSON<<ANNA<MARIA<<<<<<<<<<<<<<<<<<<";
let good = parse_td3(line1, "L898902C36UTO7408122F1204159ZE184226B<<<<<10").unwrap();
// The date-of-birth check digit misprinted as 3: that check and the composite fail.
let bad = parse_td3(line1, "L898902C36UTO7408123F1204159ZE184226B<<<<<10").unwrap();
assert_eq!(good.checks.applicable(), 5);
assert_eq!(bad.checks.applicable(), 5); // a failed check is still applicableSourcepub fn verified(&self) -> u8
pub fn verified(&self) -> u8
Number of printed check digits that verified.
use mrz::{parse_td3, Field};
let line1 = "P<UTOERIKSSON<<ANNA<MARIA<<<<<<<<<<<<<<<<<<<";
let good = parse_td3(line1, "L898902C36UTO7408122F1204159ZE184226B<<<<<10").unwrap();
// The date-of-birth check digit misprinted as 3: that check and the composite fail.
let bad = parse_td3(line1, "L898902C36UTO7408123F1204159ZE184226B<<<<<10").unwrap();
assert_eq!(good.checks.verified(), 5);
assert_eq!(bad.checks.verified(), 3);Sourcepub fn failed(&self) -> Vec<Field>
pub fn failed(&self) -> Vec<Field>
The fields whose printed check digits failed, in field order. Absent
checks are not failures. Empty when all_valid is
true.
use mrz::{parse_td3, Field};
let line1 = "P<UTOERIKSSON<<ANNA<MARIA<<<<<<<<<<<<<<<<<<<";
let good = parse_td3(line1, "L898902C36UTO7408122F1204159ZE184226B<<<<<10").unwrap();
// The date-of-birth check digit misprinted as 3: that check and the composite fail.
let bad = parse_td3(line1, "L898902C36UTO7408123F1204159ZE184226B<<<<<10").unwrap();
assert!(good.checks.failed().is_empty());
assert_eq!(bad.checks.failed(), vec![Field::DateOfBirth, Field::Composite]);Trait Implementations§
Source§impl<'de> Deserialize<'de> for Checks
Available on crate feature serde only.
impl<'de> Deserialize<'de> for Checks
serde only.