def test_set_signature_type_unknown(patch_build_hasher,
                                    patch_cryptography_utils_verify_interface,
                                    patch_cryptography_ec):
    patch_cryptography_utils_verify_interface.side_effect = InterfaceNotImplemented
    with pytest.raises(NotSupportedError) as excinfo:
        _PrehashingAuthenticator(algorithm=MagicMock(), key=sentinel.key)

    excinfo.match(r"Unsupported signing algorithm info")
def test_build_hasher(patch_set_signature_type, patch_cryptography_hashes, patch_cryptography_default_backend):
    mock_algorithm = MagicMock()
    test = _PrehashingAuthenticator(algorithm=mock_algorithm, key=sentinel.key)

    patch_cryptography_hashes.Hash.assert_called_once_with(
        mock_algorithm.signing_hash_type.return_value, backend=patch_cryptography_default_backend.return_value
    )
    assert test._hasher is patch_cryptography_hashes.Hash.return_value
def test_init(patch_set_signature_type, patch_build_hasher):
    test = _PrehashingAuthenticator(algorithm=sentinel.algorithm, key=sentinel.key)

    assert test.algorithm is sentinel.algorithm
    patch_set_signature_type.assert_called_once_with()
    assert test._signature_type is patch_set_signature_type.return_value
    assert test.key is sentinel.key
    patch_build_hasher.assert_called_once_with()
    assert test._hasher is patch_build_hasher.return_value
def test_set_signature_type_elliptic_curve(
        patch_build_hasher, patch_cryptography_utils_verify_interface,
        patch_cryptography_ec):
    mock_algorithm = MagicMock()
    test = _PrehashingAuthenticator(algorithm=mock_algorithm, key=sentinel.key)

    patch_cryptography_utils_verify_interface.assert_called_once_with(
        patch_cryptography_ec.EllipticCurve,
        mock_algorithm.signing_algorithm_info)
    assert test._signature_type is patch_cryptography_ec.EllipticCurve