[py]: type improvements and make `VirtualAuthenticator` more pythonic and simplified.
@@ -22,95 +22,41 @@ from base64 import urlsafe_b64encode
from enum import Enum
-class Protocol(Enum):
- """Protocol to communicate with the authenticator."""
+class Protocol(str, Enum):
+ CTAP2: str = "ctap2"
+ U2F: str = "ctap1/u2f"
- CTAP2 = "ctap2"
- U2F = "ctap1/u2f"
-
-class Transport(Enum):
+class Transport(str, Enum):
"""Transport method to communicate with the authenticator."""
- BLE = "ble"
- USB = "usb"
- NFC = "nfc"
- INTERNAL = "internal"
+ BLE: str = "ble"
+ USB: str = "usb"
+ NFC: str = "nfc"
+ INTERNAL: str = "internal"
class VirtualAuthenticatorOptions:
+ # These are so unnecessary but are now public API so we can't remove them without deprecating first.
+ # These should not be class level state in here.
Protocol = Protocol
Transport = Transport
def __init__(self) -> None:
- """Constructor. Initialize VirtualAuthenticatorOptions object.
-
- :default:
- - protocol: Protocol.CTAP2
- - transport: Transport.USB
- - hasResidentKey: False
- - hasUserVerification: False
- - isUserConsenting: True
- - isUserVerified: False
- """
-
- self._protocol: Protocol = Protocol.CTAP2
- self._transport: Transport = Transport.USB
- self._has_resident_key: bool = False
- self._has_user_verification: bool = False
- self._is_user_consenting: bool = True
- self._is_user_verified: bool = False
-
- @property
- def protocol(self) -> str:
- return self._protocol.value
-
- @protocol.setter
- def protocol(self, protocol: Protocol) -> None:
- self._protocol = protocol
-
- @property
- def transport(self) -> str:
- return self._transport.value
-
- @transport.setter
- def transport(self, transport: Transport) -> None:
- self._transport = transport
-
- @property
- def has_resident_key(self) -> bool:
- return self._has_resident_key
+ """Constructor.
- @has_resident_key.setter
- def has_resident_key(self, value: bool) -> None:
- self._has_resident_key = value
-
- @property
- def has_user_verification(self) -> bool:
- return self._has_user_verification
-
- @has_user_verification.setter
- def has_user_verification(self, value: bool) -> None:
- self._has_user_verification = value
-
- @property
- def is_user_consenting(self) -> bool:
- return self._is_user_consenting
-
- @is_user_consenting.setter
- def is_user_consenting(self, value: bool) -> None:
- self._is_user_consenting = value
-
- @property
- def is_user_verified(self) -> bool:
- return self._is_user_verified
+ Initialize VirtualAuthenticatorOptions object.
+ """
- @is_user_verified.setter
- def is_user_verified(self, value: bool) -> None:
- self._is_user_verified = value
+ self.protocol: str = Protocol.CTAP2
+ self.transport: str = Transport.USB
+ self.has_resident_key: bool = False
+ self.has_user_verification: bool = False
+ self.is_user_consenting: bool = True
+ self.is_user_verified: bool = False
- def to_dict(self) -> typing.Dict[str, typing.Any]:
+ def to_dict(self) -> typing.Dict[str, typing.Union[str, bool]]:
return {
"protocol": self.protocol,
"transport": self.transport,
