diff --git a/dev-requirements.txt b/dev-requirements.txt index 60b1a14..09bcf40 100644 --- a/dev-requirements.txt +++ b/dev-requirements.txt @@ -1,3 +1,3 @@ flake8==3.8.4 -black==20.8b1 +black==21.10b0 pytest==6.1.2 diff --git a/emv/card.py b/emv/card.py index 7fcc9f1..8503d18 100644 --- a/emv/card.py +++ b/emv/card.py @@ -16,21 +16,21 @@ class Card(object): - """ High-level card manipulation API """ + """High-level card manipulation API""" def __init__(self, connection): self.tp = TransmissionProtocol(connection) def get_mf(self): - """ Get the master file (MF). """ + """Get the master file (MF).""" return self.tp.exchange(SelectCommand(file_identifier=[0x3F, 0x00])) def get_pse(self): - """ Get the Payment System Environment (PSE) file """ + """Get the Payment System Environment (PSE) file""" return self.tp.exchange(SelectCommand("1PAY.SYS.DDF01")) def list_applications(self): - """ List applications on the card """ + """List applications on the card""" try: return self._list_applications_sfi() except ErrorResponse: @@ -146,7 +146,7 @@ def get_application_data(self, afl): return data def verify_pin(self, pin): - """ Verify the PIN, raising an exception if it fails.""" + """Verify the PIN, raising an exception if it fails.""" res = self.tp.exchange(VerifyCommand(pin)) if type(res) == WarningResponse: raise InvalidPINException(str(res)) @@ -154,7 +154,7 @@ def verify_pin(self, pin): return res def generate_cap_value(self, pin, challenge=None, value=None): - """ Perform a transaction to generate the EMV CAP (Pinsentry) value. """ + """Perform a transaction to generate the EMV CAP (Pinsentry) value.""" apps = self.list_applications() if len(apps) == 0: @@ -182,7 +182,9 @@ def generate_cap_value(self, pin, challenge=None, value=None): # It appears that Belgian cards use their own silliness. # https://github.com/zoobab/EMVCAP/blob/master/EMV-CAP#L512 if Tag.IPB not in app_data: - raise EMVProtocolError("Issuer Proprietary Bitmap not found in application file") + raise EMVProtocolError( + "Issuer Proprietary Bitmap not found in application file" + ) self.verify_pin(pin) diff --git a/emv/command/client.py b/emv/command/client.py index 504887f..f876349 100644 --- a/emv/command/client.py +++ b/emv/command/client.py @@ -42,7 +42,7 @@ def get_reader(reader): def run(): - " Command line entrypoint " + "Command line entrypoint" cli(obj={}) @@ -138,9 +138,7 @@ def info(ctx): "1PAY.SYS.DDF01 not available (this is normal on some cards)", fg="yellow" ) except Exception as e: - click.secho( - "Error reading 1PAY.SYS.DDF01 (may be normal): " + str(e), fg="red" - ) + click.secho("Error reading 1PAY.SYS.DDF01 (may be normal): " + str(e), fg="red") click.secho("\n2PAY.SYS.DDF01 (Index of apps for contactless payments)", bold=True) try: @@ -150,9 +148,7 @@ def info(ctx): "2PAY.SYS.DDF01 not available (this is normal on some cards)", fg="yellow" ) except Exception as e: - click.secho( - "Error reading 2PAY.SYS.DDF01 (may be normal): " + str(e), fg="red" - ) + click.secho("Error reading 2PAY.SYS.DDF01 (may be normal): " + str(e), fg="red") for app in apps: click.secho( diff --git a/emv/protocol/command.py b/emv/protocol/command.py index e602ccf..1fced46 100644 --- a/emv/protocol/command.py +++ b/emv/protocol/command.py @@ -188,7 +188,7 @@ def __init__(self, pin): class GenerateApplicationCryptogramCommand(CAPDU): - """ Defined in: EMV 4.3 Book 3 section 6.5.5 """ + """Defined in: EMV 4.3 Book 3 section 6.5.5""" name = "Generate Application Cryptogram" @@ -211,7 +211,7 @@ def __init__(self, crypto_type, data, cda_sig=False): class GetProcessingOptions(CAPDU): - """ Defined in: EMV 4.3 Book 3 section 6.5.8 """ + """Defined in: EMV 4.3 Book 3 section 6.5.8""" name = "Get Processing Opts" diff --git a/emv/protocol/data.py b/emv/protocol/data.py index 1bd3409..81f21e3 100644 --- a/emv/protocol/data.py +++ b/emv/protocol/data.py @@ -24,12 +24,12 @@ def is_two_byte(val): def is_continuation(val): - """ Any subsequent byte is a continuation byte if the MSB is set. """ + """Any subsequent byte is a continuation byte if the MSB is set.""" return val & 0b10000000 == 0b10000000 def is_constructed(val): - """ Check if a tag represents a "constructed" value, i.e. another TLV """ + """Check if a tag represents a "constructed" value, i.e. another TLV""" return val & 0b00100000 == 0b00100000 @@ -74,7 +74,7 @@ def read_length(data): @total_ordering class Tag(object): - """ Represents a data tag. Provides ordering and pretty rendering.""" + """Represents a data tag. Provides ordering and pretty rendering.""" def __init__(self, value): if type(value) in (list, tuple) and len(value) == 1: diff --git a/emv/protocol/structures.py b/emv/protocol/structures.py index 525f7a9..39a0618 100644 --- a/emv/protocol/structures.py +++ b/emv/protocol/structures.py @@ -140,7 +140,7 @@ class DOL(OrderedDict): @classmethod def unmarshal(cls, data): - """ Construct a DOL object from the binary representation (as a list of bytes) """ + """Construct a DOL object from the binary representation (as a list of bytes)""" dol = cls() i = 0 while i < len(data): @@ -152,11 +152,11 @@ def unmarshal(cls, data): return dol def size(self): - """ Total size of the resulting structure in bytes. """ + """Total size of the resulting structure in bytes.""" return sum(self.values()) def unserialise(self, data): - """ Parse an input stream of bytes and return a TLV object. """ + """Parse an input stream of bytes and return a TLV object.""" if self.size() != len(data): raise Exception( "Incorrect input size (expecting %s bytes, got %s)" @@ -190,7 +190,7 @@ def serialise(self, data): class TagList(list): - """ A list of tags. """ + """A list of tags.""" @classmethod def unmarshal(cls, data): @@ -204,7 +204,7 @@ def unmarshal(cls, data): class CVMRule(object): - """ EMV 4.3 book 3 appendix C3 """ + """EMV 4.3 book 3 appendix C3""" RULES = { # 0b00000000: "Fail CVM processing", diff --git a/emv/transmission.py b/emv/transmission.py index 5eb945b..16ba8df 100644 --- a/emv/transmission.py +++ b/emv/transmission.py @@ -11,7 +11,7 @@ class TransmissionProtocol(object): """ def __init__(self, connection): - """ Connection should be a pyscard connection. """ + """Connection should be a pyscard connection.""" self.log = logging.getLogger(__name__) self.connection = connection self.connection.connect(connection.T0_protocol)