Skip to main content

Crate iso_7064

Crate iso_7064 

Source
Expand description

§A Rust implementation of ISO/IEC 7064:2003 Check character systems

This crate provides no_std-compatible implementations of the check character (digit) systems specified by ISO/IEC 7064:2003.

use iso_7064::{MOD11_2, MOD1271_36};

assert_eq!(MOD11_2.compute("079")?, ['X']);
assert_eq!(MOD11_2.compute_lax("{0-7-9}"), ['X']);

assert!(MOD11_2.verify("079X")?);
assert!(MOD11_2.verify_lax("{0-7-9}[X]"));
assert!(MOD11_2.verify_from_values([0, 7, 9, 10])?);
assert!(!MOD11_2.verify_from_chars("0790".chars())?);

let mut buf = String::from("ISO 79");
MOD1271_36.protect_lax(&mut buf);
assert_eq!(buf, "ISO 793W");

This crate supports all the eight check character systems as shown below specified by the standard:

SystemTypeInput stringCheck character(s)
ISO/IEC 7064, MOD 11-2PureNumeric (0-9)1 digit or 'X' (0-9X)
ISO/IEC 7064, MOD 37-2PureAlphanumeric (0-9A-Z)1 digit, letter, or '*' (0-9A-Z*)
ISO/IEC 7064, MOD 97-10PureNumeric (0-9)2 digits (0-9)
ISO/IEC 7064, MOD 661-26PureAlphabetic (A-Z)2 letters (A-Z)
ISO/IEC 7064, MOD 1271-36PureAlphanumeric (0-9A-Z)2 digits or letters (0-9A-Z)
ISO/IEC 7064, MOD 11,10HybridNumeric (0-9)1 digit (0-9)
ISO/IEC 7064, MOD 27,26HybridAlphabetic (A-Z)1 letter (A-Z)
ISO/IEC 7064, MOD 37,36HybridAlphanumeric (0-9A-Z)1 digit or letter (0-9A-Z)

This library also provides support, under the extra module, for the variant of MOD 97-10 used in the International Bank Account Number (IBAN). The extra module additionally supports other widely used check character algorithms besides those in ISO/IEC 7064, namely Luhn and GS1.

The types under the system, accumulator, and charset modules provide the building blocks under the hood.

§Crate features

  • alloc (enabled by default) enables APIs operating over String.

Modules§

accumulator
Accumulators for check character computation and verification.
charset
Character set types for mapping between characters and their numerical values.
extra
Check character algorithms other than ISO/IEC 7064.
system
The System structure providing a check character system interface.

Constants§

MOD11_2
The ISO/IEC 7064, MOD 11-2 pure system with a single check character.
MOD11_10
The ISO/IEC 7064, MOD 11,10 hybrid system.
MOD27_26
The ISO/IEC 7064, MOD 27,26 hybrid system.
MOD37_2
The ISO/IEC 7064, MOD 37-2 pure system with a single check character.
MOD37_36
The ISO/IEC 7064, MOD 37,36 hybrid system.
MOD97_10
The ISO/IEC 7064, MOD 97-10 pure system with two check characters.
MOD661_26
The ISO/IEC 7064, MOD 661-26 pure system with two check characters.
MOD1271_36
The ISO/IEC 7064, MOD 1271-36 pure system with two check characters.