mirror of
https://github.com/malmeloo/FindMy.py.git
synced 2026-04-20 07:54:17 +02:00
keys: Add name getter/setter to accessories and keypairs
This commit is contained in:
@@ -106,6 +106,10 @@ class FindMyAccessory(RollingKeyPairSource):
|
|||||||
"""Name of this accessory."""
|
"""Name of this accessory."""
|
||||||
return self._name
|
return self._name
|
||||||
|
|
||||||
|
@name.setter
|
||||||
|
def name(self, name: str | None) -> None:
|
||||||
|
self._name = name
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def model(self) -> str | None:
|
def model(self) -> str | None:
|
||||||
"""Model string of this accessory, as provided by the manufacturer."""
|
"""Model string of this accessory, as provided by the manufacturer."""
|
||||||
|
|||||||
@@ -81,7 +81,12 @@ class HasPublicKey(HasHashedPublicKey, ABC):
|
|||||||
class KeyPair(HasPublicKey):
|
class KeyPair(HasPublicKey):
|
||||||
"""A private-public keypair for a trackable FindMy accessory."""
|
"""A private-public keypair for a trackable FindMy accessory."""
|
||||||
|
|
||||||
def __init__(self, private_key: bytes, key_type: KeyType = KeyType.UNKNOWN) -> None:
|
def __init__(
|
||||||
|
self,
|
||||||
|
private_key: bytes,
|
||||||
|
key_type: KeyType = KeyType.UNKNOWN,
|
||||||
|
name: str | None = None,
|
||||||
|
) -> None:
|
||||||
"""Initialize the `KeyPair` with the private key bytes."""
|
"""Initialize the `KeyPair` with the private key bytes."""
|
||||||
priv_int = crypto.bytes_to_int(private_key)
|
priv_int = crypto.bytes_to_int(private_key)
|
||||||
self._priv_key = ec.derive_private_key(
|
self._priv_key = ec.derive_private_key(
|
||||||
@@ -90,12 +95,22 @@ class KeyPair(HasPublicKey):
|
|||||||
)
|
)
|
||||||
|
|
||||||
self._key_type = key_type
|
self._key_type = key_type
|
||||||
|
self._name = name
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def key_type(self) -> KeyType:
|
def key_type(self) -> KeyType:
|
||||||
"""Type of this key."""
|
"""Type of this key."""
|
||||||
return self._key_type
|
return self._key_type
|
||||||
|
|
||||||
|
@property
|
||||||
|
def name(self) -> str | None:
|
||||||
|
"""Name of this KeyPair."""
|
||||||
|
return self._name
|
||||||
|
|
||||||
|
@name.setter
|
||||||
|
def name(self, name: str | None) -> None:
|
||||||
|
self._name = name
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def new(cls) -> KeyPair:
|
def new(cls) -> KeyPair:
|
||||||
"""Generate a new random `KeyPair`."""
|
"""Generate a new random `KeyPair`."""
|
||||||
@@ -138,7 +153,7 @@ class KeyPair(HasPublicKey):
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
def __repr__(self) -> str:
|
def __repr__(self) -> str:
|
||||||
return f'KeyPair(public_key="{self.adv_key_b64}", type={self.key_type})'
|
return f'KeyPair(name="{self.name}", public_key="{self.adv_key_b64}", type={self.key_type})'
|
||||||
|
|
||||||
|
|
||||||
K = TypeVar("K")
|
K = TypeVar("K")
|
||||||
|
|||||||
Reference in New Issue
Block a user