mirror of
https://github.com/python-kasa/python-kasa.git
synced 2024-12-22 19:23:34 +00:00
Use hashlib in place of hashes.Hash (#714)
This commit is contained in:
parent
fcd4883645
commit
dd38225f51
@ -50,7 +50,7 @@ import time
|
|||||||
from pprint import pformat as pf
|
from pprint import pformat as pf
|
||||||
from typing import Any, Dict, Optional, Tuple, cast
|
from typing import Any, Dict, Optional, Tuple, cast
|
||||||
|
|
||||||
from cryptography.hazmat.primitives import hashes, padding
|
from cryptography.hazmat.primitives import padding
|
||||||
from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes
|
from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes
|
||||||
|
|
||||||
from .credentials import Credentials
|
from .credentials import Credentials
|
||||||
@ -68,16 +68,11 @@ SESSION_EXPIRE_BUFFER_SECONDS = 60 * 20
|
|||||||
|
|
||||||
|
|
||||||
def _sha256(payload: bytes) -> bytes:
|
def _sha256(payload: bytes) -> bytes:
|
||||||
digest = hashes.Hash(hashes.SHA256()) # noqa: S303
|
return hashlib.sha256(payload).digest() # noqa: S324
|
||||||
digest.update(payload)
|
|
||||||
hash = digest.finalize()
|
|
||||||
return hash
|
|
||||||
|
|
||||||
|
|
||||||
def _sha1(payload: bytes) -> bytes:
|
def _sha1(payload: bytes) -> bytes:
|
||||||
digest = hashes.Hash(hashes.SHA1()) # noqa: S303
|
return hashlib.sha1(payload).digest() # noqa: S324
|
||||||
digest.update(payload)
|
|
||||||
return digest.finalize()
|
|
||||||
|
|
||||||
|
|
||||||
class KlapTransport(BaseTransport):
|
class KlapTransport(BaseTransport):
|
||||||
|
@ -11,6 +11,7 @@ http://www.apache.org/licenses/LICENSE-2.0
|
|||||||
"""
|
"""
|
||||||
import base64
|
import base64
|
||||||
import errno
|
import errno
|
||||||
|
import hashlib
|
||||||
import logging
|
import logging
|
||||||
import struct
|
import struct
|
||||||
from abc import ABC, abstractmethod
|
from abc import ABC, abstractmethod
|
||||||
@ -18,8 +19,6 @@ from typing import Dict, Tuple, Union
|
|||||||
|
|
||||||
# When support for cpython older than 3.11 is dropped
|
# When support for cpython older than 3.11 is dropped
|
||||||
# async_timeout can be replaced with asyncio.timeout
|
# async_timeout can be replaced with asyncio.timeout
|
||||||
from cryptography.hazmat.primitives import hashes
|
|
||||||
|
|
||||||
from .credentials import Credentials
|
from .credentials import Credentials
|
||||||
from .deviceconfig import DeviceConfig
|
from .deviceconfig import DeviceConfig
|
||||||
|
|
||||||
@ -29,11 +28,8 @@ _UNSIGNED_INT_NETWORK_ORDER = struct.Struct(">I")
|
|||||||
|
|
||||||
|
|
||||||
def md5(payload: bytes) -> bytes:
|
def md5(payload: bytes) -> bytes:
|
||||||
"""Return an md5 hash of the payload."""
|
"""Return the MD5 hash of the payload."""
|
||||||
digest = hashes.Hash(hashes.MD5()) # noqa: S303
|
return hashlib.md5(payload).digest() # noqa: S324
|
||||||
digest.update(payload)
|
|
||||||
hash = digest.finalize()
|
|
||||||
return hash
|
|
||||||
|
|
||||||
|
|
||||||
class BaseTransport(ABC):
|
class BaseTransport(ABC):
|
||||||
|
Loading…
Reference in New Issue
Block a user