A rust crate providing ISO 9362 (Business Identifier Code / BIC, a.k.a. SWIFT code) parsing and validation.
ISO 9362 is an international standard for Business Identifier Codes (BIC), a standard published by the International Organization for Standardization (ISO) as a way to uniquely identify banks and financial institutions worldwide. The BIC is also known as the SWIFT code, SWIFT-BIC, or SWIFT address.
A BIC is 8 or 11 characters long and is made up of:
- Business party prefix – four alphabetic characters identifying the business party (institution / bank code).
- Country code – two alphabetic characters, the ISO 3166-1 alpha-2 code of the country in which the business party is located.
- Business party suffix – two alphanumeric characters (the location code).
- Branch code – an optional three alphanumeric characters identifying a specific branch;
XXX, or its absence, denotes the primary office.-- Wikipedia
Unlike ISO 3166, ISO 9362 does not define a fixed, enumerable dataset (the full registry of assigned BICs is maintained by SWIFT), so this crate is a parser / validator that decomposes a BIC into its component parts.
| Position | Part | Length | Charset |
|---|---|---|---|
| 1–4 | Business party prefix | 4 | A-Z |
| 5–6 | Country code (ISO 3166-1) | 2 | A-Z |
| 7–8 | Business party suffix | 2 | A-Z0-9 |
| 9–11 | Branch code (optional) | 3 | A-Z0-9 |
[dependencies]
rust_iso9362 = "0.1.0"-
serde— implementsSerialize/DeserializeforBIC. ABICserialises to its canonical code string and deserialises case-insensitively viaBIC::parse. Enable with:rust_iso9362 = { version = "0.1.0", features = ["serde"] }
-
iso3166— addsBIC::country(), which resolves the embedded ISO 3166-1 country code to arust_iso3166::CountryCodeusing therust_iso3166crate. -
cli— builds theiso9362command-line lookup tool (pulls inprettytable-rs). Off by default; install withcargo install rust_iso9362 --features cli.
The minimum supported Rust version is 1.85.
// Parse + validate (returns Option)
let bic = rust_iso9362::parse("DEUTDEFF500").unwrap();
// Or get a Result with a descriptive error
let bic = rust_iso9362::BIC::parse("DEUTDEFF500").unwrap();
assert_eq!(bic.business_party_prefix(), "DEUT"); // a.k.a. bank_code()
assert_eq!(bic.country_code(), "DE");
assert_eq!(bic.business_party_suffix(), "FF"); // a.k.a. location_code()
assert_eq!(bic.branch_code(), Some("500"));
assert_eq!(bic.bic8(), "DEUTDEFF");
assert_eq!(bic.bic11(), "DEUTDEFF500");
assert!(!bic.is_primary_office());
// 8-character BICs identify the primary office
let bic = rust_iso9362::BIC::parse("DEUTDEFF").unwrap();
assert_eq!(bic.branch_code(), None);
assert!(bic.is_primary_office());
assert_eq!(bic.bic11(), "DEUTDEFFXXX");
// Cheap validity check
assert!(rust_iso9362::is_valid("NEDSZAJJXXX"));
assert!(!rust_iso9362::is_valid("123"));
// FromStr is implemented too
let bic: rust_iso9362::BIC = "DEUTDEFF".parse().unwrap();
// With the `iso3166` feature:
// let country = bic.country().unwrap();
// assert_eq!(country.alpha3, "DEU");Data sample:
BIC {
code: "DEUTDEFF500",
// business_party_prefix: "DEUT",
// country_code: "DE",
// business_party_suffix: "FF",
// branch_code: Some("500"),
}Feel free to submit a pull request or create an issue. or request to rust-iso
rust-iso/rust_iso9362 is licensed under the Apache-2.0 license.