Skip to content

rust-iso/rust_iso9362

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

rust_iso/iso9362

A rust crate providing ISO 9362 (Business Identifier Code / BIC, a.k.a. SWIFT code) parsing and validation.

What is ISO 9362

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

Installing

[dependencies]
rust_iso9362 = "0.1.0"

Features

  • serde — implements Serialize/Deserialize for BIC. A BIC serialises to its canonical code string and deserialises case-insensitively via BIC::parse. Enable with:

    rust_iso9362 = { version = "0.1.0", features = ["serde"] }
  • iso3166 — adds BIC::country(), which resolves the embedded ISO 3166-1 country code to a rust_iso3166::CountryCode using the rust_iso3166 crate.

  • cli — builds the iso9362 command-line lookup tool (pulls in prettytable-rs). Off by default; install with cargo install rust_iso9362 --features cli.

The minimum supported Rust version is 1.85.

Using

// 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"),
}

Contributing

Feel free to submit a pull request or create an issue. or request to rust-iso

License

rust-iso/rust_iso9362 is licensed under the Apache-2.0 license.

Source(s)

About

ISO 9362 (BIC / SWIFT code) parser and validator for Rust "ISO 9362 (Business Identifier Code, also known as the SWIFT/BIC code) defines a standard format for identifying business parties – in particular banks and financial institutions – in financial transactions. This crate parses, validates and decomposes BIC codes into their component parts.

Topics

Resources

License

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors