Skip to main content

aamva/
lib.rs

1//! AAMVA DL / ID (PDF417) reader.
2//!
3//! - [`decode_pdf417_from_image_bytes`] / [`decode_pdf417_from_luma8`] — scan
4//!   the PDF417 barcode printed on the back of a US / Canadian driver's
5//!   licence via the [`rxing`] crate.
6//! - [`parse`] — parse the text payload into an [`AamvaLicense`].
7//! - [`parse_license_from_image_bytes`] / [`parse_license_from_luma8`] —
8//!   convenience: scan + parse in one call.
9//!
10//! Covers AAMVA Card Design Standard versions 01–10 (MMDDCCYY dates for USA
11//! jurisdictions, CCYYMMDD for Canada, both tolerated).
12
13pub mod data;
14pub mod error;
15pub mod parser;
16pub mod pdf417;
17
18pub use data::{
19    AamvaHeader, AamvaLicense, Compliance, Country, EyeColor, HairColor, Height, Sex,
20    SubfileDesignator, Truncation,
21};
22pub use error::AamvaError;
23pub use parser::parse;
24pub use pdf417::{decode_pdf417_from_image_bytes, decode_pdf417_from_luma8};
25
26/// Scan the PDF417 on PNG/JPEG image bytes and parse the AAMVA payload.
27pub fn parse_license_from_image_bytes(image_bytes: &[u8]) -> Result<AamvaLicense, AamvaError> {
28    let text = decode_pdf417_from_image_bytes(image_bytes)?;
29    parse(text.as_bytes())
30}
31
32/// Scan the PDF417 on a luma8 buffer and parse the AAMVA payload.
33pub fn parse_license_from_luma8(
34    width: u32,
35    height: u32,
36    luma: Vec<u8>,
37) -> Result<AamvaLicense, AamvaError> {
38    let text = decode_pdf417_from_luma8(width, height, luma)?;
39    parse(text.as_bytes())
40}