From e5a7785b82bacad02ab14c4fb23001deb271607c Mon Sep 17 00:00:00 2001 From: supertypo Date: Sat, 6 Jul 2024 20:02:52 +0200 Subject: [PATCH] Fixed wrong implementation of ByteColumn.py (used for nonce) --- models/type_decorators/ByteColumn.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/models/type_decorators/ByteColumn.py b/models/type_decorators/ByteColumn.py index eba39dd..b084773 100644 --- a/models/type_decorators/ByteColumn.py +++ b/models/type_decorators/ByteColumn.py @@ -1,6 +1,9 @@ +import logging from sqlalchemy import TypeDecorator from sqlalchemy.dialects.postgresql import BYTEA +_logger = logging.getLogger(__name__) + class ByteColumn(TypeDecorator): impl = BYTEA @@ -8,10 +11,14 @@ class ByteColumn(TypeDecorator): def process_bind_param(self, value, dialect): if value is not None: - return value.encode() + return int(value).to_bytes((int(value).bit_length() + 7) // 8, 'big') return value def process_result_value(self, value, dialect): if value is not None: - return value.decode() + try: + return str(int.from_bytes(value, 'big')) + except Exception as e: + _logger.error("Error decoding value '%s': %s", value, e) + return '' return value