Parsing PDOL for GET PROCESSING OPTIONS command in EMV transaction

可紊 提交于 2019-12-01 05:18:35

No, you can't expect that each tag consists of two bytes (though most tags do). Tag-Length-Value (TLV) structures in EMV follow ASN.1 encoding rules (basic encoding rules, BER). See the following documents for further information:

The latter is a really good introduction that helped me getting started.

A TLV structure (data object) consists of a tag value, a length value, and a data payload (value):

+-----------+-----------+-----------+
|    Tag    |  Length   |   Value   |
| (N Bytes) | (M Bytes) | (L bytes) |
+-----------+-----------+-----------+

The PDOL (and any other data object list, DOL) contains the tag and the length part of one or more such data objects. Similarly, the PDOL related data contains the value parts of the DOs referenced in the PDOL. Both, the tag and the length part can consist of one or more bytes.

For the tag part, the rules are about like this (for more details see the above references):

  • If the lower 5 bits of the first tag byte are all ones (tag[0] & 0x01F == 0x01F), then the tag consists of at least two bytes.
  • If the upper bit of the next tag byte is one (tag[i] & 0x080 == 0x080), then the tag consists of one more byte. This is repeated for each subsequent byte.

For the length part, the rules are about like this (for more details see the above references):

  • If the upper bit of the first length byte is zero (length[0] & 0x080 == 0), then the remaining seven bits encode the length value (length[0] & 0x07F).
  • If the upper bit of the first length byte is one (length[0] & 0x080 == 0x080), then the remaining seven bits encode the number of remaining bytes of the length part (length[0] & 0x07F). The remaining bytes represent the length value as unsigned integer with MSB first.
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!