Skip to content

Commit

Permalink
Update error handling and version support
Browse files Browse the repository at this point in the history
Added debug logging for unknown signal errors, updated supported account file versions to include version 9, and implemented loading of version 9 data. Incremented package version to 0.5.9 to reflect these changes.
  • Loading branch information
pnearing committed Sep 10, 2024
1 parent 27d0c6b commit 08ab7a9
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 4 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "SignalCliAPi"
version = "0.5.8.6"
version = "0.5.9"
authors = [
{ name="Peter Nearing", email="[email protected]" }
]
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = SignalCliApi
version = 0.5.8.6
version = 0.5.9
author = Peter Nearing
author_email = [email protected]
description = A python interface to the signal-cli found at https://github.com/AsamK/signal-cli
Expand Down
2 changes: 1 addition & 1 deletion src/signal_cli_api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
File: __init__.py
Description: A python3 interface to signal-cli.
"""
__version__: str = '0.5.8.6'
__version__: str = '0.5.9'
__author__: str = 'Peter Nearing'
__email__: str = '[email protected]'

Expand Down
40 changes: 39 additions & 1 deletion src/signal_cli_api/signal_account.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

class SignalAccount:
"""Class to store an account."""
supportedAccountFileVersions: tuple[int, int] = (5, 6, 8)
supportedAccountFileVersions: tuple[int, int] = (5, 6, 8, 9)
"""Supported account detail file versions."""

def __init__(self,
Expand Down Expand Up @@ -232,6 +232,15 @@ def __init__(self,
"""I don't know."""
self.pni_account_data: Optional[dict[str, int | str]] = None
"""I don't know."""
# Version 9 info:
self.timestamp: Optional[SignalTimestamp] = None
"""I don't know."""
self.username_link_entropy: Optional[str] = None
"""I don't know"""
self.username_link_server_id: Optional[str] = None
"""I don't know."""

# Receiving properties:
self._is_receiving: bool = False
"""Whether this account is current receiving messages."""

Expand Down Expand Up @@ -423,6 +432,35 @@ def __load_version_8__(self, raw_account: dict[str, Any]) -> None:
raise InvalidDataFile(error_message, e, self._account_file_path) from e
logger.debug("Data loaded.")

def __load_version_9__(self, raw_account: dict[str, Any]) -> None:
logger: logging.Logger = logging.getLogger(__name__ + '.' +
self.__load_version_9__.__name__)
logger.debug("Loading version 9 data...")
try:
self.timestamp = SignalTimestamp(timestamp=raw_account['timestamp'])
self.service_environment = raw_account['serviceEnvironment']
self.registered = raw_account['registered']
self.number = raw_account['number']
self.username = raw_account['username']
self.encrypted_device_name = raw_account['encryptedDeviceName']
self.device_id = raw_account['deviceId']
self.is_multi_device = raw_account['isMultiDevice']
self.password = raw_account['password']
self.aci_account_data = raw_account['aciAccountData']
self.pni_account_data = raw_account['pniAccountData']
self.registration_lock_pin = raw_account['registrationLockPin']
self.pin_master_key = raw_account['pinMasterKey']
self.storage_key = raw_account['storageKey']
self.profile_key = raw_account['profileKey']
self.username_link_entropy = raw_account['usernameLinkEntropy']
self.username_link_server_id = raw_account['usernameLinkServerId']
except KeyError as e:
error_message: str = "KeyError while loading version 9 data: {str(e.args)}."
logger.critical("Raising InvalidDataFile(%s). File: %s", error_message,
self._account_file_path)
raise InvalidDataFile(error_message, e, self._account_file_path) from e
logger.debug("Data loaded.")

def __do_load__(self) -> None:
"""
Load the properties of the account from the account detail file.
Expand Down
1 change: 1 addition & 0 deletions src/signal_cli_api/signal_link_thread.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,7 @@ def run(self) -> None:
self.__call_callback__(LinkAccountCallbackStates.LINK_EXISTS_ERROR, signal_message)
elif signal_code == -2:
logger.debug("Calling unknown error callback.")
logger.debug("signal error message = %s", signal_message)
self.__call_callback__(LinkAccountCallbackStates.LINK_UNKNOWN_ERROR, signal_message)
elif signal_code == -3:
logger.debug("Calling timeout error callback.")
Expand Down

0 comments on commit 08ab7a9

Please sign in to comment.