Skip to content

Commit 925fee1

Browse files
authored
Merge pull request #19 from mszeu/devel
Devel
2 parents 1e80dcf + 4139c2a commit 925fee1

File tree

3 files changed

+32
-36
lines changed

3 files changed

+32
-36
lines changed

.gitignore

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,2 @@
1-
/venv
21
/.idea
3-
/venv38
4-
/dist
5-
/build
6-
pressureTest.spec
2+
/win-build

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ It requires **Python 3**. It was tested on **Python 3.7**, **3.8** and **3.9** u
1818

1919
## Version
2020

21-
**1.1.6**
21+
**1.1.7**
2222

2323
## Usage
2424

@@ -58,7 +58,7 @@ It requires **Python 3**. It was tested on **Python 3.7**, **3.8** and **3.9** u
5858
**--b2** Echoes received data, specified through the **--echo** parameter, back to the user.
5959

6060
**--ecc** Generates an ECC public/private key pair using the Elliptic Curve algorithm.
61-
By default, the curve used is curve used is NIST P-521, the exportability is 'S' (Sensitive)
61+
By default, the curve used is NIST P-521, the exportability is 'S' (Sensitive)
6262
and the key usage is 'S' (Only digital signature).
6363
Use the parameters **--ecc-curve**, **--key-use** and **--key-exportability** to change the default values.
6464

pressureTest.py

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@
1313
from typing import Tuple, Dict
1414
from types import FunctionType
1515

16-
VERSION = "1.1.6"
16+
VERSION = "1.1.7"
1717

1818

1919
def decode_n0(response_to_decode: bytes, head_len: int):
2020
"""
21-
It decodes the result of the command N0 an prints the meaning of the returned output
21+
It decodes the result of the command N0 and prints the meaning of the returned output
2222
2323
Parameters
2424
___________
@@ -31,17 +31,17 @@ def decode_n0(response_to_decode: bytes, head_len: int):
3131
___________
3232
nothing
3333
"""
34-
response_to_decode, msg_len, str_pointer = common_parser(response_to_decode, head_len)
35-
if response_to_decode[str_pointer:str_pointer + 2] == '01':
34+
response_to_decode_str, msg_len, str_pointer = common_parser(response_to_decode, head_len)
35+
if response_to_decode_str[str_pointer:str_pointer + 2] == '01':
3636
print("Invalid Random Value Length")
37-
elif response_to_decode[str_pointer:str_pointer + 2] == '00':
37+
elif response_to_decode_str[str_pointer:str_pointer + 2] == '00':
3838
print("Random payload:(HEX)",
39-
binascii.hexlify((response_to_decode[6 + head_len:]).encode()).decode('ascii', 'ignore'))
39+
bytes.hex(response_to_decode[6 + head_len:]))
4040

4141

4242
def decode_no(response_to_decode: bytes, head_len: int):
4343
"""
44-
It decodes the result of the command NO an prints the meaning of the returned output
44+
It decodes the result of the command NO and prints the meaning of the returned output
4545
4646
Parameters
4747
___________
@@ -92,7 +92,7 @@ def decode_no(response_to_decode: bytes, head_len: int):
9292

9393
def decode_ni(response_to_decode: bytes, head_len: int):
9494
"""
95-
It decodes the result of the command NI an prints the meaning of the returned output
95+
It decodes the result of the command NI and prints the meaning of the returned output
9696
9797
Parameters
9898
___________
@@ -160,7 +160,7 @@ def decode_ni(response_to_decode: bytes, head_len: int):
160160

161161
def decode_nc(response_to_decode: bytes, head_len: int):
162162
"""
163-
It decodes the result of the command NC an prints the meaning of the returned output
163+
It decodes the result of the command NC and prints the meaning of the returned output
164164
The message trailer is not considered
165165
166166
Parameters
@@ -184,7 +184,7 @@ def decode_nc(response_to_decode: bytes, head_len: int):
184184

185185
def decode_j8(response_to_decode: bytes, head_len: int):
186186
"""
187-
It decodes the result of the command J8 an prints the meaning of the returned output
187+
It decodes the result of the command J8 and prints the meaning of the returned output
188188
The message trailer is not considered
189189
190190
Parameters
@@ -228,7 +228,7 @@ def decode_j8(response_to_decode: bytes, head_len: int):
228228

229229
def decode_b2(response_to_decode: bytes, head_len: int):
230230
"""
231-
It decodes the result of the command B2 an prints the meaning of the returned output
231+
It decodes the result of the command B2 and prints the meaning of the returned output
232232
The message trailer is not considered
233233
234234
Parameters
@@ -250,7 +250,7 @@ def decode_b2(response_to_decode: bytes, head_len: int):
250250

251251
def decode_j2(response_to_decode: bytes, head_len: int):
252252
"""
253-
It decodes the result of the command J2 an prints the meaning of the returned output
253+
It decodes the result of the command J2 and prints the meaning of the returned output
254254
The message trailer is not considered
255255
256256
Parameters
@@ -298,7 +298,7 @@ def decode_j2(response_to_decode: bytes, head_len: int):
298298

299299
def decode_j4(response_to_decode: bytes, head_len: int):
300300
"""
301-
It decodes the result of the command J4 an prints the meaning of the returned output
301+
It decodes the result of the command J4 and prints the meaning of the returned output
302302
The message trailer is not considered
303303
304304
Parameters
@@ -341,7 +341,7 @@ def decode_j4(response_to_decode: bytes, head_len: int):
341341

342342
def decode_jk(response_to_decode: bytes, head_len: int):
343343
"""
344-
It decodes the result of the command JK an prints the meaning of the returned output
344+
It decodes the result of the command JK and prints the meaning of the returned output
345345
The message trailer is not considered
346346
347347
Parameters
@@ -485,7 +485,7 @@ def decode_jk(response_to_decode: bytes, head_len: int):
485485

486486
def decode_ecc(response_to_decode: bytes, head_len: int):
487487
"""
488-
It decodes the result of the command FY an prints the meaning of the returned output
488+
It decodes the result of the command FY and prints the meaning of the returned output
489489
490490
Parameters
491491
___________
@@ -498,19 +498,20 @@ def decode_ecc(response_to_decode: bytes, head_len: int):
498498
___________
499499
nothing
500500
"""
501-
response_to_decode, msg_len, str_pointer = common_parser(response_to_decode, head_len)
502-
if response_to_decode[str_pointer:str_pointer + 2] == '00':
501+
response_to_decode_str, msg_len, str_pointer = common_parser(response_to_decode, head_len)
502+
if response_to_decode_str[str_pointer:str_pointer + 2] == '00':
503503
str_pointer = str_pointer + 2
504-
key_len = int(response_to_decode[str_pointer:str_pointer + 4])
504+
key_len = int(response_to_decode_str[str_pointer:str_pointer + 4])
505505
print("ECC Public Key Length: ", key_len)
506506
str_pointer = str_pointer + 4
507507
print("ECC Public Key",
508-
binascii.hexlify((response_to_decode[str_pointer:str_pointer + key_len]).encode())
509-
.decode('ascii', 'ignore'))
510-
print("Public/private separator: ", response_to_decode[str_pointer + key_len:str_pointer + key_len + 1])
508+
bytes.hex(response_to_decode[str_pointer:str_pointer + key_len]))
509+
510+
print("Public/private separator: ",
511+
response_to_decode[str_pointer + key_len:str_pointer + key_len + 1].decode('ascii', 'ignore'))
511512
str_pointer = str_pointer + key_len + 1
512513
print("ECC Private Key under LMK",
513-
response_to_decode[str_pointer:])
514+
bytes.hex(response_to_decode[str_pointer:]))
514515

515516

516517
def payshield_error_codes(error_code: str) -> str:
@@ -694,7 +695,6 @@ def test_printable(input_str):
694695

695696
def hex2ip(hex_ip):
696697
addr_long = int(hex_ip, 16)
697-
hex(addr_long)
698698
hex_ip = socket.inet_ntoa(pack(">L", addr_long))
699699
return hex_ip
700700

@@ -784,12 +784,12 @@ def run_test(ip_addr: str, port: int, host_command: str, proto: str = "tcp", hea
784784
if test_printable(message[2:].decode("ascii", "ignore")):
785785
print("sent data (ASCII) :", message[2:].decode("ascii", "ignore"))
786786

787-
print("sent data (HEX) :", binascii.hexlify(message))
787+
print("sent data (HEX) :", bytes.hex(message))
788788

789789
if test_printable((data[2:]).decode("ascii", "ignore")):
790790
print("received data (ASCII):", data[2:].decode("ascii", "ignore"))
791791

792-
print("received data (HEX) :", binascii.hexlify(data))
792+
print("received data (HEX) :", bytes.hex(data))
793793
if (decoder_funct is not None) and callable(decoder_funct):
794794
print("")
795795
print("-----DECODING RESPONSE-----")
@@ -812,7 +812,7 @@ def run_test(ip_addr: str, port: int, host_command: str, proto: str = "tcp", hea
812812

813813
def common_parser(response_to_decode: bytes, head_len: int) -> Tuple[str, int, int]:
814814
"""
815-
This function is an helper used by the decode_XX functions.
815+
This function is a helper used by the decode_XX functions.
816816
It converts the response_to_decode in ascii, calculates and prints the message size and
817817
prints the header, the command returned and the error code.
818818
@@ -962,21 +962,21 @@ def common_parser(response_to_decode: bytes, head_len: int) -> Tuple[str, int, i
962962
command = args.header + 'FY010' + args.ecc_curve + '03#' + args.key_use + '00' + args.key_exportability + '00'
963963
if args.b2:
964964
# we need to calculate the hexadecimal representation of the length of the payload string
965-
# the length of the string field is 4 char long so we need to format it accordingly
965+
# the length of the string field is 4 char long, so we need to format it accordingly
966966
# Example: 0001 or 000FA etc.
967967
# Note: this padding algorithm works for echo payloads up to the length of 0xFFFF.
968968
# I hope no one would be so crazy to exceed that quantity.
969969
h_padding = '0000'
970970
len_echo_message = len(args.echo)
971971
hex_string_len = hex(len_echo_message).lstrip('0x').upper()
972972
# using lstrip() to strip the '0x' prefix is acceptable due to the expected pattern
973-
# Ideally you should use removeprefix() but it was introduced in python 3.9 and I want to keep compatibility
973+
# Ideally you should use removeprefix() but it was introduced in python 3.9, and I want to keep compatibility
974974
hex_string_len = h_padding[:4 - len(hex_string_len)] + hex_string_len
975975
command = args.header + 'B2' + hex_string_len + args.echo
976976

977977
# IMPORTANT: At this point the 'command' need to contain something.
978978
# If you want to add to the tool command link arguments about commands do it before this comment block
979-
# Now we verify if the command variable is empty. In this case we thrown an error.
979+
# Now we verify if the command variable is empty. In this case we throw an error.
980980
if len(command) == 0:
981981
print("You forgot to specify the action you want to to perform on the payShield")
982982
exit()

0 commit comments

Comments
 (0)