Remove unnecessary dependency on pyca

Python’s built-in hashlib is capable of calculating SHA1.  There’s
no need to depend on a third party library which may or may not be
available.
This commit is contained in:
Michal Nazarewicz 2019-03-13 00:39:49 +00:00
parent 80f2da2f03
commit 19fd5102cb

View File

@ -1,18 +1,10 @@
import hashlib
import requests import requests
import cryptography
from base64 import b16encode
import sys import sys
from cryptography.hazmat.backends import default_backend
from cryptography.hazmat.primitives import hashes
def hash_password_sha1_hex(pwd):
digest = hashes.Hash(hashes.SHA1(), backend=default_backend())
digest.update(pwd.encode('ASCII'))
sha1 = b16encode(digest.finalize()).decode('ASCII')
return sha1
def lookup_pwned_api(pwd): def lookup_pwned_api(pwd):
sha1pwd = hash_password_sha1_hex(pwd) sha1pwd = hashlib.sha1(pwd.encode('ascii')).hexdigest().upper()
head = sha1pwd[:5] head = sha1pwd[:5]
tail = sha1pwd[5:] tail = sha1pwd[5:]
@ -32,4 +24,4 @@ if (api_return):
else: else:
print (sys.argv[1], "was not found") print (sys.argv[1], "was not found")
exit() exit()