Skip to content

Commit dc6ddff

Browse files
committed
Minor modifications on functions and vars names
1 parent 69dc2bf commit dc6ddff

File tree

3 files changed

+28
-26
lines changed

3 files changed

+28
-26
lines changed

pyntegrity/core.py

+11-9
Original file line numberDiff line numberDiff line change
@@ -23,36 +23,38 @@
2323
from .config import SUPPORTED_HASH_ALGOS
2424

2525

26-
def detect_hash_algo(hash_str: str):
26+
def detect_hash_algo(checksum_str: str):
2727
"""
2828
Detects hash algorithm based on its length.
2929
30-
:param hash_str: the hash string
30+
:param checksum_str: the hash string
3131
:return: the name of the hash algorithm
3232
:raises HashAlgorithmNotSupportedException: raised if the hash
3333
length isn't valid for any supported algorithm
3434
"""
35-
hash_len = len(hash_str)
35+
hash_len = len(checksum_str)
3636
for name, infos in SUPPORTED_HASH_ALGOS.items():
3737
if infos["LENGTH"] == hash_len:
3838
return name
3939
else:
4040
raise HashAlgorithmNotSupportedException(
41-
detected_length=hash_len, hash_str=hash_str
41+
detected_length=hash_len, checksum_str=checksum_str
4242
)
4343

4444

45-
def validate_hash_str(hash_str: str):
45+
def validate_checksum_str(checksum_str: str):
4646
"""
4747
Checks if the str is a valid checksum in the detected algorithm
4848
49-
:param hash_str:the hash string
49+
:param checksum_str:the hash string
5050
:return: True if valid
5151
:raises HashStrNotValidException: raised if the hash str isn't valid
5252
"""
53-
hash_name = detect_hash_algo(hash_str)
53+
hash_name = detect_hash_algo(checksum_str)
5454
pattern = re.compile(SUPPORTED_HASH_ALGOS[hash_name]["REX"])
55-
if pattern.match(hash_str):
55+
if pattern.match(checksum_str):
5656
return True
5757
else:
58-
raise HashStrNotValidException(detected_hash_algo=hash_name, hash_str=hash_str)
58+
raise HashStrNotValidException(
59+
detected_hash_algo=hash_name, checksum_str=checksum_str
60+
)

pyntegrity/exceptions.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,16 @@
1919

2020

2121
class HashAlgorithmNotSupportedException(Exception):
22-
def __init__(self, detected_length: int, hash_str: str):
22+
def __init__(self, detected_length: int, checksum_str: str):
2323
"""
2424
Exception raised when the hash length does not match
2525
any supported Hash algorithm;
2626
2727
:param detected_length: the length of the checked hash string
28-
:param hash_str: the hash string
28+
:param checksum_str: the hash string
2929
"""
3030
self.detected_length = detected_length
31-
self.hash_str = hash_str
31+
self.checksum_str = checksum_str
3232
self.message = (
3333
"[!] The hash string length does not "
3434
"match any supported hash algorithm: ["
@@ -42,16 +42,16 @@ def __init__(self, detected_length: int, hash_str: str):
4242

4343

4444
class HashStrNotValidException(Exception):
45-
def __init__(self, detected_hash_algo: str, hash_str: str):
45+
def __init__(self, detected_hash_algo: str, checksum_str: str):
4646
"""
4747
Exception raised when hash string isn't valid
4848
for the detected hash algorithm;
4949
5050
:param detected_hash_algo: the name of the detected algo
51-
:param hash_str: the hash string
51+
:param checksum_str: the hash string
5252
"""
5353
self.detected_hash_algo = detected_hash_algo
54-
self.hash_str = hash_str
54+
self.checksum_str = checksum_str
5555
self.message = (
5656
f"[!] The hash string doesn't "
5757
f'seem valid for the detected algorithm"{detected_hash_algo}"'

tests/test_core.py

+11-11
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from unittest import TestCase
22

33
from pyntegrity.core import detect_hash_algo
4-
from pyntegrity.core import validate_hash_str
4+
from pyntegrity.core import validate_checksum_str
55

66
from pyntegrity.exceptions import HashStrNotValidException
77
from pyntegrity.exceptions import HashAlgorithmNotSupportedException
@@ -17,30 +17,30 @@ def test_detect_hash_algo_ok(self):
1717
self.assertEqual(hash_name, "sha256")
1818

1919
def test_detect_hash_algo_nok(self):
20-
invalid_hash_str = "6545ed"
20+
invalid_checksum_str = "6545ed"
2121
with self.assertRaises(HashAlgorithmNotSupportedException):
22-
detect_hash_algo(invalid_hash_str)
22+
detect_hash_algo(invalid_checksum_str)
2323

2424

2525
class TestValidateHashStr(TestCase):
26-
def test_validate_hash_str_md5_ok(self):
26+
def test_validate_checksum_str_md5_ok(self):
2727
valid_md5 = "098f6bcd4621d373cade4e832627b4f6"
28-
self.assertTrue(validate_hash_str(valid_md5))
28+
self.assertTrue(validate_checksum_str(valid_md5))
2929

30-
def test_validate_hash_str_md5_nok(self):
30+
def test_validate_checksum_str_md5_nok(self):
3131
invalid_md5 = "098f6bcd4621d373xade4e832627b4f6"
3232
with self.assertRaises(HashStrNotValidException):
33-
validate_hash_str(invalid_md5)
33+
validate_checksum_str(invalid_md5)
3434

35-
def test_validate_hash_str_sha256_ok(self):
35+
def test_validate_checksum_str_sha256_ok(self):
3636
valid_sha256 = (
3737
"9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08"
3838
)
39-
self.assertTrue(validate_hash_str(valid_sha256))
39+
self.assertTrue(validate_checksum_str(valid_sha256))
4040

41-
def test_validate_hash_str_sha256_nok(self):
41+
def test_validate_checksum_str_sha256_nok(self):
4242
invalid_sha256 = (
4343
"9f86d081884x7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08"
4444
)
4545
with self.assertRaises(HashStrNotValidException):
46-
validate_hash_str(invalid_sha256)
46+
validate_checksum_str(invalid_sha256)

0 commit comments

Comments
 (0)