Skip to main content

Crate fprint_fp3

Crate fprint_fp3 

Source
Expand description

§fprint-fp3

The FP3 fingerprint-template codec: the edge translator between libfprint/fprintd’s on-disk "FP3" blob and the fprint_core::Print domain model.

An FP3 blob is the three ASCII bytes "FP3" followed by a little-endian, normal-form GVariant value of type (issbymsmsia{sv}v) (see docs/fp3-format.md). Everything wire-specific — the magic, the GVariant signature, the Julian-day dates with their G_MININT32 sentinel, the maybe-strings, the NBIS (a(aiaiai)) payload — lives here and never leaks up into fprint-core (ARCHITECTURE.md principle 3).

The public surface is to_bytes and from_bytes:

use fprint_core::{Finger, Minutia, Print, Template};

let print = Print::builder()
    .template(Template::Nbis(vec![vec![Minutia { x: 12, y: 34, theta: 90 }]]))
    .finger(Finger::RightIndex)
    .username("alice".to_string())
    .build();

let bytes: Vec<u8> = fprint_fp3::to_bytes(&print)?;
assert!(bytes.starts_with(fprint_fp3::MAGIC));
assert_eq!(fprint_fp3::from_bytes(&bytes)?, print);

§Round-trip

from_bytes(to_bytes(p)) reproduces p for every Print whose finger is Some and whose driver/device_id are either None or non-empty. Outside that, two distinctions collapse because the wire cannot express them:

  • finger: None decodes as Some(Finger::Unknown) — the FP3 y byte has no “absent”.
  • driver/device_id of Some("") decode as None — GVariant s is not nullable, so the empty string is the format’s “unset”.

tests/property.rs states the exact law, collapse included, and sweeps it. to_bytes is partial for two further reasons of its own: Template::Undefined has no on-disk form, and an EnrollDate outside the Julian day’s i32 range has no encoding (Fp3Error::DateOutOfRange).

The signature’s reserved a{sv} metadata dictionary is not a data channel: libfprint always writes it empty, so to_bytes writes it empty and from_bytes ignores whatever it holds. Preserving a populated reserved dict would carry wire bytes inside the domain Print, which principle 3 forbids, so a non-conforming blob with a non-empty reserved dict decodes without it.

Modules§

prelude
The crate’s essentials, for a single glob import.

Enums§

Fp3Error
Everything that can go wrong turning bytes into a Print or back.

Constants§

MAGIC
The FP3 container’s leading magic bytes ("FP3").

Functions§

from_bytes
Parse an FP3 blob back into a Print.
to_bytes
Serialize a Print to an FP3 blob: "FP3" magic followed by the GVariant tuple.

Type Aliases§

Result
Crate result alias.