OpenPay (1 crate, 1801 LOC, 57 tests)
op-bin BIN/IIN database + range matching + card-network
classification. 8-digit normalized prefix Bin +
BinRange. Sorted-vec interval tree with O(log N) point
lookup + overlap rejection. CardNetwork classify()
with structural rules (Visa 4, MC 51-55/2221-2720,
Amex 34/37, Discover, JCB, Diners, UnionPay, RuPay,
Mir, Troy, Maestro, Elo). Static prefix tables +
build_default_tree(). ISO/IEC 7812-1 Annex B Luhn
(validate / is_valid / check_digit). Card-type +
issuer-country + Durbin regulated-debit. PCI-safe:
8-digit cap, no full-PAN APIs.
Smart Byte (1 crate, ~1500 LOC, 20 tests)
smart-byte-tendermint BFT consensus. Step enum + Round + propose/prevote/
precommit/commit FSM with voting-power tallies.
ValidatorSet with 2/3+1 quorum, 1/3+1 trust
threshold, round-robin proposer. Block / Header /
Commit / CommitSig with Blake3 hashing. Light client
(sequential + skipping). ABCI Application trait +
EchoApp. DuplicateVoteEvidence + LightClientAttackEvidence.
IBC ClientState + ConsensusState + light-client
update.
EOC (1 crate, 2084 LOC, 23 tests)
eoc-safety AI safety primitives. RegexSet over 16 prompt-injection
signatures. 13-family jailbreak detector (DAN/DUDE/
Grandma/STAN/AIM/dev-mode/etc.). Presidio-style PII
redactor with Luhn-validated CC. Toxicity / bias /
NSFW classifier traits + heuristic baselines (5-axis
bias, 4-category NSFW with hard-reject for minors).
Constitutional AI critique→revise loop. Composable
InputGuard / OutputGuard pipelines. JSON-Schema-subset
output validator. Token-bucket rate limiter +
abuse-window detection. Red-team replay harness.
Co-Authored-By: Claude Opus 4.7 <[email protected]>
53 lines
1.6 KiB
Rust
53 lines
1.6 KiB
Rust
//! Every BIN starting with `4` is Visa, regardless of the
|
|
//! remaining digits. Confirm against representative samples and
|
|
//! boundary digits.
|
|
|
|
use op_bin::{classify, Bin, CardNetwork};
|
|
|
|
#[test]
|
|
fn all_4_prefixes_classify_as_visa() {
|
|
for tail in ["00000", "11111", "55555", "99999", "12345"] {
|
|
let s = format!("4{tail}");
|
|
let b = Bin::parse(&s).expect("valid BIN");
|
|
assert_eq!(
|
|
classify(&b),
|
|
CardNetwork::Visa,
|
|
"BIN {s} should be Visa",
|
|
);
|
|
}
|
|
}
|
|
|
|
#[test]
|
|
fn six_seven_eight_digit_visa_all_classify() {
|
|
let six = Bin::parse("411111").expect("ok");
|
|
let seven = Bin::parse("4111111").expect("ok");
|
|
let eight = Bin::parse("41111111").expect("ok");
|
|
assert_eq!(classify(&six), CardNetwork::Visa);
|
|
assert_eq!(classify(&seven), CardNetwork::Visa);
|
|
assert_eq!(classify(&eight), CardNetwork::Visa);
|
|
}
|
|
|
|
#[test]
|
|
fn boundary_3_and_5_are_not_visa() {
|
|
assert_ne!(
|
|
classify(&Bin::parse("399999").expect("ok")),
|
|
CardNetwork::Visa,
|
|
);
|
|
assert_ne!(
|
|
classify(&Bin::parse("500000").expect("ok")),
|
|
CardNetwork::Visa,
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn classifier_agrees_with_range_tree_for_visa() {
|
|
let tree = op_bin::network_ranges::build_default_tree().expect("disjoint");
|
|
for tail in ["00000", "11111", "55555", "99999"] {
|
|
let s = format!("4{tail}");
|
|
let b = Bin::parse(&s).expect("ok");
|
|
let from_classifier = classify(&b);
|
|
let from_tree = tree.lookup(&b).map(|r| r.network).unwrap_or(CardNetwork::Unknown);
|
|
assert_eq!(from_classifier, CardNetwork::Visa);
|
|
assert_eq!(from_tree, CardNetwork::Visa);
|
|
}
|
|
}
|