| Crates.io | verhoeff-checksum |
| lib.rs | verhoeff-checksum |
| version | 0.1.0 |
| created_at | 2025-08-11 13:02:27.796851+00 |
| updated_at | 2025-08-11 13:02:27.796851+00 |
| description | A Rust implementation of the Verhoeff checksum algorithm for error detection |
| homepage | |
| repository | https://github.com/yuyudhan/verhoeff.rs |
| max_upload_size | |
| id | 1790141 |
| size | 64,902 |
Rust implementation of the Verhoeff checksum algorithm. Detects 100% of single-digit errors and transposition errors in numerical data.
Add to your Cargo.toml:
[dependencies]
verhoeff = "0.1.0"
Or using cargo-add:
cargo add verhoeff
use verhoeff::{calculate_checksum, validate, validate_aadhaar};
// Calculate checksum digit
let checksum = calculate_checksum("12345678901");
println!("Checksum: {}", checksum); // Output: 0
// Validate number with checksum
let is_valid = validate("123456789010");
println!("Valid: {}", is_valid); // Output: true
// Validate Aadhaar number (12-digit Indian ID)
match validate_aadhaar("123456789010") {
Ok(true) => println!("Valid Aadhaar"),
Ok(false) => println!("Invalid checksum"),
Err(e) => println!("Format error: {}", e),
}
| Function | Description | Example |
|---|---|---|
calculate_checksum(input: &str) -> u8 |
Calculate checksum digit | calculate_checksum("12345") returns 1 |
validate(input: &str) -> bool |
Validate number with checksum | validate("123451") returns true |
append_checksum(input: &str) -> String |
Append checksum to number | append_checksum("12345") returns "123451" |
use verhoeff::validate_aadhaar;
// Returns Result<bool, VerhoeffError>
match validate_aadhaar("123456789010") {
Ok(valid) => println!("Checksum valid: {}", valid),
Err(e) => println!("Error: {}", e),
}
pub enum VerhoeffError {
InvalidCharacter(char), // Non-digit character found
EmptyInput, // Empty string provided
InvalidAadhaarLength(usize), // Not 12 digits
}
Run the included example:
cargo run --example basic_usage
See DEVELOPER.md for development setup, architecture details, and contribution guidelines.
MIT License - see LICENSE file for details.
Ankur Pandey (@yuyudhan)