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