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:
| System | Type | Input string | Check character(s) |
|---|---|---|---|
| ISO/IEC 7064, MOD 11-2 | Pure | Numeric (0-9) | 1 digit or 'X' (0-9X) |
| ISO/IEC 7064, MOD 37-2 | Pure | Alphanumeric (0-9A-Z) | 1 digit, letter, or '*' (0-9A-Z*) |
| ISO/IEC 7064, MOD 97-10 | Pure | Numeric (0-9) | 2 digits (0-9) |
| ISO/IEC 7064, MOD 661-26 | Pure | Alphabetic (A-Z) | 2 letters (A-Z) |
| ISO/IEC 7064, MOD 1271-36 | Pure | Alphanumeric (0-9A-Z) | 2 digits or letters (0-9A-Z) |
| ISO/IEC 7064, MOD 11,10 | Hybrid | Numeric (0-9) | 1 digit (0-9) |
| ISO/IEC 7064, MOD 27,26 | Hybrid | Alphabetic (A-Z) | 1 letter (A-Z) |
| ISO/IEC 7064, MOD 37,36 | Hybrid | Alphanumeric (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 overString.
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
Systemstructure 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.