Skip to content

Commit

Permalink
Fixed wrong implementation of ByteColumn.py (used for nonce)
Browse files Browse the repository at this point in the history
  • Loading branch information
supertypo committed Jul 6, 2024
1 parent 840b02b commit e5a7785
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions models/type_decorators/ByteColumn.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,24 @@
import logging
from sqlalchemy import TypeDecorator
from sqlalchemy.dialects.postgresql import BYTEA

_logger = logging.getLogger(__name__)


class ByteColumn(TypeDecorator):
impl = BYTEA
cache_ok = True

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

0 comments on commit e5a7785

Please sign in to comment.