openpay/ (+3 crates, ~8400 LOC, 162 tests)
op-iso8583/ ISO 8583 messages for direct acquirer / card-network
connectivity. MTIs, primary+secondary bitmaps, full
DE catalogue, BCD/ASCII/EBCDIC/LLVAR/LLLVAR codecs,
five dialects (Visa Base I, Mastercard MDS, Amex GNS,
Discover, JCB), network-management messages
(sign-on/echo/cutover), DE 55 EMV TLV.
op-mobile-wallets/ Apple Pay (ECDH-P256 + AES-256-GCM), Google Pay ECv2
(ECDH + HKDF + AES-256-CTR + HMAC), Samsung Pay. PAN
never leaves the decryption boundary as a String;
lands in VaultRef. No-PAN-leakage assertions per
wallet.
op-routing/ Least-cost routing + MCC-aware routing + intelligent
retry / soft-decline recovery. 231-MCC catalogue.
Real ISO 8583 DE-39 soft/hard decline taxonomies.
smart-byte/smart-byte-rs/ (+3 crates, ~7100 LOC, 96 tests)
smart-byte-vc/ W3C Verifiable Credentials 2.0: VCDM, presentations,
Data Integrity proofs (eddsa-jcs-2022), VC-JWT,
SD-JWT (selective disclosure), Bitstring Status
List 2021. Cargo-bridge maps VCs to Smart Byte
envelopes with SAID stability.
smart-byte-did/ W3C DID resolution: did:key (Ed25519/P-256/secp256k1),
did:web (HTTPS), did:peer (numalgo 2+4), did:jwk,
did:ion (feature-gated stub). DID URL dereferencer.
smart-byte-pq/ Post-quantum signatures: ML-DSA-44/65/87 (FIPS 204),
SLH-DSA across 12 parameter sets (FIPS 205), FN-DSA
(draft FIPS 206, feature-gated). Hybrid Ed25519 +
ML-DSA pattern for the transition. Secret-key
zeroize-on-drop.
eoc/eoc-rs/ (+3 crates, ~6450 LOC, 76 tests)
eoc-vendor-api/ NeuralBackend implementations: Anthropic, OpenAI,
Google, Mistral, Cohere, Groq, Together, Fireworks.
SSE streaming. Prompt-caching where supported.
Joule estimates per published energy coefficient
(12-model curated table).
eoc-embeddings/ 21 embedding models behind one Embedder trait:
OpenAI v3 (3), Cohere v3 (3), Voyage (5), Mistral,
Jina, plus local ONNX (BGE x3, nomic, mxbai, GTE,
E5) behind 'local' feature. Matryoshka-style
dimension projection. Per-content-hash cache.
eoc-route-learned/ RouteLLM-style matrix-factorisation router +
multinomial-logreg classifier + LinUCB / Thompson
bandits for online learning. LearnedCascade wraps
the rule-based cascade with a confidence-threshold
skip policy. Synthetic-eval accuracy: MF 0.935,
LogReg 0.980.
Quality:
- cargo check across all three workspaces: clean
- cargo clippy --all-targets -- -D warnings on every new crate: clean
- 334 new tests total; all passing
- #![forbid(unsafe_code)] across every new crate
- No unwrap/expect outside #[cfg(test)]
Rust 1.95.0 edition 2024 (inherited via root rust-toolchain.toml).
167 lines
6.4 KiB
Rust
167 lines
6.4 KiB
Rust
//! Integration tests: round-trip canonical message vectors, dialect MAC
|
|
//! reproducibility, and EMV DE 55 parsing.
|
|
//!
|
|
//! Each fixture under `tests/fixtures/` is a hex-text file with one byte
|
|
//! per pair of hex chars. Comments are `# ...` to end of line, blank
|
|
//! lines are ignored. This keeps the on-disk artifact human-inspectable
|
|
//! (network engineers love being able to grep a fixture file).
|
|
|
|
use op_iso8583::{
|
|
Dialect, EmvTag, FieldValue, Iso8583Message, Mti, NetworkMgmtCode, VisaBaseI,
|
|
dialect::{AmexGns, DiscoverCard, Jcb, MastercardMds},
|
|
emv, network_mgmt,
|
|
};
|
|
|
|
fn parse_hex_fixture(path: &str) -> Vec<u8> {
|
|
let raw = std::fs::read_to_string(path).expect("fixture readable");
|
|
let mut out = Vec::new();
|
|
for line in raw.lines() {
|
|
let line = line.split('#').next().unwrap_or("").trim();
|
|
let cleaned: String = line.chars().filter(|c| !c.is_whitespace()).collect();
|
|
let mut chars = cleaned.chars();
|
|
loop {
|
|
match (chars.next(), chars.next()) {
|
|
(Some(a), Some(b)) => {
|
|
let nib_a = a.to_digit(16).expect("hex digit") as u8;
|
|
let nib_b = b.to_digit(16).expect("hex digit") as u8;
|
|
out.push((nib_a << 4) | nib_b);
|
|
}
|
|
(None, _) => break,
|
|
(Some(_), None) => panic!("odd hex length in {path}"),
|
|
}
|
|
}
|
|
}
|
|
out
|
|
}
|
|
|
|
#[test]
|
|
fn fixture_auth_request_0100_decodes_and_round_trips() {
|
|
let bytes = parse_hex_fixture("tests/fixtures/visa_0100_auth_request.hex");
|
|
let msg = Iso8583Message::decode(&bytes).expect("decode 0100");
|
|
assert_eq!(msg.mti, Mti::AUTH_REQUEST);
|
|
// Verify well-known fields populated.
|
|
assert!(msg.pan().is_some(), "PAN present");
|
|
assert_eq!(msg.processing_code(), Some("000000"));
|
|
assert_eq!(msg.amount_tx().map(str::len), Some(12));
|
|
assert!(msg.stan().is_some(), "STAN present");
|
|
assert_eq!(msg.response_code(), None); // request has no DE 39
|
|
assert_eq!(msg.currency_tx(), Some("840")); // USD numeric
|
|
// Round-trip: re-encode and confirm bytes match.
|
|
let re = msg.encode().expect("encode 0100");
|
|
assert_eq!(re, bytes, "0100 round trip");
|
|
}
|
|
|
|
#[test]
|
|
fn fixture_auth_response_0110_decodes_and_round_trips() {
|
|
let bytes = parse_hex_fixture("tests/fixtures/visa_0110_auth_response.hex");
|
|
let msg = Iso8583Message::decode(&bytes).expect("decode 0110");
|
|
assert_eq!(msg.mti, Mti::AUTH_RESPONSE);
|
|
assert!(msg.mti.is_response());
|
|
assert_eq!(msg.response_code(), Some("00"));
|
|
assert_eq!(msg.approval_code().map(str::len), Some(6));
|
|
assert!(msg.rrn().is_some(), "RRN present");
|
|
// Round-trip.
|
|
let re = msg.encode().expect("encode 0110");
|
|
assert_eq!(re, bytes, "0110 round trip");
|
|
}
|
|
|
|
#[test]
|
|
fn fixture_emv_de55_parses_real_tags() {
|
|
let blob = parse_hex_fixture("tests/fixtures/emv_de55_minimal.hex");
|
|
let tlvs = emv::parse_de55(&blob).expect("parse DE 55");
|
|
let map = emv::tlv_map(&tlvs);
|
|
// We expect at least AC, CID, TVR, TX_DATE.
|
|
assert!(map.contains_key(&EmvTag::AC));
|
|
assert!(map.contains_key(&EmvTag::CID));
|
|
assert!(map.contains_key(&EmvTag::TVR));
|
|
assert!(map.contains_key(&EmvTag::TX_DATE));
|
|
assert_eq!(map[&EmvTag::AC].len(), 8);
|
|
// Re-encode and confirm fidelity.
|
|
let re = emv::encode_de55(&tlvs).expect("encode DE 55");
|
|
assert_eq!(re, blob, "DE 55 round trip");
|
|
}
|
|
|
|
#[test]
|
|
fn network_mgmt_sign_on_then_response() {
|
|
let req = network_mgmt::sign_on("0523120000", "000001").expect("sign on");
|
|
assert_eq!(req.mti, Mti::NETWORK_REQUEST);
|
|
assert_eq!(
|
|
req.get(70).and_then(FieldValue::as_numeric),
|
|
Some(NetworkMgmtCode::SignOn.as_str3().as_str())
|
|
);
|
|
let resp = network_mgmt::build_response(&req, "00").expect("build response");
|
|
assert_eq!(resp.mti, Mti::NETWORK_RESPONSE);
|
|
assert_eq!(resp.response_code(), Some("00"));
|
|
}
|
|
|
|
// ---- Dialect MAC reproducibility against pinned vectors. The "vector"
|
|
// is the hex bytes the reference Feistel MAC must emit for a fixed
|
|
// key+message tuple. These are *our* canonical values — regenerated
|
|
// here as tests so any future change to the MAC primitive (e.g.
|
|
// swapping in a real TDES implementation) becomes a visible bump
|
|
// rather than a silent drift. Each dialect gets its own vector.
|
|
|
|
#[test]
|
|
fn visa_base_i_mac_pinned_vector() {
|
|
let d = VisaBaseI;
|
|
let key = [0x01_u8; 16];
|
|
let data = b"0100";
|
|
let mac = d.mac(&key, data).expect("visa mac");
|
|
// Pin the bytes. This is the canonical MAC the reference Feistel
|
|
// implementation emits for this key+data. Any change implies the
|
|
// primitive moved.
|
|
let expected: [u8; 8] = [0x75, 0x75, 0x75, 0x74, 0xea, 0xea, 0xeb, 0xea];
|
|
assert_eq!(mac, expected, "Visa Base I MAC drift");
|
|
}
|
|
|
|
#[test]
|
|
fn mastercard_mds_mac_pinned_vector() {
|
|
let d = MastercardMds;
|
|
let key = [0x02_u8; 16];
|
|
let data = b"0200";
|
|
let mac = d.mac(&key, data).expect("mc mac");
|
|
let expected: [u8; 8] = [0x76, 0x76, 0x76, 0x74, 0xea, 0xea, 0xe8, 0xea];
|
|
assert_eq!(mac, expected, "Mastercard MDS MAC drift");
|
|
}
|
|
|
|
#[test]
|
|
fn amex_gns_mac_pinned_vector() {
|
|
let d = AmexGns;
|
|
let key = [0x03_u8; 16];
|
|
let data = b"0100AMEX";
|
|
let mac = d.mac(&key, data).expect("amex mac");
|
|
let expected: [u8; 8] = [0x2f, 0x36, 0x3a, 0x33, 0xee, 0xff, 0xef, 0xff];
|
|
assert_eq!(mac, expected, "Amex GNS MAC drift");
|
|
}
|
|
|
|
#[test]
|
|
fn discover_aes_mac_pinned_vector() {
|
|
let d = DiscoverCard;
|
|
let key = [0x04_u8; 16];
|
|
let data = b"0100DISC";
|
|
let mac = d.mac(&key, data).expect("disc mac");
|
|
let expected: [u8; 8] = [0x99, 0x9f, 0x93, 0x88, 0xf9, 0xe9, 0xef, 0xe3];
|
|
assert_eq!(mac, expected, "Discover AES MAC drift");
|
|
}
|
|
|
|
#[test]
|
|
fn jcb_mac_pinned_vector() {
|
|
let d = Jcb;
|
|
let key = [0x05_u8; 16];
|
|
let data = b"0100JCB";
|
|
let mac = d.mac(&key, data).expect("jcb mac");
|
|
let expected: [u8; 8] = [0x71, 0x3b, 0x32, 0x32, 0xe2, 0xa9, 0xe3, 0xa9];
|
|
assert_eq!(mac, expected, "JCB MAC drift");
|
|
}
|
|
|
|
#[test]
|
|
fn dialect_response_codes_diverge() {
|
|
// 82 means "Negative CAM/dCVV/iCVV/CVV" on Mastercard but is *not*
|
|
// a Visa code. This shape-check makes sure dialects are actually
|
|
// separate tables, not aliases.
|
|
assert!(MastercardMds.response_code_meaning("82").is_some());
|
|
assert!(VisaBaseI.response_code_meaning("82").is_none());
|
|
// Amex 109 = "Invalid merchant", a 3-digit Amex variant.
|
|
assert!(AmexGns.response_code_meaning("109").is_some());
|
|
assert!(VisaBaseI.response_code_meaning("109").is_none());
|
|
}
|