-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed wrong implementation of ByteColumn.py (used for nonce)
- Loading branch information
supertypo
committed
Jul 6, 2024
1 parent
840b02b
commit e5a7785
Showing
1 changed file
with
9 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |