mirror of
https://github.com/malmeloo/FindMy.py.git
synced 2026-04-17 22:53:56 +02:00
fix: add guard against incorrect account data deserialization
This commit is contained in:
@@ -15,6 +15,7 @@ from typing import (
|
||||
TYPE_CHECKING,
|
||||
Any,
|
||||
Callable,
|
||||
Literal,
|
||||
TypedDict,
|
||||
TypeVar,
|
||||
cast,
|
||||
@@ -91,6 +92,8 @@ class _AccountStateMappingLoginState(TypedDict):
|
||||
class AccountStateMapping(TypedDict):
|
||||
"""JSON mapping representing state of an Apple account instance."""
|
||||
|
||||
type: Literal["account"]
|
||||
|
||||
ids: _AccountStateMappingIds
|
||||
account: _AccountStateMappingAccount
|
||||
login: _AccountStateMappingLoginState
|
||||
@@ -436,6 +439,7 @@ class AsyncAppleAccount(BaseAppleAccount):
|
||||
@override
|
||||
def to_json(self, path: str | Path | None = None, /) -> AccountStateMapping:
|
||||
res: AccountStateMapping = {
|
||||
"type": "account",
|
||||
"ids": {"uid": self._uid, "devid": self._devid},
|
||||
"account": {
|
||||
"username": self._username,
|
||||
@@ -461,6 +465,8 @@ class AsyncAppleAccount(BaseAppleAccount):
|
||||
anisette_libs_path: str | Path | None = None,
|
||||
) -> AsyncAppleAccount:
|
||||
val = read_data_json(val)
|
||||
assert val["type"] == "account"
|
||||
|
||||
try:
|
||||
ani_provider = get_provider_from_mapping(val["anisette"], libs_path=anisette_libs_path)
|
||||
return cls(ani_provider, state_info=val)
|
||||
|
||||
Reference in New Issue
Block a user