From 17a3816e91ee68300ce097ef65368616da2bece5 Mon Sep 17 00:00:00 2001 From: Peter Bieringer Date: Sun, 28 Dec 2025 13:12:41 +0100 Subject: [PATCH] add comment, code review --- radicale/item/__init__.py | 2 +- radicale/utils.py | 18 ++++++++++++------ 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/radicale/item/__init__.py b/radicale/item/__init__.py index 3d354a81..1c9dcadb 100644 --- a/radicale/item/__init__.py +++ b/radicale/item/__init__.py @@ -341,7 +341,7 @@ def verify(file: str, encoding: str): with open(file, "rb") as f: content_raw = f.read() content = content_raw.decode(encoding) - logger.info("Verifying item: %s has sha256sum %r", file, utils.sha256_str(content)) + logger.info("Verifying item: %s has sha256sum %r", file, utils.sha256_bytes(content_raw)) try: vobject_items = read_components(content) # noqa: F841 except Exception as e: diff --git a/radicale/utils.py b/radicale/utils.py index c7e7645f..e2e01903 100644 --- a/radicale/utils.py +++ b/radicale/utils.py @@ -382,11 +382,11 @@ def dataToSpecial(data, count): result += 'C' elif char == '\n': result += 'L' - elif (ord(char) & 0xf8) == 0xf0: + elif (ord(char) & 0xf8) == 0xf0: # assuming UTF-8 result += '4' - elif (ord(char) & 0xf0) == 0xf0: + elif (ord(char) & 0xf0) == 0xf0: # assuming UTF-8 result += '3' - elif (ord(char) & 0xe0) == 0xe0: + elif (ord(char) & 0xe0) == 0xe0: # assuming UTF-8 result += '2' else: result += '.' @@ -397,7 +397,7 @@ def hexdump_str(content: str, limit: int = 2000) -> str: result = "Hexdump of string: index | | |\n" index = 0 size = 16 - bytestring = content.encode("utf-8") + bytestring = content.encode("utf-8") # assuming UTF-8 length = len(bytestring) while (index < length) and (index < limit): @@ -421,7 +421,7 @@ def hexdump_str(content: str, limit: int = 2000) -> str: def hexdump_line(line: str, limit: int = 200) -> str: result = "" length_str = len(line) - bytestring = line.encode("utf-8") + bytestring = line.encode("utf-8") # assuming UTF-8 length = len(bytestring) size = length if (size > limit): @@ -456,5 +456,11 @@ def hexdump_lines(lines: str, limit: int = 200) -> str: def sha256_str(content: str) -> str: _hash = sha256() - _hash.update(content.encode("utf-8")) + _hash.update(content.encode("utf-8")) # assuming UTF-8 + return _hash.hexdigest() + + +def sha256_bytes(content: bytes) -> str: + _hash = sha256() + _hash.update(content) return _hash.hexdigest()