Skip to main content

Checks

Struct Checks 

Source
#[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 too

Fields (Non-exhaustive)§

This struct is marked as non-exhaustive
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional 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

Source

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

Source

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 applicable
Source

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);
Source

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 Clone for Checks

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Checks

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for Checks

Available on crate feature serde only.
Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Eq for Checks

Source§

impl PartialEq for Checks

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl Serialize for Checks

Available on crate feature serde only.
Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for Checks

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.