Skip to content

cardkit 0.1.0

Choose a tag to compare

@ANASS99T ANASS99T released this 30 Oct 09:41
· 3 commits to main since this release

First release of cardkit: lossless Mastercard IPM tooling and a drop-in replacement for cardutil 0.7.3, with its bugs fixed.

Highlights

IPM → CSV → IPM gives a file identical to the original, byte for byte.

  • Values are written exactly as they are in the file: spaces, leading zeros and dates are left alone.
  • DE55 is written as hex, and the PDS data in DE48/DE62/DE123–125 exactly as in the file.
  • Records that can't be parsed are kept whole as hex, so nothing is ever lost.
  • File details (encoding, 1014 blocking, block trailers, end-of-file record, trailing bytes) are kept in a META row.
  • ipm2csv checks that the CSV rebuilds the identical file before it finishes.

File header and trailer generation. When a CSV has no 1644/697 header or 1644/695 trailer, csv2ipm generates them:

  • File ID (PDS 0105), copied from the existing header/trailer if there is one.
  • Processing mode (PDS 0122).
  • File amount checksum (PDS 0301) and message count (PDS 0306).

Every IPM message type: presentments (1240), chargebacks (1442), fees (1740), addenda and the other 1644 file messages.

Fast: large files are converted on several CPU cores (--workers), and records always stay in file order. On 100,002 records (72 MB):

cardutil 0.7.3 cardkit 0.1.0
IPM → CSV 38.3 s 1.8 s, verification included
CSV → IPM 10.8 s 0.85 s
Rebuilt file 27 MB, different 72 MB, identical

Other defaults and detection

  • Encoding is EBCDIC cp037 unless --encoding is given.
  • 1014 blocking is detected whatever bytes end the blocks (x'4040' or x'0000').

Usage

pip install https://github.com/ANASS99T/cardkit/releases/download/v0.1.0/cardkit-0.1.0-py3-none-any.whl
cardkit ipm2csv in.ipm -o out.csv
cardkit csv2ipm out.csv -o rebuilt.ipm
cardkit compare in.ipm rebuilt.ipm

cardutil fixes

The cardkit.iso8583, mciipm, card, pinblock, key and config modules keep cardutil's API. Change cardutil to cardkit in your imports.

  • Messages with only a primary bitmap can be read, and DE128 is processed.
  • A value too long for its field raises an error. Before, it was cut off, or it corrupted the length prefix.
  • dumps() no longer changes the dict passed to it, and too much PDS data gives a clear error.
  • DE55 is parsed as real BER-TLV, including multi-byte tags and long-form lengths.
  • 10–12 digit PINs work in ISO-0 and ISO-4 PIN blocks.
  • Luhn validation works under python -O, and short card numbers are masked safely.
  • loads is about 2.7× faster.

See ANALYSIS.md for the full list.