ISO8583
A high-performance Rust library for parsing and serializing ISO 8583 financial messages.
JSON-spec-driven architecture with support for Visa BASE I, Mastercard MIP, and generic ISO 8583 — no code changes needed for new networks.
ISO8583 is a production-ready Rust library for handling ISO 8583 financial messages used in payment card transactions. Field definitions live entirely in JSON specification files — adding support for new card networks or custom fields requires zero code changes. The library ships with bundled specs for Generic ISO 8583, Visa BASE I, and Mastercard MIP.
Key Features
- JSON-Spec-Driven: Field definitions, encodings, padding, and validation rules all live in JSON — extend or customize without touching Rust code
- Multi-Network Support: Bundled specs for Generic ISO 8583:1987, Visa BASE I, and Mastercard MIP with correct encoding defaults
- Multi-Encoding: ASCII, EBCDIC (CP037), BCD (packed Binary Coded Decimal), and Binary/Hex encodings
- Composite Fields: Ordered subfields, TLV (EMV ICC data with BER-TLV), Bitmap-based composites, and Mastercard PDS (Private Data Subelements)
- Non-Blocking Validation: Accumulates all validation errors instead of failing on the first — MTI, mandatory fields, format, length, pattern, and response code checks
- Bitmap Support: Primary, secondary, and tertiary bitmaps with hex and binary encodings (up to 192 data elements)
- Response Code Lookup: 87 standard DE 39 response codes with lazy-loaded lookup
- Performance Optimized: O(1) field lookup via HashMap, zero-copy where possible, minimal allocations
- 67 Tests: Comprehensive test coverage across all encodings, networks, and composite field types
Architecture
JSON Specification System
The library is driven by JSON spec files that define per-field encoding, prefix type, padding, and validation rules. Each spec has defaults that individual fields can override:
Data Flow
Parsing: hex string → decode MTI → decode bitmap → unpack each field → JSON output
Publishing: JSON input → encode MTI → encode bitmap → pack each field → hex string
Bundled Specifications
| Spec | Version | Encoding | Prefix | Bitmap | MTI | Bitmaps | Network |
|---|---|---|---|---|---|---|---|
fields.json |
1987 | ASCII | ASCII | Hex | ASCII | 2 | Generic ISO 8583 |
visa_base1.json |
2003 | EBCDIC | BCD | Binary | BCD | 3 | Visa BASE I |
mastercard_mip.json |
2003 | EBCDIC | BCD | Binary | ASCII | 2 | Mastercard MIP |
Installation
Add iso8583-codec-rs to your Cargo.toml:
[]
= "0.1"
Usage
Basic Parsing and Publishing
use ;
use json;
// Load a specification
let spec_json = include_str!;
let spec = load_spec.unwrap;
// Build a message as JSON
let message = json!;
// Publish to hex-encoded ISO 8583
let hex_message = publish.unwrap;
// Parse back to JSON
let parsed = parse.unwrap;
assert_eq!;
assert_eq!;
Network-Specific Messages
use ;
use json;
// Visa BASE I (EBCDIC + BCD prefix + Binary bitmap + BCD MTI)
let visa_spec = load_spec.unwrap;
let visa_auth = json!;
let hex = publish.unwrap;
let parsed = parse.unwrap;
// Mastercard MIP (EBCDIC data + ASCII MTI + BCD prefix + Binary bitmap)
let mc_spec = load_spec.unwrap;
let mc_auth = json!;
let hex = publish.unwrap;
let parsed = parse.unwrap;
Composite Fields
The library handles four types of composite fields transparently:
use json;
// Ordered: subfields concatenated in sequence (e.g., DE 22 POS Entry Mode)
"de022_pos_entry_mode":
// TLV: Tag-Length-Value for EMV data (e.g., DE 55)
// Supports 1-byte, 2-byte, and 3-byte tags with BER-TLV length encoding
"de055_emv_data":
// Bitmap: internal bitmap indicating present subfields (e.g., Visa DE 62)
"de062_custom_payment_service":
// PDS: Mastercard Private Data Subelements (e.g., Mastercard DE 48)
"de048_additional_data_private":
Validation
Validation is non-blocking and accumulates all errors:
use ;
use json;
let spec = load_spec.unwrap;
let message = json!;
let result = validate;
if result.is_valid else
Validation rules include:
- MTI: Format (4 digits), version (0/1/2/9), class (1-8), function (0-5)
- Mandatory fields: Per-MTI required field checks
- Format: Numeric (digits only), binary (hex only), x+n (C/D prefix + digits)
- Length: Min/max constraints, fixed-length enforcement
- Pattern: MMDD dates, hhmmss times, YYMM expiry dates
- Response codes: DE 39 validated against 87 known codes
Response Code Lookup
use lookup_response_code;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
Module Overview
| Module | Purpose |
|---|---|
lib.rs |
Public API: parse(), publish(), load_spec(), validate(), lookup_response_code() |
iso8583.rs |
Parse/publish pipeline orchestration, composite field dispatch |
codec.rs |
Field-level encode/decode (ASCII, EBCDIC, BCD, Binary), prefix handling, padding |
bitmap.rs |
Primary/secondary/tertiary bitmap handling (hex and binary) |
mti.rs |
Message Type Indicator encode/decode and classification |
field_spec.rs |
LoadedSpec and FieldSpec structs, JSON spec loading |
validation.rs |
Non-blocking validation with accumulated errors |
error.rs |
Iso8583Error enum with structured error variants |
Encoding Support
| Encoding | Data | Prefix | Bitmap | MTI |
|---|---|---|---|---|
| ASCII | String/Numeric fields | LLVAR/LLLVAR/LLLLVAR length | 16 hex chars per bitmap | 4 ASCII chars |
| EBCDIC (CP037) | String/Numeric fields | LLVAR/LLLVAR/LLLLVAR length | — | 4 EBCDIC chars |
| BCD | Packed numeric (2 digits/byte) | Packed length prefix | — | 2 BCD bytes |
| Binary/Hex | Raw binary data (e.g., PIN block) | — | 8 bytes per bitmap | — |
Testing
# Run all 67 tests
# Run a single test
# Run tests with output visible
# Run network-specific tests
Contributing
Contributions are welcome! If you'd like to help, please feel free to fork the repository, make your changes, and submit a pull request. We ask that you ensure test coverage for new features and follow existing code patterns.
About Plasmatic
ISO8583 is developed by Plasmatic, an organization focused on building open-source tools for financial infrastructure. We believe in transparency, security, and performance.
Check out our other projects:
- SwiftMTMessage: A SWIFT MT message parsing library.
- MXMessage: An ISO 20022 (MX) message parsing library.
- Reframe: A SWIFT MT to ISO 20022 (and back) transformation engine.
License
This library is licensed under the Apache License, Version 2.0. See the LICENSE file for details.