Merge pull request #416 from Lukasa/docs/asn1

Explain that FILETYPE_ASN1 is DER.
diff --git a/.travis.yml b/.travis.yml
index 00902b8..d65665e 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -45,6 +45,21 @@
   - python: "pypy"
     env: TOXENV=pypy-cryptographyMaster
 
+  # And older cryptography versions.
+  - python: "2.6"
+    env: TOXENV=py26-cryptography1.1
+  - python: "2.7"
+    env: TOXENV=py27-cryptography1.1
+  - python: "3.3"
+    env: TOXENV=py33-cryptography1.1
+  - python: "3.4"
+    env: TOXENV=py34-cryptography1.1
+  - python: "3.5"
+    env: TOXENV=py35-cryptography1.1
+  - python: "pypy"
+    env: TOXENV=pypy-cryptography1.1
+
+
   # Make sure we don't break Twisted
   - python: "2.7"
     env: TOXENV=py27-twistedMaster
@@ -84,8 +99,6 @@
   - env: TOXENV=py33-cryptographyMaster
   - env: TOXENV=py34-cryptographyMaster
   - env: TOXENV=py35-cryptographyMaster
-  - env: TOXENV=pypy-cryptographyMaster
-  - env: TOXENV=pypy
 
 install:
   - |
@@ -96,6 +109,15 @@
       python get-pip.py --user
       pip install --user virtualenv
     else
+      # install our own pypy. This can be removed if and when Travis gets a reasonably up to date pypy
+      if [[ "${TOXENV}" = pypy* ]]; then
+          git clone https://github.com/yyuu/pyenv.git ~/.pyenv
+          PYENV_ROOT="$HOME/.pyenv"
+          PATH="$PYENV_ROOT/bin:$PATH"
+          eval "$(pyenv init -)"
+          pyenv install pypy-4.0.1
+          pyenv global pypy-4.0.1
+      fi
       pip install virtualenv
     fi
     python -m virtualenv ~/.venv
@@ -110,6 +132,12 @@
       export CFLAGS="-I/usr/local/opt/openssl/include"
       export PATH="/usr/local/opt/openssl/bin:$PATH"
     fi
+    # activate the pypy env we installed via our custom pyenv in the install stage
+    if [[ "${TOXENV}" == "pypy" ]]; then
+        PYENV_ROOT="$HOME/.pyenv"
+        PATH="$PYENV_ROOT/bin:$PATH"
+        eval "$(pyenv init -)"
+    fi
     # This section potentially downloads, compiles and installs openssl 0.9.8zg
     if [[ "${OPENSSL}" == "0.9.8" ]]; then
       # download, compile, and install if it's not already present via travis cache
diff --git a/setup.cfg b/setup.cfg
index e68206f..8a1dc84 100644
--- a/setup.cfg
+++ b/setup.cfg
@@ -1,5 +1,5 @@
 [pytest]
-minversion = 2.8.2
+minversion = 2.8.5
 strict = true
 testpaths = tests
 
diff --git a/src/OpenSSL/crypto.py b/src/OpenSSL/crypto.py
index a00b5c0..6d78bd7 100644
--- a/src/OpenSSL/crypto.py
+++ b/src/OpenSSL/crypto.py
@@ -247,7 +247,7 @@
         if self._only_public:
             raise TypeError("public key only")
 
-        if _lib.EVP_PKEY_type(self._pkey.type) != _lib.EVP_PKEY_RSA:
+        if _lib.EVP_PKEY_type(self.type()) != _lib.EVP_PKEY_RSA:
             raise TypeError("key type unsupported")
 
         rsa = _lib.EVP_PKEY_get1_RSA(self._pkey)
@@ -263,7 +263,12 @@
 
         :return: The type of the key.
         """
-        return self._pkey.type
+        try:
+            # cryptography 1.2+
+            return _lib.Cryptography_EVP_PKEY_id(self._pkey)
+        except AttributeError:
+            # Older releases of cryptography.
+            return self._pkey.type
 
     def bits(self):
         """
diff --git a/tests/test_ssl.py b/tests/test_ssl.py
index de144ce..ecdb40c 100644
--- a/tests/test_ssl.py
+++ b/tests/test_ssl.py
@@ -2346,42 +2346,8 @@
         server = self._loopbackServerFactory(server)
         client = self._loopbackClientFactory(client)
 
-        self.assertEqual('before/accept initialization',
-                         server.state_string().decode())
-        self.assertEqual('before/connect initialization',
-                         client.state_string().decode())
-
-        for conn in [server, client]:
-            try:
-                conn.do_handshake()
-            except WantReadError:
-                pass
-
-        self.assertEqual('SSLv3 read client hello B',
-                         server.state_string().decode())
-        self.assertEqual('SSLv3 read server hello A',
-                         client.state_string().decode())
-
-        for conn in [server, client]:
-            try:
-                conn.do_handshake()
-            except WantReadError:
-                pass
-
-        assert server.state_string().decode() in (
-            "SSLv3 read client certificate A",
-            "SSLv3 read client key exchange A",  # 1.0.2d+
-        )
-        self.assertEqual('SSLv3 read server session ticket A',
-                         client.state_string().decode())
-
-        for conn in [server, client]:
-            conn.do_handshake()
-
-        self.assertEqual('SSL negotiation finished successfully',
-                         server.state_string().decode())
-        self.assertEqual('SSL negotiation finished successfully',
-                         client.state_string().decode())
+        assert b"before/accept initialization" == server.state_string()
+        assert b"before/connect initialization" == client.state_string()
 
     def test_app_data_wrong_args(self):
         """
diff --git a/tox.ini b/tox.ini
index 73f6018..cf4912b 100644
--- a/tox.ini
+++ b/tox.ini
@@ -1,5 +1,5 @@
 [tox]
-envlist = coverage-clean,{pypy,py26,py27,py33,py34,py35}{,-cryptographyMaster},py27-twistedMaster,pypi-readme,check-manifest,flake8,docs,coverage-report
+envlist = coverage-clean,{pypy,py26,py27,py33,py34,py35}{,-cryptographyMaster,-cryptography1.1},py27-twistedMaster,pypi-readme,check-manifest,flake8,docs,coverage-report
 
 [testenv]
 whitelist_externals =
@@ -7,8 +7,9 @@
 passenv = ARCHFLAGS CFLAGS LC_ALL LDFLAGS PATH LD_LIBRARY_PATH TERM
 deps =
     coverage
-    pytest>=2.8.2,!=2.8.4
+    pytest>=2.8.5
     cryptographyMaster: git+https://github.com/pyca/cryptography.git
+    cryptography1.1: cryptography<1.2
 setenv =
     # Do not allow the executing environment to pollute the test environment
     # with extra packages.