refactor(core): move is_printable_ascii to common
What changed, and why it matters
This commit simply moves a small helper function that checks whether a string contains only normal printable characters from one file to another shared location. No behavior changes, no bug fixes, and no security implications are visible in the code change itself.
No security action required. Review the follow-up Solana off-chain message parsing commits when they appear, as they will be the ones introducing new parsing and signing logic.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The change is a pure refactor: is_printable_ascii is relocated from apps/cardano/helpers/utils.py to apps/common/signverify.py, and its existing callers in Cardano code now import it from the new shared location. The function body is unchanged. The commit message explicitly states this is preparatory work for future Solana off-chain message parsing.
Changed components
core/src/apps/cardano/helpers/utils.pycore/src/apps/cardano/sign_message.pycore/src/apps/common/signverify.pyInspect captured patch +9 / −6
diff --git a/core/src/apps/cardano/helpers/utils.py b/core/src/apps/cardano/helpers/utils.py
index cbdbe332..90dcc08d 100644
--- a/core/src/apps/cardano/helpers/utils.py
+++ b/core/src/apps/cardano/helpers/utils.py
@@ -117,16 +117,13 @@ def validate_network_info(network_id: int, protocol_magic: int) -> None:
raise wire.ProcessError("Invalid network id/protocol magic combination!")
-def is_printable_ascii(bytestring: AnyBytes) -> bool:
- """Includes space character."""
- return all(32 <= b <= 126 for b in bytestring)
-
-
def is_unambiguous_ascii(bytestring: AnyBytes) -> bool:
"""
Checks whether the bytestring can be printed as ASCII without confusion.
Based on https://github.com/vacuumlabs/ledger-app-cardano-shelley/blob/6ddc60e8fdff13e35bff5cdf108b84b81a79f10c/src/textUtils.c#L274
"""
+ from apps.common.signverify import is_printable_ascii
+
# no empty strings
if len(bytestring) == 0:
return False
diff --git a/core/src/apps/cardano/sign_message.py b/core/src/apps/cardano/sign_message.py
index 99e8d4be..3606e387 100644
--- a/core/src/apps/cardano/sign_message.py
+++ b/core/src/apps/cardano/sign_message.py
@@ -6,8 +6,9 @@ from trezor.wire.context import call as ctx_call
from apps.cardano.helpers.credential import Credential
from apps.cardano.helpers.paths import SCHEMA_MINT, SCHEMA_PUBKEY
-from apps.cardano.helpers.utils import derive_public_key, is_printable_ascii
+from apps.cardano.helpers.utils import derive_public_key
from apps.common import cbor
+from apps.common.signverify import is_printable_ascii
from . import addresses, seed
diff --git a/core/src/apps/common/signverify.py b/core/src/apps/common/signverify.py
index ad32dc1b..2511aba6 100644
--- a/core/src/apps/common/signverify.py
+++ b/core/src/apps/common/signverify.py
@@ -35,3 +35,8 @@ def decode_message(message: AnyBytes) -> str:
return bytes(message).decode()
except UnicodeError:
return f"hex({hexlify(message).decode()})"
+
+
+def is_printable_ascii(bytestring: AnyBytes) -> bool:
+ """Includes space character."""
+ return all(32 <= b <= 126 for b in bytestring)
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.