Esempio n. 1
0
def get_preferred_auth_type(service: BaseService) -> AuthenticationType:
    """Return the preferred authentication type depending on what is supported."""
    features_string = service.properties.get("features")
    if features_string:
        features = parse_features(features_string)
        if AirPlayFlags.SupportsCoreUtilsPairingAndEncryption in features:
            return AuthenticationType.HAP
    return AuthenticationType.Legacy
Esempio n. 2
0
def extract_credentials(service: BaseService) -> HapCredentials:
    """Extract credentials from service based on what's supported."""
    if service.credentials is not None:
        return parse_credentials(service.credentials)

    flags = parse_features(service.properties.get("features", "0x0"))
    if (
        AirPlayFlags.SupportsSystemPairing in flags
        or AirPlayFlags.SupportsCoreUtilsPairingAndEncryption in flags
    ):
        return TRANSIENT_CREDENTIALS

    return NO_CREDENTIALS
Esempio n. 3
0
def pair(config: BaseConfig, service: BaseService,
         session_manager: ClientSessionManager,
         loop: asyncio.AbstractEventLoop, **kwargs) -> PairingHandler:
    """Return pairing handler for protocol."""
    features = service.properties.get("ft")
    if not features:
        # TODO: Better handle cases like these (provide API)
        raise exceptions.NotSupportedError("pairing not required")

    flags = parse_features(features)
    if AirPlayFlags.SupportsLegacyPairing not in flags:
        raise exceptions.NotSupportedError("legacy pairing not supported")

    return AirPlayPairingHandler(config, service, session_manager,
                                 AuthenticationType.Legacy, **kwargs)
Esempio n. 4
0
 def __init__(self, service: BaseService) -> None:
     """Initialize a new AirPlayFeatures instance."""
     self.service = service
     self._features = parse_features(
         self.service.properties.get("features", "0x0"))
Esempio n. 5
0
def test_bad_input(value):
    with pytest.raises(ValueError):
        parse_features(value)
Esempio n. 6
0
def test_parse_features(flags, output):
    assert parse_features(flags) == output