Add custom 'install' command class

CFFIBuild adds ext_modules late in the configuration phase. However,
distutils default 'install' command also parses setup.py and thus misses
that cffi contains several extension modules rather than being pure. As
a consequence, add a CFFIInstall with a proper finalize_options method
and use it.
diff --git a/setup.py b/setup.py
index ccb1e5f..c1a6d64 100644
--- a/setup.py
+++ b/setup.py
@@ -21,6 +21,7 @@
 import pkg_resources
 
 from setuptools import find_packages, setup
+from setuptools.command.install import install
 from setuptools.command.test import test
 
 
@@ -53,6 +54,25 @@
     test_requirements.append(VECTORS_DEPENDENCY)
 
 
+def get_ext_modules():
+    from cryptography.hazmat.bindings.commoncrypto.binding import (
+        Binding as CommonCryptoBinding
+    )
+    from cryptography.hazmat.bindings.openssl.binding import (
+        Binding as OpenSSLBinding
+    )
+    from cryptography.hazmat.primitives import constant_time, padding
+
+    ext_modules = [
+        OpenSSLBinding().ffi.verifier.get_extension(),
+        constant_time._ffi.verifier.get_extension(),
+        padding._ffi.verifier.get_extension()
+    ]
+    if CommonCryptoBinding.is_available():
+        ext_modules.append(CommonCryptoBinding().ffi.verifier.get_extension())
+    return ext_modules
+
+
 class CFFIBuild(build):
     """
     This class exists, instead of just providing ``ext_modules=[...]`` directly
@@ -64,27 +84,22 @@
     """
 
     def finalize_options(self):
-        from cryptography.hazmat.bindings.commoncrypto.binding import (
-            Binding as CommonCryptoBinding
-        )
-        from cryptography.hazmat.bindings.openssl.binding import (
-            Binding as OpenSSLBinding
-        )
-        from cryptography.hazmat.primitives import constant_time, padding
-
-        self.distribution.ext_modules = [
-            OpenSSLBinding().ffi.verifier.get_extension(),
-            constant_time._ffi.verifier.get_extension(),
-            padding._ffi.verifier.get_extension()
-        ]
-        if CommonCryptoBinding.is_available():
-            self.distribution.ext_modules.append(
-                CommonCryptoBinding().ffi.verifier.get_extension()
-            )
-
+        self.distribution.ext_modules = get_ext_modules()
         build.finalize_options(self)
 
 
+class CFFIInstall(install):
+    """
+    As a consequence of CFFIBuild and it's late addition of ext_modules, we
+    need the equivalent for the ``install`` command to install into platlib
+    install-dir rather than purelib.
+    """
+
+    def finalize_options(self):
+        self.distribution.ext_modules = get_ext_modules()
+        install.finalize_options(self)
+
+
 class PyTest(test):
     def finalize_options(self):
         test.finalize_options(self)
@@ -154,6 +169,7 @@
     ext_package="cryptography",
     cmdclass={
         "build": CFFIBuild,
+        "install": CFFIInstall,
         "test": PyTest,
     }
 )