Add a register_interface_if decorator. (#3120)

* Add a register_interface_if decorator.

* Add tests.

* PEP 8.
diff --git a/src/cryptography/utils.py b/src/cryptography/utils.py
index d3e845a..48ed449 100644
--- a/src/cryptography/utils.py
+++ b/src/cryptography/utils.py
@@ -31,6 +31,15 @@
     return register_decorator
 
 
+def register_interface_if(predicate, iface):
+    def register_decorator(klass):
+        if predicate:
+            verify_interface(iface, klass)
+            iface.register(klass)
+        return klass
+    return register_decorator
+
+
 if hasattr(int, "from_bytes"):
     int_from_bytes = int.from_bytes
 else:
diff --git a/tests/test_interfaces.py b/tests/test_interfaces.py
index bdb4a94..97df45a 100644
--- a/tests/test_interfaces.py
+++ b/tests/test_interfaces.py
@@ -8,7 +8,33 @@
 
 import six
 
-from cryptography.utils import InterfaceNotImplemented, verify_interface
+from cryptography.utils import (
+    InterfaceNotImplemented, register_interface_if, verify_interface
+)
+
+
+def test_register_interface_if_true():
+    @six.add_metaclass(abc.ABCMeta)
+    class SimpleInterface(object):
+        pass
+
+    @register_interface_if(1 == 1, SimpleInterface)
+    class SimpleClass(object):
+        pass
+
+    assert issubclass(SimpleClass, SimpleInterface) is True
+
+
+def test_register_interface_if_false():
+    @six.add_metaclass(abc.ABCMeta)
+    class SimpleInterface(object):
+        pass
+
+    @register_interface_if(1 == 2, SimpleInterface)
+    class SimpleClass(object):
+        pass
+
+    assert issubclass(SimpleClass, SimpleInterface) is False
 
 
 class TestVerifyInterface(object):