pub struct DammTable { /* private fields */ }Expand description
Damm quasi-group table for check digit calculation.
The table has the following properties:
- Each row is a permutation of 0..size
- Each column is a permutation of 0..size
- Diagonal is all zeros:
table[i][i] = 0 - Anti-symmetric:
table[a][b] != table[b][a]whena != b
Implementations§
Source§impl DammTable
impl DammTable
Sourcepub fn new(size: usize) -> Self
pub fn new(size: usize) -> Self
Generate a quasi-group table for the given alphabet size.
The generated table guarantees:
- 100% detection of single-character errors
- 100% detection of adjacent transposition errors
§Arguments
size- The alphabet size (10-62)
§Examples
use promocrypt_core::DammTable;
let table = DammTable::new(26);
assert_eq!(table.size(), 26);Sourcepub fn calculate_for_start(&self, chars: &[char], alphabet: &Alphabet) -> char
pub fn calculate_for_start(&self, chars: &[char], alphabet: &Alphabet) -> char
Sourcepub fn calculate_for_position(
&self,
chars: &[char],
alphabet: &Alphabet,
position: usize,
) -> char
pub fn calculate_for_position( &self, chars: &[char], alphabet: &Alphabet, position: usize, ) -> char
Calculate check digit for arbitrary position in the code.
Finds a check digit X such that inserting X at position in chars
results in a valid code (Damm validation returns 0).
§Arguments
chars- The characters (check digit will be inserted at position)alphabet- The alphabet used for character→index mappingposition- Position where check digit will be inserted (0-based)
§Returns
The check digit character from the alphabet.
Sourcepub fn calculate_str(&self, s: &str, alphabet: &Alphabet) -> char
pub fn calculate_str(&self, s: &str, alphabet: &Alphabet) -> char
Calculate check digit for a string.
Sourcepub fn from_bytes(bytes: &[u8]) -> Result<Self>
pub fn from_bytes(bytes: &[u8]) -> Result<Self>
Deserialize table from bytes.
Sourcepub fn from_base64(s: &str) -> Result<Self>
pub fn from_base64(s: &str) -> Result<Self>
Deserialize from base64 string.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for DammTable
impl<'de> Deserialize<'de> for DammTable
Source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
impl Eq for DammTable
impl StructuralPartialEq for DammTable
Auto Trait Implementations§
impl Freeze for DammTable
impl RefUnwindSafe for DammTable
impl Send for DammTable
impl Sync for DammTable
impl Unpin for DammTable
impl UnwindSafe for DammTable
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more