iranianbank

Crates.ioiranianbank
lib.rsiranianbank
version0.1.0
created_at2025-12-10 17:38:52.998138+00
updated_at2025-12-10 17:38:52.998138+00
descriptionA comprehensive Rust library for validating Iranian bank cards and IBANs (Sheba).
homepagehttps://github.com/farshadsharifi/iranianbank
repositoryhttps://github.com/farshadsharifi/iranianbank
max_upload_size
id1978501
size19,104
Farshad Sharifi (farshadsharifi)

documentation

https://docs.rs/iranianbank

README

IranianBank

Crates.io Documentation License

A comprehensive, high-performance, and zero-dependency Rust library for validating and generating Iranian bank information.

iranianbank provides a robust set of tools to handle Iranian banking data, including Card number validation (Luhn algorithm), IBAN (Sheba) generation and validation, and bank identification.

توضیحات فارسی: کتابخانه‌ای جامع، سریع و بدون وابستگی در زبان راست (Rust) برای اعتبارسنجی و تولید اطلاعات بانکی ایران. این کتابخانه ابزارهایی برای بررسی صحت شماره کارت، تولید و اعتبارسنجی شبا و شناسایی بانک‌ها را فراهم می‌کند.


🚀 Features (امکانات)

English

  • Zero Dependencies: Blazing fast and lightweight, ideal for microservices.
  • Card Validation: Validates 16-digit card numbers using the standard Luhn algorithm.
  • IBAN (Sheba) Tools:
    • Parse and validate existing IBANs (Checksum verification ISO 7064).
    • Generate valid IBANs from account numbers.
    • Extract bank information from IBANs.
  • Bank Directory: Built-in support for major Iranian banks (Melli, Sepah, Pasargad, etc.) with their codes and names.
  • Type-Safe: Leveraging Rust's strong type system with custom error handling.

فارسی

  • بدون وابستگی (Zero Dependencies): بسیار سبک و سریع.
  • اعتبارسنجی کارت: بررسی صحت کارت‌های ۱۶ رقمی با الگوریتم لاهن.
  • ابزارهای شبا (IBAN):
    • بررسی صحت کد شبا (ساختار و Checksum).
    • تولید شبا از روی شماره حساب.
    • استخراج نام بانک از کد شبا.
  • بانک اطلاعاتی: پشتیبانی از بانک‌های اصلی ایران (ملی، سپه، ملت و...) به همراه کدها.
  • ایمن: استفاده از سیستم تایپ Rust و مدیریت خطای اختصاصی.

📦 Installation

Add this to your Cargo.toml:

[dependencies]
iranianbank = "0.1.0"

🛠 Usage Examples (راهنمای استفاده)

1. Validate a Bank Card (اعتبارسنجی کارت بانکی)

Verify if a card number is valid based on the checksum algorithm.

use iranianbank::validate_card;

fn main() {
    let card = "6037997556165554"; // Example Melli Bank card
    
    match validate_card(card) {
        Ok(_) => println!("✅ Card is valid."),
        Err(e) => println!("❌ Invalid card: {}", e),
    }
}

2. IBAN (Sheba) Validation & Parsing (اعتبارسنجی شبا)

Parse an IBAN string to check its validity (length, prefix, and checksum) and extract the bank details.

use iranianbank::{Iban, Bank};

fn main() {
    let raw_iban = "IR720170000000225264111007";

    match Iban::parse(raw_iban) {
        Ok(iban) => {
            println!("✅ IBAN is valid.");
            
            // Extract Bank Information
            if let Ok(bank) = iban.extract_bank() {
                println!("Bank Name: {}", bank.name()); // Output: Melli Bank
                println!("Bank Code: {}", bank.code()); // Output: 017
            }
        },
        Err(e) => println!("❌ Invalid IBAN: {}", e),
    }
}

3. Generate IBAN from Account Number (تولید شبا از شماره حساب)

You can generate a valid IBAN if you have the bank, account type, and account number.

use iranianbank::{Iban, Bank};

fn main() {
    let bank = Bank::Melli;
    let account_type = '0'; // Usually '0' for deposits (سپرده)
    let account_number = "225264111007";

    match Iban::new(bank, account_type, account_number) {
        Ok(iban) => println!("Generated IBAN: {}", iban.as_str()),
        Err(e) => println!("Error generating IBAN: {}", e),
    }
}

4. Working with Bank Codes (کار با کدهای بانکی)

Convert between bank codes and the Bank enum.

use iranianbank::Bank;

fn main() {
    // Find bank by code
    let bank = Bank::from_code("057").unwrap();
    
    if bank == Bank::Pasargad {
        println!("Bank found: {}", bank.name()); // Pasargad Bank
    }
}

🤝 Supported Banks

This library supports a wide range of Iranian banks, including:

Central Bank (بانک مرکزی)

Melli (ملی)

Sepah (سپه)

Saderat (صادرات)

Tejarat (تجارت)

Mellat (ملت)

Pasargad (پاسارگاد)

Parsian (پارسیان)

Saman (سامان)

Ayandeh (آینده)

And more...

⚖️ License

This project is licensed under the MIT License.

👨‍💻 Author

Developed by Farshad Sharifi. Contributions are welcome! Please open an issue or submit a pull request on GitHub.

Commit count: 0

cargo fmt