Skip to content
This repository was archived by the owner on Mar 27, 2026. It is now read-only.

Commit 54a8eb3

Browse files
committed
Reformat for newer version of Black
1 parent 45dcf54 commit 54a8eb3

9 files changed

Lines changed: 71 additions & 73 deletions

File tree

emv/cap.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@
2626

2727

2828
def get_arqc_req(app_data, value=None, challenge=None):
29-
""" Generate the data to send with the generate application cryptogram request.
30-
This data is in the format requested by the card in the CDOL1 field of the
31-
application data.
29+
"""Generate the data to send with the generate application cryptogram request.
30+
This data is in the format requested by the card in the CDOL1 field of the
31+
application data.
3232
33-
This is the algorithm that barclays_pinsentry.c uses.
33+
This is the algorithm that barclays_pinsentry.c uses.
3434
"""
3535
if Tag.CDOL1 not in app_data:
3636
raise CAPError("Application data doesn't include CDOL1 field: %r" % app_data)
@@ -57,12 +57,12 @@ def get_arqc_req(app_data, value=None, challenge=None):
5757

5858

5959
def get_cap_value(response, ipb, psn):
60-
""" Generate a CAP value from the ARQC response.
60+
"""Generate a CAP value from the ARQC response.
6161
62-
The ARQC response is traditionally a data structure returned to the terminal by the
63-
card during a payment transaction. CAP (mis)uses it to generate an 8-digit one-time
64-
code. This is done by bitwise masking the values in this structure with the Issuer
65-
Proprietary Bitmap (IPB) provided by the card in the Application Data structure.
62+
The ARQC response is traditionally a data structure returned to the terminal by the
63+
card during a payment transaction. CAP (mis)uses it to generate an 8-digit one-time
64+
code. This is done by bitwise masking the values in this structure with the Issuer
65+
Proprietary Bitmap (IPB) provided by the card in the Application Data structure.
6666
"""
6767

6868
if Tag.RMTF1 in response.data:

emv/card.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ def list_applications(self):
3737
return self._list_applications_static_aid()
3838

3939
def _list_applications_static_aid(self):
40-
""" Try to find applications by trying to select a static application ID.
41-
This is an older method of app discovery which is still used by some cards.
40+
"""Try to find applications by trying to select a static application ID.
41+
This is an older method of app discovery which is still used by some cards.
4242
"""
4343
STATIC_AIDS = [
4444
[0xA0, 0x00, 0x00, 0x00, 0x25, 0x01], # Amex
@@ -68,10 +68,10 @@ def _list_applications_static_aid(self):
6868
return apps
6969

7070
def _list_applications_sfi(self):
71-
""" List applications on the card using the SFI method.
71+
"""List applications on the card using the SFI method.
7272
73-
This fetches the SFI (short file identifier) from the PSE (Payment System Environment)
74-
file, and uses it to locate all the apps on the card.
73+
This fetches the SFI (short file identifier) from the PSE (Payment System Environment)
74+
file, and uses it to locate all the apps on the card.
7575
"""
7676
pse = self.get_pse()
7777
sfi = pse.data[Tag.FCI][Tag.FCI_PROP][Tag.SFI][0]

emv/command/client.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -187,9 +187,7 @@ def cap(ctx, challenge, amount):
187187

188188
card = get_reader(ctx.obj["reader"])
189189
try:
190-
click.echo(
191-
card.generate_cap_value(pin, challenge=challenge, value=amount)
192-
)
190+
click.echo(card.generate_cap_value(pin, challenge=challenge, value=amount))
193191
except InvalidPINException:
194192
click.secho("Invalid PIN", fg="red")
195193
sys.exit(1)

emv/protocol/command.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ def assert_valid_byte(val):
99

1010

1111
class CAPDU(object):
12-
""" Command APDU.
12+
"""Command APDU.
1313
14-
Defined in: EMV 4.3 Book 1 sections:
15-
- 9.4.1
16-
- 11.1
14+
Defined in: EMV 4.3 Book 1 sections:
15+
- 9.4.1
16+
- 11.1
1717
"""
1818

1919
# Map the class name of the command to the CLA,INS bytes.
@@ -79,9 +79,9 @@ def __repr__(self):
7979

8080

8181
class SelectCommand(CAPDU):
82-
""" Select an application or file on the card.
82+
"""Select an application or file on the card.
8383
84-
Defined in: EMV 4.3 Book 1 section 11.3
84+
Defined in: EMV 4.3 Book 1 section 11.3
8585
"""
8686

8787
name = "Select"
@@ -116,9 +116,9 @@ def __repr__(self):
116116

117117

118118
class ReadCommand(CAPDU):
119-
""" Read a record from an application or file.
119+
"""Read a record from an application or file.
120120
121-
Defined in: EMV 4.3 Book 1 section 11.2
121+
Defined in: EMV 4.3 Book 1 section 11.2
122122
"""
123123

124124
name = "Read"
@@ -140,9 +140,9 @@ def __init__(self, record_number, sfi=None):
140140

141141

142142
class GetDataCommand(CAPDU):
143-
""" Get miscellaneous data
143+
"""Get miscellaneous data
144144
145-
Defined in: EMV 4.3 Book 3 section 6.5.7
145+
Defined in: EMV 4.3 Book 3 section 6.5.7
146146
"""
147147

148148
name = "Get Data"
@@ -161,9 +161,9 @@ def __init__(self, obj):
161161

162162

163163
class VerifyCommand(CAPDU):
164-
""" Verify the PIN.
164+
"""Verify the PIN.
165165
166-
Defined in: EMV 4.3 Book 3 section 6.5.12
166+
Defined in: EMV 4.3 Book 3 section 6.5.12
167167
"""
168168

169169
name = "Verify"

emv/protocol/data.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818

1919

2020
def is_two_byte(val):
21-
""" A tag is at least two bytes long if the least significant
22-
5 bits of the first byte are set. """
21+
"""A tag is at least two bytes long if the least significant
22+
5 bits of the first byte are set."""
2323
return val & 0b00011111 == 0b00011111
2424

2525

@@ -34,11 +34,11 @@ def is_constructed(val):
3434

3535

3636
def read_tag(data):
37-
""" Read a variable-length tag from a list of bytes, starting at the
38-
first byte. Returns the tag, plus the number of bytes read from
39-
the list.
37+
"""Read a variable-length tag from a list of bytes, starting at the
38+
first byte. Returns the tag, plus the number of bytes read from
39+
the list.
4040
41-
EMV 4.3 Book 3 Annex B1
41+
EMV 4.3 Book 3 Annex B1
4242
"""
4343
i = 0
4444
tag = [data[i]]
@@ -55,10 +55,10 @@ def read_tag(data):
5555

5656

5757
def read_length(data):
58-
""" Read length from a list of bytes, starting at the first byte.
59-
Returns the length, plus the number of bytes read from the list.
58+
"""Read length from a list of bytes, starting at the first byte.
59+
Returns the length, plus the number of bytes read from the list.
6060
61-
EMV 4.3 Book 3 Annex B2
61+
EMV 4.3 Book 3 Annex B2
6262
"""
6363
i = 0
6464
length = data[i]

emv/protocol/response.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33

44
class RAPDU(object):
5-
""" Response Application Protocol Data Unit
5+
"""Response Application Protocol Data Unit
66
7-
Defined in: EMV 4.3 Book 3 section 6.3.3
7+
Defined in: EMV 4.3 Book 3 section 6.3.3
88
"""
99

1010
@classmethod

emv/protocol/structures.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@ def parse_element(tag, value):
2929

3030

3131
class TLV(OrderedDict):
32-
""" BER-TLV
33-
A serialisation format.
32+
"""BER-TLV
33+
A serialisation format.
3434
35-
Documented in EMV 4.3 Book 3 Annex B
35+
Documented in EMV 4.3 Book 3 Annex B
3636
"""
3737

3838
@classmethod
@@ -92,12 +92,12 @@ def __repr__(self):
9292

9393

9494
class ASRPD(dict):
95-
""" Application Selection Registered Proprietary Data list.
95+
"""Application Selection Registered Proprietary Data list.
9696
97-
An almost-TLV structure used in the FCI Discretionary Data object.
98-
The tags here are fixed-length.
97+
An almost-TLV structure used in the FCI Discretionary Data object.
98+
The tags here are fixed-length.
9999
100-
https://www.emvco.com/wp-content/uploads/2017/05/BookB_Entry_Point_Specification_v2_6_20160809023257319.pdf
100+
https://www.emvco.com/wp-content/uploads/2017/05/BookB_Entry_Point_Specification_v2_6_20160809023257319.pdf
101101
"""
102102

103103
@classmethod
@@ -130,13 +130,13 @@ def __repr__(self):
130130

131131

132132
class DOL(OrderedDict):
133-
""" Data Object List.
134-
This is sent by the card to the terminal to define a structure for
135-
future transactions, consisting of an ordered list of data elements and lengths.
133+
"""Data Object List.
134+
This is sent by the card to the terminal to define a structure for
135+
future transactions, consisting of an ordered list of data elements and lengths.
136136
137-
It's essentially a TLV object without the values.
137+
It's essentially a TLV object without the values.
138138
139-
EMV 4.3 Book 3 section 5.4 """
139+
EMV 4.3 Book 3 section 5.4"""
140140

141141
@classmethod
142142
def unmarshal(cls, data):
@@ -172,8 +172,8 @@ def unserialise(self, data):
172172
return tlv
173173

174174
def serialise(self, data):
175-
""" Given a dictionary of tag -> value, write this data out
176-
according to the DOL. Missing data will be null.
175+
"""Given a dictionary of tag -> value, write this data out
176+
according to the DOL. Missing data will be null.
177177
"""
178178
output = []
179179
for tag, length in self.items():
@@ -264,7 +264,7 @@ class CVMList(object):
264264
265265
It doesn't seem to get much interesting use on many of the cards I've seen though.
266266
267-
EMV 4.3 book 3 section 10.5 """
267+
EMV 4.3 book 3 section 10.5"""
268268

269269
def __init__(self):
270270
self.x = None

emv/transmission.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44

55

66
class TransmissionProtocol(object):
7-
""" Transport layer. Only currently supports T0 transport.
7+
"""Transport layer. Only currently supports T0 transport.
88
9-
Defined in: EMV 4.3 Book 1 section 9
10-
See also Annex A for examples.
9+
Defined in: EMV 4.3 Book 1 section 9
10+
See also Annex A for examples.
1111
"""
1212

1313
def __init__(self, connection):
@@ -19,22 +19,22 @@ def __init__(self, connection):
1919
self.log.info("Connected to reader")
2020

2121
def transmit(self, tx_data):
22-
""" Send raw data to the card, and receive the reply.
22+
"""Send raw data to the card, and receive the reply.
2323
24-
tx_data should be a list of bytes.
24+
tx_data should be a list of bytes.
2525
26-
Returns a tuple of (data, sw1, sw2) where sw1 and sw2
27-
are the protocol status bytes.
26+
Returns a tuple of (data, sw1, sw2) where sw1 and sw2
27+
are the protocol status bytes.
2828
"""
2929
self.log.debug("Tx: %s", format_bytes(tx_data))
3030
data, sw1, sw2 = self.connection.transmit(tx_data)
3131
self.log.debug("Rx: %s, SW1: %02x, SW2: %02x", format_bytes(data), sw1, sw2)
3232
return data, sw1, sw2
3333

3434
def exchange(self, capdu):
35-
""" Send a command to the card and return the response.
35+
"""Send a command to the card and return the response.
3636
37-
Accepts a CAPDU object and returns a RAPDU.
37+
Accepts a CAPDU object and returns a RAPDU.
3838
"""
3939
send_data = capdu.marshal()
4040
data, sw1, sw2 = self.transmit(send_data)

emv/util.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22

33

44
def hex_int(val):
5-
""" Convert an integer into a decimal-encoded hex integer as bytes,
6-
which the EMV spec seems awfully keen on.
5+
"""Convert an integer into a decimal-encoded hex integer as bytes,
6+
which the EMV spec seems awfully keen on.
77
8-
>>> hex_int(123456)
9-
[0x12, 0x34, 0x56]
10-
>>> hex_int(65432)
11-
[0x06, 0x54, 0x32]
8+
>>> hex_int(123456)
9+
[0x12, 0x34, 0x56]
10+
>>> hex_int(65432)
11+
[0x06, 0x54, 0x32]
1212
"""
1313
s = str(val)
1414
if len(s) % 2 != 0:
@@ -17,10 +17,10 @@ def hex_int(val):
1717

1818

1919
def from_hex_int(val):
20-
""" Convert hex digits to decimal.
20+
"""Convert hex digits to decimal.
2121
22-
>>> from_hex_int([0x12, 0x34])
23-
1234
22+
>>> from_hex_int([0x12, 0x34])
23+
1234
2424
"""
2525
return int("".join(["%02x" % i for i in val]))
2626

0 commit comments

Comments
 (0)