From e50b947b9b116a64f449e1410aae69582b000d1e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jeremy=20Lain=C3=A9?= Date: Wed, 27 Jan 2021 13:47:41 +0100 Subject: [PATCH] [sctp] fix import warning for crc32c The crc32c package renamed the `crc32` function to `crc32c` as in release 2.1. It is also no longer necessary to set `CRC32C_SW_MODE` since release 2.0. --- setup.py | 2 +- src/aiortc/rtcsctptransport.py | 12 +++--------- stubs/crc32c.pyi | 2 +- 3 files changed, 5 insertions(+), 11 deletions(-) diff --git a/setup.py b/setup.py index 1d6dc3c54..d2fb4d206 100644 --- a/setup.py +++ b/setup.py @@ -21,7 +21,7 @@ "aioice>=0.7.0,<0.8.0", "av>=8.0.0,<9.0.0", "cffi>=1.0.0", - "crc32c", + "crc32c>=2.1", "cryptography>=2.2", 'dataclasses; python_version < "3.7"', "pyee>=6.0.0", diff --git a/src/aiortc/rtcsctptransport.py b/src/aiortc/rtcsctptransport.py index 130509214..05f29e6ec 100644 --- a/src/aiortc/rtcsctptransport.py +++ b/src/aiortc/rtcsctptransport.py @@ -22,6 +22,7 @@ no_type_check, ) +from crc32c import crc32c from pyee import AsyncIOEventEmitter from .exceptions import InvalidStateError @@ -29,13 +30,6 @@ from .rtcdtlstransport import RTCDtlsTransport from .utils import random32, uint16_add, uint16_gt, uint32_gt, uint32_gte -try: - from crc32c import crc32 -except ImportError: # pragma: no cover - os.environ["CRC32C_SW_MODE"] = "1" - from crc32c import crc32 - - logger = logging.getLogger("sctp") # local constants @@ -406,7 +400,7 @@ def parse_packet(data: bytes) -> Tuple[int, int, int, List[Any]]: # verify checksum checksum = unpack_from(" bytes: header = pack("!HHL", source_port, destination_port, verification_tag) data = bytes(chunk) - checksum = crc32(header + b"\x00\x00\x00\x00" + data) + checksum = crc32c(header + b"\x00\x00\x00\x00" + data) return header + pack(" int: ... +def crc32c(data: bytes) -> int: ...