ISO8583 library written in Rust
(This project is mostly WIP)
``` rust
extern crate byteorder; extern crate hex;
extern crate lazy_static;
extern crate log; extern crate simplelog;
use std::collections::HashMap; use std::time::Duration;
use iso8583rs::iso8583::{bitmap, IsoError}; use iso8583rs::iso8583::isospec::IsoMsg; use iso8583rs::iso8583::msgprocessor::MsgProcessor; use iso8583rs::iso8583::server::IsoServer;
// Below is an example implementation of a MsgProcessor i.e the entity responsible for handling incoming messages // at the server
pub struct SampleMsgProcessor {}
impl MsgProcessor for SampleMsgProcessor {
fn process(&self, isoserver: &IsoServer, msg: &mut Vec
let mut iso_resp_msg = IsoMsg {
spec: &iso_msg.spec,
msg: &iso_msg.spec.get_message_from_header("1110").unwrap(),
fd_map: HashMap::new(),
bmp: bitmap::new_bmp(0, 0, 0),
};
// process the incoming request based on amount
match iso_msg.bmp_child_value(4) {
Ok(amt) => {
iso_resp_msg.set("message_type", "1110");
match amt.parse::<u32>() {
Ok(i_amt) => {
debug!("amount = {}", i_amt);
if i_amt < 100 {
iso_resp_msg.set_on(38, "APPR01");
iso_resp_msg.set_on(39, "000");
} else {
iso_resp_msg.set_on(39, "100");
}
iso_resp_msg.set_on(63, "007");
}
Err(e) => {
iso_resp_msg.set_on(39, "107");
}
};
match iso_resp_msg.echo_from(&iso_msg, &[2, 3, 4, 11, 14, 19, 96]) {
Err(e) => {
error!("failed to echo fields into response. error = {}", "!");
}
_ => {}
};
iso_resp_msg.fd_map.insert("bitmap".to_string(), iso_resp_msg.bmp.as_vec());
}
Err(e) => {
iso_resp_msg.set("message_type", "1110");
iso_resp_msg.set_on(39, "115");
match iso_resp_msg.echo_from(&iso_msg, &[2, 3, 4, 11, 14, 19, 96]) {
Err(e) => {
error!("failed to echo fields into response. error = {}", "!");
}
_ => {}
};
}
}
match iso_resp_msg.assemble() {
Ok(resp_data) => Ok((resp_data, iso_resp_msg)),
Err(e) => {
error!("Failed to assemble response message - {}", e.msg);
Err(IsoError { msg: format!("error: msg assembly failed..{} ", e.msg) })
}
}
}
Err(e) => {
Err(IsoError { msg: e.msg })
}
}
}
}
fn main() { std::env::setvar("SPECFILE", "samplespec\samplespec.yaml");
let _ = simplelog::SimpleLogger::init(simplelog::LevelFilter::Debug, simplelog::Config::default());
let iso_spec = iso8583_rs::iso8583::iso_spec::spec("");
info!("starting iso server for spec {} at port {}", iso_spec.name(), 6666);
let server: IsoServer = match iso8583_rs::iso8583::server::new("localhost:6666".to_string(), Box::new(SampleMsgProcessor {}), iso_spec) {
Ok(server) => {
server
}
Err(e) => {
panic!(e)
}
};
server.start().join();
}
```
``
Finished dev [unoptimized + debuginfo] target(s) in 1.71s
Running
target\debug\iso8583rs.exe`
current-dir: C:\Users\rkbal\IdeaProjects\iso8583rs
spec-file: samplespec\samplespec.yaml
15:36:36 [INFO] starting iso server for spec SampleSpec at port 6666
15:36:42 [DEBUG] (2) iso8583rs::iso8583::server: Accepted new connection .. Ok(V6([::1]:56615))
15:36:42 [DEBUG] (3) iso8583rs::iso8583::server: received request len = 89 : data = 31313030f02420000000100080000001000000000000000100000000313231323334353637383931303130303430303030303030303030303031393937373935383132323034f8f4f001020304050607083132333438383838
15:36:42 [DEBUG] (3) iso8583rs::iso8583::isospec: computed header value for incoming message = 1100
15:36:42 [DEBUG] (3) iso8583rs::iso8583::isospec: parsing field : messagetype
15:36:42 [DEBUG] (3) iso8583rs::iso8583::isospec: parsing field : bitmap
15:36:42 [DEBUG] (3) iso8583rs::iso8583::bitmap: parsing field - pan
15:36:42 [DEBUG] (3) iso8583rs::iso8583::bitmap: parsing field - proccode
15:36:42 [DEBUG] (3) iso8583rs::iso8583::bitmap: parsing field - amount
15:36:42 [DEBUG] (3) iso8583rs::iso8583::bitmap: parsing field - stan
15:36:42 [DEBUG] (3) iso8583rs::iso8583::bitmap: parsing field - expirationdate
15:36:42 [DEBUG] (3) iso8583rs::iso8583::bitmap: parsing field - countrycode
15:36:42 [DEBUG] (3) iso8583rs::iso8583::bitmap: parsing field - pindata
15:36:42 [DEBUG] (3) iso8583rs::iso8583::bitmap: parsing field - keymgmtdata
15:36:42 [DEBUG] (3) iso8583rs::iso8583::bitmap: parsing field - reserveddata
15:36:42 [DEBUG] (3) iso8583rs: parsed incoming request - message = "1100 - Authorization" successfully.
: parsed message:
messagetype : 1100 bitmap : f02420000000100080000001000000000000000100000000 pan [002]: 123456789101 proccode [003]: 004000 amount [004]: 000000000199 stan [011]: 779581 expirationdate [014]: 2204 countrycode [019]: 840 pindata [052]: 0102030405060708 keymgmtdata [096]: 1234 reserveddata [160]: 8888
15:36:42 [DEBUG] (3) iso8583rs: amount = 199 15:36:42 [DEBUG] (3) iso8583rs::iso8583::isospec: echoing .. 2: 123456789101 15:36:42 [DEBUG] (3) iso8583rs::iso8583::isospec: echoing .. 3: 004000 15:36:42 [DEBUG] (3) iso8583rs::iso8583::isospec: echoing .. 4: 000000000199 15:36:42 [DEBUG] (3) iso8583rs::iso8583::isospec: echoing .. 11: 779581 15:36:42 [DEBUG] (3) iso8583rs::iso8583::isospec: echoing .. 14: 2204 15:36:42 [DEBUG] (3) iso8583rs::iso8583::isospec: echoing .. 19: 840 15:36:42 [DEBUG] (3) iso8583rs::iso8583::isospec: echoing .. 96: 1234 15:36:42 [DEBUG] (3) iso8583rs::iso8583::server: iso_response raw:: 31313130f0242000020000020000000100000000313231323334353637383931303130303430303030303030303030303031393937373935383132323034f8f4f0313030f0f0f330303731323334, parsed::
messagetype : 1110 bitmap : f0242000020000020000000100000000 pan [002]: 123456789101 proccode [003]: 004000 amount [004]: 000000000199 stan [011]: 779581 expirationdate [014]: 2204 countrycode [019]: 840 actioncode [039]: 100 private3 [063]: 007 keymgmtdata [096]: 1234
15:36:42 [INFO] client socket closed : [::1]:56615 ```
Now run src/iso8583/test.rs:testsendrecv_iso(..)
```
Testing started at 21:29 ... raw iso msg = 006731313030f02420000000100280000001000000000000000100000000313231323334353637383931303130303430303030303030303030303031393937373935383132323034f8f4f00102030405060708f0f1f138373837373632323532353132333438383838 received response: "31313130f0242000020000020000000100000000313231323334353637383931303130303430303030303030303030303031393937373935383132323034f8f4f0313030f0f0f330303731323334" with 78 bytes. current-dir: C:\Users\rkbal\IdeaProjects\iso8583rs spec-file: samplespec/sample_spec.yaml parsed iso-response "1100 - Authorization"
messagetype : 1110 bitmap : f0242000020000020000000100000000 pan [002]: 123456789101 proccode [003]: 004000 amount [004]: 000000000199 stan [011]: 779581 expirationdate [014]: 2204 countrycode [019]: 840 actioncode [039]: 100 private3 [063]: 007 keymgmtdata [096]: 1234
```