File size: 207,756 Bytes
5980447
1
2
{"repo": "IdentityPython/pyXMLSecurity", "pull_number": 41, "instance_id": "IdentityPython__pyXMLSecurity-41", "issue_numbers": "", "base_commit": "982550b81821253b837dee928c1e527fd405e175", "patch": "diff --git a/src/xmlsec/PyCryptoShim.py b/src/xmlsec/PyCryptoShim.py\nnew file mode 100644\n--- /dev/null\n+++ b/src/xmlsec/PyCryptoShim.py\n@@ -0,0 +1,47 @@\n+\"\"\"\n+Emulate pycrypto RSAobj object as used by former crypto backend \n+rsa_x509_pem.\n+\"\"\"\n+\n+datefmt = \"%y%m%d%H%M%SZ\"\n+\n+class RSAobjShim(object):\n+\n+    def __init__(self, cert):\n+        self.cert = cert\n+\n+        self.validity = dict()\n+        self.validity['notAfter'] = [self.cert.not_valid_after.strftime(datefmt)]\n+        self.validity['notBefore'] = [self.cert.not_valid_before.strftime(datefmt)]\n+        self.subject = self.cert.subject\n+        self.issuer = self.cert.issuer\n+\n+    def getSubject(self):\n+        return self.subject\n+\n+    def get_subject(self):\n+        return self.getSubject()\n+\n+    def getIssuer(self):\n+        return self.issuer\n+\n+    def get_issuer(self):\n+        return self.getIssuer()\n+\n+    def getValidity(self):\n+        return self.validity\n+\n+    def getNotAfter(self):\n+        return self.getValidity()['notAfter'][0]\n+\n+    def get_notAfter(self):\n+        return self.getNotAfter()\n+\n+    def getNotBefore(self):\n+        return self.getValidity()['notBefore'][0]\n+\n+    def get_notBefore(self):\n+        return self.getNotBefore()\n+\n+    def dict(self):\n+        raise NotImplementedError(\"Legacy interface not supported anymore.\")\ndiff --git a/src/xmlsec/__init__.py b/src/xmlsec/__init__.py\n--- a/src/xmlsec/__init__.py\n+++ b/src/xmlsec/__init__.py\n@@ -8,13 +8,11 @@\n from defusedxml import lxml\n from lxml import etree as etree\n import logging\n-import hashlib\n import copy\n-from . import int_to_bytes as itb\n from lxml.builder import ElementMaker\n from xmlsec.exceptions import XMLSigException\n from xmlsec import constants\n-from xmlsec.utils import parse_xml, pem2b64, unescape_xml_entities, delete_elt, root_elt, b64d, b64e, b642cert\n+from xmlsec.utils import parse_xml, pem2b64, unescape_xml_entities, delete_elt, root_elt, b64d, b64e\n import xmlsec.crypto\n import pyconfig\n \n@@ -91,20 +89,6 @@ def _signed_value(data, key_size, do_pad, hash_alg):  # TODO Do proper asn1 CMS\n         return asn_digest\n \n \n-def _digest(data, hash_alg):\n-    \"\"\"\n-    Calculate a hash digest of algorithm hash_alg and return the result base64 encoded.\n-\n-    :param hash_alg: String with algorithm, such as 'sha1'\n-    :param data: The data to digest\n-    :returns: Base64 string\n-    \"\"\"\n-    h = getattr(hashlib, hash_alg)()\n-    h.update(data)\n-    digest = b64e(h.digest())\n-    return digest\n-\n-\n def _get_by_id(t, id_v):\n     for id_a in config.id_attributes:\n         logging.debug(\"Looking for #%s using id attribute '%s'\" % (id_v, id_a))\n@@ -116,14 +100,10 @@ def _get_by_id(t, id_v):\n \n def _alg(elt):\n     \"\"\"\n-    Return the hashlib name of an Algorithm. Hopefully.\n+    Return the xmldsig name of an Algorithm. Hopefully.\n     :returns: None or string\n     \"\"\"\n-    uri = elt.get('Algorithm', None)\n-    if uri is None:\n-        return None\n-    else:\n-        return uri\n+    return elt.get('Algorithm', None)\n \n \n def _remove_child_comments(t):\n@@ -194,7 +174,7 @@ def _process_references(t, sig, verify_mode=True, sig_path=\".//{%s}Signature\" %\n \n         hash_alg = _ref_digest(ref)\n         logging.debug(\"using hash algorithm %s\" % hash_alg)\n-        digest = _digest(obj, hash_alg)\n+        digest = xmlsec.crypto._digest(obj, hash_alg)\n         logging.debug(\"computed %s digest %s for ref %s\" % (hash_alg, digest, uri))\n         dv = ref.find(\".//{%s}DigestValue\" % NS['ds'])\n \n@@ -222,9 +202,10 @@ def _ref_digest(ref):\n     if dm is None:\n         raise XMLSigException(\"Unable to find DigestMethod for Reference@URI {!s}\".format(ref.get('URI')))\n     alg_uri = _alg(dm)\n-    hash_alg = (alg_uri.split(\"#\"))[1]\n-    if not hash_alg:\n-        raise XMLSigException(\"Unable to determine digest algorithm from {!s}\".format(alg_uri))\n+    if alg_uri is None:\n+        raise XMLSigException(\"No suitable DigestMethod\")\n+    hash_alg = constants.sign_alg_xmldsig_digest_to_internal(alg_uri.lower())\n+\n     return hash_alg\n \n \n@@ -327,14 +308,27 @@ def _verify(t, keyspec, sig_path=\".//{%s}Signature\" % NS['ds'], drop_signature=F\n             si = sig.find(\".//{%s}SignedInfo\" % NS['ds'])\n             logging.debug(\"Found signedinfo {!s}\".format(etree.tostring(si)))\n             cm_alg = _cm_alg(si)\n-            sig_digest_alg = _sig_digest(si)\n+            try:\n+                sig_digest_alg = _sig_alg(si)\n+            except AttributeError:\n+                raise XMLSigException(\"Failed to validate {!s} because of unsupported hash format\".format(etree.tostring(sig)))\n \n             refmap = _process_references(t, sig, verify_mode=True, sig_path=sig_path, drop_signature=drop_signature)\n             for ref,obj in refmap.items():\n-                b_digest = _create_signature_digest(si, cm_alg, sig_digest_alg)\n-                actual = _signed_value(b_digest, this_cert.keysize, True, sig_digest_alg)\n-                if not this_cert.verify(b64d(sv), actual):\n-                    raise XMLSigException(\"Failed to validate {!s} using sig digest {!s} and cm {!s}\".format(etree.tostring(sig),sig_digest_alg,cm_alg))\n+\n+                logging.debug(\"transform %s on %s\" % (cm_alg, etree.tostring(si)))\n+                sic = _transform(cm_alg, si)\n+                logging.debug(\"SignedInfo C14N: %s\" % sic)\n+                if this_cert.do_digest:\n+                    digest = xmlsec.crypto._digest(sic, sig_digest_alg)\n+                    logging.debug(\"SignedInfo digest: %s\" % digest)\n+                    b_digest = b64d(digest)\n+                    actual = _signed_value(b_digest, this_cert.keysize, True, sig_digest_alg)\n+                else:\n+                    actual = sic\n+\n+                if not this_cert.verify(b64d(sv), actual, sig_digest_alg):\n+                    raise XMLSigException(\"Failed to validate {!s} using sig digest {!s} and cm {!s}\".format(etree.tostring(sig), sig_digest_alg, cm_alg))\n                 validated.append(obj)\n         except XMLSigException, ex:\n             logging.error(ex)\n@@ -456,15 +450,24 @@ def sign(t, key_spec, cert_spec=None, reference_uri='', insert_index=0, sig_path\n         si = sig.find(\".//{%s}SignedInfo\" % NS['ds'])\n         assert si is not None\n         cm_alg = _cm_alg(si)\n-        digest_alg = _sig_digest(si)\n+        sig_alg = _sig_alg(si)\n \n         _process_references(t, sig, verify_mode=False, sig_path=sig_path)\n         # XXX create signature reference duplicates/overlaps process references unless a c14 is part of transforms\n-        b_digest = _create_signature_digest(si, cm_alg, digest_alg)\n+        logging.debug(\"transform %s on %s\" % (cm_alg, etree.tostring(si)))\n+        sic = _transform(cm_alg, si)\n+        logging.debug(\"SignedInfo C14N: %s\" % sic)\n \n         # sign hash digest and insert it into the XML\n-        tbs = _signed_value(b_digest, private.keysize, private.do_padding, digest_alg)\n-        signed = private.sign(tbs)\n+        if private.do_digest:\n+            digest = xmlsec.crypto._digest(sic, sig_alg)\n+            logging.debug(\"SignedInfo digest: %s\" % digest)\n+            b_digest = b64d(digest)\n+            tbs = _signed_value(b_digest, private.keysize, private.do_padding, sig_alg)\n+        else:\n+            tbs = sic\n+\n+        signed = private.sign(tbs, sig_alg)\n         signature = b64e(signed)\n         logging.debug(\"SignatureValue: %s\" % signature)\n         sv = sig.find(\".//{%s}SignatureValue\" % NS['ds'])\n@@ -493,25 +496,8 @@ def _cm_alg(si):\n \n def _sig_alg(si):\n     sm = si.find(\".//{%s}SignatureMethod\" % NS['ds'])\n-    sig_alg = _alg(sm)\n-    if sm is None or sig_alg is None:\n+    sig_uri = _alg(sm)\n+    if sm is None or sig_uri is None:\n         raise XMLSigException(\"No SignatureMethod\")\n-    return (sig_alg.split(\"#\"))[1]\n-\n-\n-def _sig_digest(si):\n-    return (_sig_alg(si).split(\"-\"))[1]\n-\n-\n-def _create_signature_digest(si, cm_alg, hash_alg):\n-    \"\"\"\n-    :param hash_alg: string such as 'sha1'\n-    \"\"\"\n-    logging.debug(\"transform %s on %s\" % (cm_alg, etree.tostring(si)))\n-    sic = _transform(cm_alg, si)\n-    logging.debug(\"SignedInfo C14N: %s\" % sic)\n-    digest = _digest(sic, hash_alg)\n-    logging.debug(\"SignedInfo digest: %s\" % digest)\n-    return b64d(digest)\n-\n \n+    return constants.sign_alg_xmldsig_sig_to_internal(sig_uri.lower())\ndiff --git a/src/xmlsec/constants.py b/src/xmlsec/constants.py\n--- a/src/xmlsec/constants.py\n+++ b/src/xmlsec/constants.py\n@@ -1,5 +1,8 @@\n __author__ = 'leifj'\n \n+from xmlsec.exceptions import XMLSigException\n+\n+\n # ASN.1 BER SHA1 algorithm designator prefixes (RFC3447)\n ASN1_BER_ALG_DESIGNATOR_PREFIX = {\n     # disabled 'md2': '\\x30\\x20\\x30\\x0c\\x06\\x08\\x2a\\x86\\x48\\x86\\xf7\\x0d\\x02\\x02\\x05\\x00\\x04\\x10',\n@@ -15,16 +18,45 @@\n TRANSFORM_C14N_EXCLUSIVE = 'http://www.w3.org/2001/10/xml-exc-c14n#'\n TRANSFORM_C14N_INCLUSIVE = 'http://www.w3.org/TR/2001/REC-xml-c14n-20010315'\n \n-ALGORITHM_DIGEST_SHA1 = \"http://www.w3.org/2000/09/xmldsig#sha1\"\n-ALGORITHM_SIGNATURE_RSA_SHA1 = \"http://www.w3.org/2000/09/xmldsig#rsa-sha1\"\n \n-ALGORITHM_DIGEST_SHA256 = \"http://www.w3.org/2001/04/xmlenc#sha256\"\n-ALGORITHM_SIGNATURE_RSA_SHA256 = \"http://www.w3.org/2001/04/xmldsig-more#rsa-sha256\"\n \n-ALGORITHM_DIGEST_SHA384 = \"http://www.w3.org/2001/04/xmlenc#sha384\"\n-ALGORITHM_SIGNATURE_RSA_SHA384 = \"http://www.w3.org/2001/04/xmldsig-more#rsa-sha384\"\n+# All suported crypto primitives and some factories normalization of names as\n+# pyca/cryptography uses UPPERCASE object-names for hashes.\n \n+ALGORITHM_DIGEST_SHA1 = \"http://www.w3.org/2000/09/xmldsig#sha1\"\n+ALGORITHM_DIGEST_SHA256 = \"http://www.w3.org/2001/04/xmlenc#sha256\"\n+ALGORITHM_DIGEST_SHA384 = \"http://www.w3.org/2001/04/xmlenc#sha384\"\n ALGORITHM_DIGEST_SHA512 = \"http://www.w3.org/2001/04/xmlenc#sha512\"\n+\n+ALGORITHM_SIGNATURE_RSA_SHA1 = \"http://www.w3.org/2000/09/xmldsig#rsa-sha1\"\n+ALGORITHM_SIGNATURE_RSA_SHA256 = \"http://www.w3.org/2001/04/xmldsig-more#rsa-sha256\"\n+ALGORITHM_SIGNATURE_RSA_SHA384 = \"http://www.w3.org/2001/04/xmldsig-more#rsa-sha384\"\n ALGORITHM_SIGNATURE_RSA_SHA512 = \"http://www.w3.org/2001/04/xmldsig-more#rsa-sha512\"\n \n+sign_alg_xmldsig_digest_to_internal_d = {\n+    ALGORITHM_DIGEST_SHA1: 'SHA1',\n+    ALGORITHM_DIGEST_SHA256: 'SHA256',\n+    ALGORITHM_DIGEST_SHA384: 'SHA384',\n+    ALGORITHM_DIGEST_SHA512: 'SHA512',\n+}\n+\n+sign_alg_xmldsig_sig_to_internal_d = {\n+    ALGORITHM_SIGNATURE_RSA_SHA1: 'SHA1',\n+    ALGORITHM_SIGNATURE_RSA_SHA256: 'SHA256',\n+    ALGORITHM_SIGNATURE_RSA_SHA384: 'SHA384',\n+    ALGORITHM_SIGNATURE_RSA_SHA512: 'SHA512',\n+}\n+\n+\n+def _try_a_to_b(dic, item):\n+    try:\n+        return dic[item]\n+    except KeyError:\n+        raise XMLSigException(\"Algorithm '%s' not supported.\" % item)\n+\n+def sign_alg_xmldsig_sig_to_internal(xmldsig_sign_alg):\n+    return _try_a_to_b(sign_alg_xmldsig_sig_to_internal_d, xmldsig_sign_alg)\n+\n \n+def sign_alg_xmldsig_digest_to_internal(xmldsig_digest_alg):\n+    return _try_a_to_b(sign_alg_xmldsig_digest_to_internal_d, xmldsig_digest_alg)\ndiff --git a/src/xmlsec/crypto.py b/src/xmlsec/crypto.py\n--- a/src/xmlsec/crypto.py\n+++ b/src/xmlsec/crypto.py\n@@ -1,12 +1,17 @@\n import io\n import os\n import base64\n-import hashlib\n import logging\n import threading\n+from binascii import hexlify\n from UserDict import DictMixin\n-from . import rsa_x509_pem\n from xmlsec.exceptions import XMLSigException\n+from cryptography.exceptions import InvalidSignature\n+from cryptography.hazmat.backends import default_backend\n+from cryptography.hazmat.primitives import serialization, hashes\n+from cryptography.hazmat.primitives.asymmetric import rsa, padding, utils\n+from cryptography.x509 import load_pem_x509_certificate, load_der_x509_certificate, Certificate\n+\n \n NS = {'ds': 'http://www.w3.org/2000/09/xmldsig#'}\n \n@@ -40,11 +45,10 @@ def from_keyspec(keyspec, private=False, signature_element=None):\n \n       {'keyspec': keyspec,\n        'source': 'pkcs11' or 'file' or 'fingerprint' or 'keyspec',\n-       'data': X.509 certificate as string if source != 'pkcs11',\n-       'key': Parsed key from certificate if source != 'pkcs11',\n+       'cert_pem': key as string if source != 'pkcs11',\n+       'key': pyca.cryptography key instance if source != 'pkcs11',\n        'keysize': Keysize in bits if source != 'pkcs11',\n-       'f_public': rsa_x509_pem.f_public(key) if private == False,\n-       'f_private': rsa_x509_pem.f_private(key) if private == True,\n+       'private': True if private key, False if public key/certificate,\n       }\n \n     :param keyspec: Keyspec as string or callable. See above.\n@@ -68,9 +72,8 @@ def from_keyspec(keyspec, private=False, signature_element=None):\n     thread_local.cache = cache\n     return key\n \n-\n class XMlSecCrypto(object):\n-    def __init__(self, source, do_padding, private):\n+    def __init__(self, source, do_padding, private, do_digest=True):\n         # Public attributes\n         self.source = source\n         self.keysize = None\n@@ -78,16 +81,32 @@ def __init__(self, source, do_padding, private):\n         self.key = None\n         self.is_private = private\n         self.do_padding = do_padding\n-\n-    def sign(self, data):\n-        # This used to be f_private()\n-        return rsa_x509_pem.f_sign(self.key)(data)\n-\n-    def verify(self, data, actual):\n-        # This used to be f_public()\n-        expected = rsa_x509_pem.f_public(self.key)(data)\n-        # XXX does constant time comparision of RSA signatures matter?\n-        return actual == expected\n+        self.do_digest = do_digest\n+\n+    def sign(self, data, hash_alg, pad_alg=\"PKCS1v15\"):\n+        if self.is_private:\n+            hasher = getattr(hashes, hash_alg)\n+            padder = getattr(padding, pad_alg)\n+            return self.key.sign(data, padder(), hasher())\n+        else:\n+            raise XMLSigException('Signing is only possible with a private key.')\n+\n+    def verify(self, signature, msg, hash_alg, pad_alg=\"PKCS1v15\"):\n+        if not self.is_private:\n+            try:\n+                hasher = getattr(hashes, hash_alg)\n+                padder = getattr(padding, pad_alg)\n+                self.key.public_key().verify(\n+                    signature,\n+                    msg,\n+                    padder(),\n+                    hasher()\n+                )\n+            except InvalidSignature:\n+                return False\n+            return True\n+        else:\n+            raise XMLSigException('Verifying is only possible with a certificate.')\n \n \n class XMLSecCryptoCallable(XMlSecCrypto):\n@@ -95,24 +114,37 @@ def __init__(self, private):\n         super(XMLSecCryptoCallable, self).__init__(source='callable', do_padding=True, private=private)\n         self._private_callable = private\n \n-    def sign(self, data):\n+    def sign(self, data, hash_alg=None):\n         return self._private_callable(data)\n \n-    def verify(self, data, actual):\n+    def verify(self, data, actual, hash_alg=None):\n         raise XMLSigException('Trying to verify with a private key (from a callable)')\n \n \n class XMLSecCryptoFile(XMlSecCrypto):\n     def __init__(self, filename, private):\n-        super(XMLSecCryptoFile, self).__init__(source='file', do_padding=True, private=private)\n-        with io.open(filename) as c:\n-            data = c.read()\n-\n-        cert = rsa_x509_pem.parse(data)\n-        self.cert_pem = cert.get('pem')\n-        self.key = rsa_x509_pem.get_key(cert)\n-        self.keysize = int(self.key.size()) + 1\n-\n+        super(XMLSecCryptoFile, self).__init__(source='file', do_padding=False, private=private, do_digest=False)\n+        with io.open(filename, \"rb\") as file:\n+            if private:\n+                self.key = serialization.load_pem_private_key(file.read(), password=None, backend=default_backend())\n+                if not isinstance(self.key, rsa.RSAPrivateKey):\n+                    raise XMLSigException(\"We don't support non-RSA private keys at the moment.\")\n+\n+                # XXX now we could implement encrypted-PEM-support\n+                self.cert_pem = self.key.private_bytes(\n+                    encoding=serialization.Encoding.PEM,\n+                    format=serialization.PrivateFormat.PKCS8,\n+                    encryption_algorithm=serialization.NoEncryption())\n+\n+                self.keysize = self.key.key_size\n+            else:\n+                self.key = load_pem_x509_certificate(file.read(), backend=default_backend())\n+                if not isinstance(self.key.public_key(), rsa.RSAPublicKey):\n+                    raise XMLSigException(\"We don't support non-RSA public keys at the moment.\")\n+\n+                self.cert_pem = self.key.public_bytes(encoding=serialization.Encoding.PEM)\n+                self.keysize = self.key.public_key().key_size\n+        \n         self._from_file = filename  # for debugging\n \n \n@@ -125,12 +157,16 @@ def __init__(self, keyspec):\n         self._private_callable, data = pk11.signer(keyspec)\n         logging.debug(\"Using pkcs11 signing key: {!s}\".format(self._private_callable))\n         if data is not None:\n-            cert = rsa_x509_pem.parse(data)\n-            self.cert_pem = cert.get('pem')\n+            self.key = load_pem_x509_certificate(data, backend=default_backend())\n+            if not isinstance(self.key.public_key(), rsa.RSAPublicKey):\n+                raise XMLSigException(\"We don't support non-RSA public keys at the moment.\")\n+\n+            self.cert_pem = self.key.public_bytes(encoding=serialization.Encoding.PEM)\n+            self.keysize = self.key.public_key().key_size\n \n         self._from_keyspec = keyspec  # for debugging\n \n-    def sign(self, data):\n+    def sign(self, data, hash_alg=None):\n         return self._private_callable(data)\n \n \n@@ -144,7 +180,7 @@ def __init__(self, signature_element, keyspec):\n             fp,_ = _cert_fingerprint(keyspec)\n         cd = _find_cert_by_fingerprint(signature_element, fp)\n         if cd is not None:\n-            data = \"-----BEGIN CERTIFICATE-----\\n%s\\n-----END CERTIFICATE-----\" % cd\n+            data = cd\n             source = 'signature_element'\n         elif '-----BEGIN' in keyspec:\n             data = keyspec\n@@ -153,12 +189,16 @@ def __init__(self, signature_element, keyspec):\n         if data is None:\n             raise ValueError(\"Unable to find cert matching fingerprint: %s\" % fp)\n \n-        super(XMLSecCryptoFromXML, self).__init__(source=source, do_padding=False, private=True)\n+        super(XMLSecCryptoFromXML, self).__init__(source=source, do_padding=False, private=False, do_digest=False)\n+\n+        self.key = load_pem_x509_certificate(data, backend=default_backend())\n+        if not isinstance(self.key.public_key(), rsa.RSAPublicKey):\n+            raise XMLSigException(\"We don't support non-RSA public keys at the moment.\")\n+\n+        # XXX now we could implement encrypted-PEM-support\n+        self.cert_pem = self.key.public_bytes(encoding=serialization.Encoding.PEM)\n \n-        cert = rsa_x509_pem.parse(data)\n-        self.cert_pem = cert.get('pem')\n-        self.key = rsa_x509_pem.get_key(cert)\n-        self.keysize = int(self.key.size()) + 1\n+        self.keysize = self.key.public_key().key_size\n         self._from_keyspec = keyspec  # for debugging\n \n \n@@ -167,7 +207,7 @@ def __init__(self, keyspec):\n         super(XMLSecCryptoREST, self).__init__(source=\"rest\", do_padding=False, private=True)\n         self._keyspec = keyspec\n \n-    def sign(self, data):\n+    def sign(self, data, hash_alg=None):\n         try:\n             import requests\n             import json\n@@ -205,7 +245,7 @@ def _load_keyspec(keyspec, private=False, signature_element=None):\n class CertDict(DictMixin):\n     \"\"\"\n     Extract all X509Certificate XML elements and create a dict-like object\n-    to access the certificates.\n+    to access the certificates as pem strings.\n     \"\"\"\n \n     def __init__(self, t):\n@@ -214,30 +254,49 @@ def __init__(self, t):\n         \"\"\"\n         self.certs = {}\n         for cd in t.findall(\".//{%s}X509Certificate\" % NS['ds']):\n-            fingerprint, cert_pem = _cert_fingerprint(cd.text)\n-            self.certs[fingerprint] = cert_pem\n+            fingerprint, cert = _cert_fingerprint(cd.text)\n+            self.certs[fingerprint] = cert\n \n     def __getitem__(self, item):\n-        return self.certs[item]\n+        return self.certs[item].public_bytes(encoding=serialization.Encoding.PEM)\n \n     def keys(self):\n         return self.certs.keys()\n \n     def __setitem__(self, key, value):\n-        self.certs[key] = value\n+        if isinstance(value, Certificate):\n+            self.certs[key] = value\n+        else:\n+            self.certs[key] = load_pem_x509_certificate(value, backend=default_backend())\n \n     def __delitem__(self, key):\n         del self.certs[key]\n \n+    def _get_cert_by_fp(self, fp):\n+        \"\"\"\n+        Get the cryptography.x509.Certificate representation.\n+\n+        :param fp: A fingerprint in the format \"aa:bb:cc:...\"\n+        :returns: a cryptography.x509.Certificate or None\n+        \"\"\"\n+        try:\n+            c = self.certs[fp]\n+        except KeyError:\n+            return None\n+        \n+        return c\n+\n+\n def _cert_fingerprint(cert_pem):\n     if \"-----BEGIN CERTIFICATE\" in cert_pem:\n-        cert_pem = pem2b64(cert_pem)\n-    cert_der = base64.b64decode(cert_pem)\n-    m = hashlib.sha1()\n-    m.update(cert_der)\n-    fingerprint = m.hexdigest().lower()\n+        cert = load_pem_x509_certificate(cert_pem, backend=default_backend())\n+    else:\n+        cert = load_der_x509_certificate(base64.standard_b64decode(cert_pem), backend=default_backend())\n+\n+    fingerprint = hexlify(cert.fingerprint(hashes.SHA1())).lower()\n     fingerprint = \":\".join([fingerprint[x:x + 2] for x in xrange(0, len(fingerprint), 2)])\n-    return fingerprint, cert_pem\n+    \n+    return fingerprint, cert\n \n \n def _find_cert_by_fingerprint(t, fp):\n@@ -250,7 +309,24 @@ def _find_cert_by_fingerprint(t, fp):\n     \"\"\"\n     if t is None:\n         return None\n-    for cfp, pem in CertDict(t).iteritems():\n-        if fp.lower() == cfp:\n-            return pem\n-    return None\n+\n+    d = CertDict(t)\n+    cert = d._get_cert_by_fp(fp.strip().lower())\n+    \n+    if cert is None:\n+        return None\n+\n+    return cert.public_bytes(encoding=serialization.Encoding.PEM)\n+\n+def _digest(data, hash_alg):\n+    \"\"\"\n+    Calculate a hash digest of algorithm hash_alg and return the result base64 encoded.\n+\n+    :param hash_alg: String with algorithm, such as 'SHA256' (as named by pyca/cryptography)\n+    :param data: The data to digest\n+    :returns: Base64 string\n+    \"\"\"\n+    h = getattr(hashes, hash_alg)\n+    d = hashes.Hash(h(), backend=default_backend())\n+    d.update(data)\n+    return base64.b64encode(d.finalize())\ndiff --git a/src/xmlsec/rsa_x509_pem/Crypto/PublicKey/DSA.py b/src/xmlsec/rsa_x509_pem/Crypto/PublicKey/DSA.py\ndeleted file mode 100755\n--- a/src/xmlsec/rsa_x509_pem/Crypto/PublicKey/DSA.py\n+++ /dev/null\n@@ -1,228 +0,0 @@\n-#\n-#   DSA.py : Digital Signature Algorithm\n-#\n-#  Part of the Python Cryptography Toolkit\n-#\n-# Distribute and use freely; there are no restrictions on further\n-# dissemination and usage except those imposed by the laws of your\n-# country of residence.  This software is provided \"as is\" without\n-# warranty of fitness for use or suitability for any purpose, express\n-# or implied. Use at your own risk or not at all.\n-#\n-\n-__revision__ = \"$Id: DSA.py,v 1.16 2004/05/06 12:52:54 akuchling Exp $\"\n-\n-from . import pubkey\n-from . import number\n-from .number import bytes_to_long, long_to_bytes, isPrime, bignum, inverse\n-from Crypto.Hash import SHA # XXX Crypto.Hash is NOT bundled with xmlsec\n-\n-try:\n-    from . import _fastmath\n-except ImportError:\n-    _fastmath = None\n-\n-\n-def generateQ(randfunc):\n-    S = randfunc(20)\n-    hash1 = SHA.new(S).digest()\n-    hash2 = SHA.new(long_to_bytes(bytes_to_long(S) + 1)).digest()\n-    q = bignum(0)\n-    for i in range(0, 20):\n-        c = ord(hash1[i]) ^ ord(hash2[i])\n-        if i == 0:\n-            c = c | 128\n-        if i == 19:\n-            c = c | 1\n-        q = q * 256 + c\n-    while (not isPrime(q)):\n-        q = q + 2\n-    if pow(2, 159L) < q < pow(2, 160L):\n-        return S, q\n-    raise pubkey.CryptoPubkeyError('Bad q value generated')\n-\n-\n-def generate(bits, randfunc, progress_func=None):\n-    \"\"\"generate(bits:int, randfunc:callable, progress_func:callable)\n-\n-    Generate a DSA key of length 'bits', using 'randfunc' to get\n-    random data and 'progress_func', if present, to display\n-    the progress of the key generation.\n-    \"\"\"\n-\n-    if bits < 160:\n-        raise pubkey.CryptoPubkeyError('Key length <160 bits')\n-    obj = DSAobj()\n-    # Generate string S and prime q\n-    if progress_func:\n-        progress_func('p,q\\n')\n-    while (1):\n-        S, obj.q = generateQ(randfunc)\n-        n = (bits - 1) / 160\n-        C, N, V = 0, 2, {}\n-        b = (obj.q >> 5) & 15\n-        powb = pow(bignum(2), b)\n-        powL1 = pow(bignum(2), bits - 1)\n-        while C < 4096:\n-            for k in range(0, n + 1):\n-                V[k] = bytes_to_long(SHA.new(S + str(N) + str(k)).digest())\n-            W = V[n] % powb\n-            for k in range(n - 1, -1, -1):\n-                W = (W << 160L) + V[k]\n-            X = W + powL1\n-            p = X - (X % (2 * obj.q) - 1)\n-            if powL1 <= p and isPrime(p):\n-                break\n-            C, N = C + 1, N + n + 1\n-        if C < 4096:\n-            break\n-        if progress_func:\n-            progress_func('4096 multiples failed\\n')\n-\n-    obj.p = p\n-    power = (p - 1) / obj.q\n-    if progress_func:\n-        progress_func('h,g\\n')\n-    while (1):\n-        h = bytes_to_long(randfunc(bits)) % (p - 1)\n-        g = pow(h, power, p)\n-        if 1 < h < p - 1 and g > 1:\n-            break\n-    obj.g = g\n-    if progress_func:\n-        progress_func('x,y\\n')\n-    while (1):\n-        x = bytes_to_long(randfunc(20))\n-        if 0 < x < obj.q:\n-            break\n-    obj.x, obj.y = x, pow(g, x, p)\n-    return obj\n-\n-\n-def construct(tuple):\n-    \"\"\"construct(tuple:(long,long,long,long)|(long,long,long,long,long)):DSAobj\n-    Construct a DSA object from a 4- or 5-tuple of numbers.\n-    \"\"\"\n-    return pubkey.construct(tuple, [4, 5], DSAobj())\n-\n-\n-class DSAobj(pubkey.CryptoPubkey):\n-    keydata = ['y', 'g', 'p', 'q', 'x']\n-\n-    def _encrypt(self, s, Kstr):\n-        raise pubkey.CryptoPubkeyError('DSA algorithm cannot encrypt data')\n-\n-    def _decrypt(self, s):\n-        raise pubkey.CryptoPubkeyError('DSA algorithm cannot decrypt data')\n-\n-    def _sign(self, M, K):\n-        if (K < 2 or self.q <= K):\n-            raise pubkey.CryptoPubkeyError('K is not between 2 and q')\n-        r = pow(self.g, K, self.p) % self.q\n-        s = (inverse(K, self.q) * (M + self.x * r)) % self.q\n-        return (r, s)\n-\n-    def _verify(self, M, sig):\n-        r, s = sig\n-        if r <= 0 or r >= self.q or s <= 0 or s >= self.q:\n-            return 0\n-        w = inverse(s, self.q)\n-        u1, u2 = (M * w) % self.q, (r * w) % self.q\n-        v1 = pow(self.g, u1, self.p)\n-        v2 = pow(self.y, u2, self.p)\n-        v = ((v1 * v2) % self.p)\n-        v = v % self.q\n-        if v == r:\n-            return 1\n-        return 0\n-\n-    def size(self):\n-        \"Return the maximum number of bits that can be handled by this key.\"\n-        return number.size(self.p) - 1\n-\n-    def has_private(self):\n-        \"\"\"Return a Boolean denoting whether the object contains\n-        private components.\"\"\"\n-        if hasattr(self, 'x'):\n-            return 1\n-        else:\n-            return 0\n-\n-    def can_sign(self):\n-        \"\"\"Return a Boolean value recording whether this algorithm can generate signatures.\"\"\"\n-        return 1\n-\n-    def can_encrypt(self):\n-        \"\"\"Return a Boolean value recording whether this algorithm can encrypt data.\"\"\"\n-        return 0\n-\n-    def publickey(self):\n-        \"\"\"Return a new key object containing only the public information.\"\"\"\n-        return construct((self.y, self.g, self.p, self.q))\n-\n-\n-object = DSAobj\n-\n-generate_py = generate\n-construct_py = construct\n-\n-\n-class DSAobj_c(pubkey.CryptoPubkey):\n-    keydata = ['y', 'g', 'p', 'q', 'x']\n-\n-    def __init__(self, key):\n-        self.key = key\n-\n-    def __getstate__(self):\n-        d = {}\n-        for k in self.keydata:\n-            if hasattr(self.key, k):\n-                d[k] = getattr(self.key, k)\n-        return d\n-\n-    def __setstate__(self, state):\n-        y, g, p, q = state['y'], state['g'], state['p'], state['q']\n-        if not state.has_key('x'):\n-            self.key = _fastmath.dsa_construct(y, g, p, q)\n-        else:\n-            x = state['x']\n-            self.key = _fastmath.dsa_construct(y, g, p, q, x)\n-\n-    def _sign(self, M, K):\n-        return self.key._sign(M, K)\n-\n-    def _verify(self, M, (r, s)):\n-        return self.key._verify(M, r, s)\n-\n-    def size(self):\n-        return self.key.size()\n-\n-    def has_private(self):\n-        return self.key.has_private()\n-\n-    def publickey(self):\n-        return construct_c((self.key.y, self.key.g, self.key.p, self.key.q))\n-\n-    def can_sign(self):\n-        return 1\n-\n-    def can_encrypt(self):\n-        return 0\n-\n-\n-def generate_c(bits, randfunc, progress_func=None):\n-    obj = generate_py(bits, randfunc, progress_func)\n-    y, g, p, q, x = obj.y, obj.g, obj.p, obj.q, obj.x\n-    return construct_c((y, g, p, q, x))\n-\n-\n-def construct_c(tuple):\n-    key = apply(_fastmath.dsa_construct, tuple)\n-    return DSAobj_c(key)\n-\n-\n-if _fastmath:\n-    #print \"using C version of DSA\"\n-    generate = generate_c\n-    construct = construct_c\n-    error = _fastmath.error\ndiff --git a/src/xmlsec/rsa_x509_pem/Crypto/PublicKey/ElGamal.py b/src/xmlsec/rsa_x509_pem/Crypto/PublicKey/ElGamal.py\ndeleted file mode 100755\n--- a/src/xmlsec/rsa_x509_pem/Crypto/PublicKey/ElGamal.py\n+++ /dev/null\n@@ -1,127 +0,0 @@\n-#\n-#   ElGamal.py : ElGamal encryption/decryption and signatures\n-#\n-#  Part of the Python Cryptography Toolkit\n-#\n-# Distribute and use freely; there are no restrictions on further\n-# dissemination and usage except those imposed by the laws of your\n-# country of residence.  This software is provided \"as is\" without\n-# warranty of fitness for use or suitability for any purpose, express\n-# or implied. Use at your own risk or not at all.\n-#\n-\n-__revision__ = \"$Id: ElGamal.py,v 1.9 2003/04/04 19:44:26 akuchling Exp $\"\n-\n-from . import pubkey\n-from . import number\n-from .number import bignum, getPrime, inverse, GCD\n-\n-\n-# Generate an ElGamal key with N bits\n-def generate(bits, randfunc, progress_func=None):\n-    \"\"\"generate(bits:int, randfunc:callable, progress_func:callable)\n-\n-    Generate an ElGamal key of length 'bits', using 'randfunc' to get\n-    random data and 'progress_func', if present, to display\n-    the progress of the key generation.\n-    \"\"\"\n-    obj = ElGamalobj()\n-    # Generate prime p\n-    if progress_func:\n-        progress_func('p\\n')\n-    obj.p = bignum(getPrime(bits, randfunc))\n-    # Generate random number g\n-    if progress_func:\n-        progress_func('g\\n')\n-    size = bits - 1 - (ord(randfunc(1)) & 63) # g will be from 1--64 bits smaller than p\n-    if size < 1:\n-        size = bits - 1\n-    while (1):\n-        obj.g = bignum(getPrime(size, randfunc))\n-        if obj.g < obj.p:\n-            break\n-        size = (size + 1) % bits\n-        if size == 0:\n-            size = 4\n-        # Generate random number x\n-    if progress_func:\n-        progress_func('x\\n')\n-    while (1):\n-        size = bits - 1 - ord(randfunc(1)) # x will be from 1 to 256 bits smaller than p\n-        if size > 2:\n-            break\n-    while (1):\n-        obj.x = bignum(getPrime(size, randfunc))\n-        if obj.x < obj.p:\n-            break\n-        size = (size + 1) % bits\n-        if size == 0:\n-            size = 4\n-    if progress_func:\n-        progress_func('y\\n')\n-    obj.y = pow(obj.g, obj.x, obj.p)\n-    return obj\n-\n-\n-def construct(tuple):\n-    \"\"\"construct(tuple:(long,long,long,long)|(long,long,long,long,long)))\n-             : ElGamalobj\n-    Construct an ElGamal key from a 3- or 4-tuple of numbers.\n-    \"\"\"\n-    return pubkey.construct(tupe, [3, 4], ElGamalobj())\n-\n-\n-class ElGamalobj(pubkey.CryptoPubkey):\n-    keydata = ['p', 'g', 'y', 'x']\n-\n-    def _encrypt(self, M, K):\n-        a = pow(self.g, K, self.p)\n-        b = ( M * pow(self.y, K, self.p) ) % self.p\n-        return ( a, b )\n-\n-    def _decrypt(self, M):\n-        if (not hasattr(self, 'x')):\n-            raise pubkey.CryptoPubkeyError('Private key not available in this object')\n-        ax = pow(M[0], self.x, self.p)\n-        plaintext = (M[1] * inverse(ax, self.p) ) % self.p\n-        return plaintext\n-\n-    def _sign(self, M, K):\n-        if (not hasattr(self, 'x')):\n-            raise pubkey.CryptoPubkeyError('Private key not available in this object')\n-        p1 = self.p - 1\n-        if (GCD(K, p1) != 1):\n-            raise pubkey.CryptoPubkeyError('Bad K value: GCD(K,p-1)!=1')\n-        a = pow(self.g, K, self.p)\n-        t = (M - self.x * a) % p1\n-        while t < 0:\n-            t = t + p1\n-        b = (t * inverse(K, p1)) % p1\n-        return (a, b)\n-\n-    def _verify(self, M, sig):\n-        v1 = pow(self.y, sig[0], self.p)\n-        v1 = (v1 * pow(sig[0], sig[1], self.p)) % self.p\n-        v2 = pow(self.g, M, self.p)\n-        if v1 == v2:\n-            return 1\n-        return 0\n-\n-    def size(self):\n-        \"Return the maximum number of bits that can be handled by this key.\"\n-        return number.size(self.p) - 1\n-\n-    def has_private(self):\n-        \"\"\"Return a Boolean denoting whether the object contains\n-        private components.\"\"\"\n-        if hasattr(self, 'x'):\n-            return 1\n-        else:\n-            return 0\n-\n-    def publickey(self):\n-        \"\"\"Return a new key object containing only the public information.\"\"\"\n-        return construct((self.p, self.g, self.y))\n-\n-\n-object = ElGamalobj\ndiff --git a/src/xmlsec/rsa_x509_pem/Crypto/PublicKey/RSA.py b/src/xmlsec/rsa_x509_pem/Crypto/PublicKey/RSA.py\ndeleted file mode 100755\n--- a/src/xmlsec/rsa_x509_pem/Crypto/PublicKey/RSA.py\n+++ /dev/null\n@@ -1,247 +0,0 @@\n-#\n-#   RSA.py : RSA encryption/decryption\n-#\n-#  Part of the Python Cryptography Toolkit\n-#\n-# Distribute and use freely; there are no restrictions on further\n-# dissemination and usage except those imposed by the laws of your\n-# country of residence.  This software is provided \"as is\" without\n-# warranty of fitness for use or suitability for any purpose, express\n-# or implied. Use at your own risk or not at all.\n-#\n-\n-__revision__ = \"$Id: RSA.py,v 1.20 2004/05/06 12:52:54 akuchling Exp $\"\n-\n-from . import pubkey\n-from . import number\n-\n-try:\n-    from . import _fastmath\n-except ImportError:\n-    _fastmath = None\n-\n-\n-def generate(bits, randfunc, progress_func=None):\n-    \"\"\"generate(bits:int, randfunc:callable, progress_func:callable)\n-\n-    Generate an RSA key of length 'bits', using 'randfunc' to get\n-    random data and 'progress_func', if present, to display\n-    the progress of the key generation.\n-    \"\"\"\n-    obj = RSAobj()\n-\n-    # Generate the prime factors of n\n-    if progress_func:\n-        progress_func('p,q\\n')\n-    p = q = 1L\n-    while number.size(p * q) < bits:\n-        p = pubkey.getPrime(bits / 2, randfunc)\n-        q = pubkey.getPrime(bits / 2, randfunc)\n-\n-    # p shall be smaller than q (for calc of u)\n-    if p > q:\n-        (p, q) = (q, p)\n-    obj.p = p\n-    obj.q = q\n-\n-    if progress_func:\n-        progress_func('u\\n')\n-    obj.u = pubkey.inverse(obj.p, obj.q)\n-    obj.n = obj.p * obj.q\n-\n-    obj.e = 65537L\n-    if progress_func:\n-        progress_func('d\\n')\n-    obj.d = pubkey.inverse(obj.e, (obj.p - 1) * (obj.q - 1))\n-\n-    assert bits <= 1 + obj.size(), \"Generated key is too small\"\n-\n-    return obj\n-\n-\n-def construct(tuple):\n-    \"\"\"construct(tuple:(long,) : RSAobj\n-    Construct an RSA object from a 2-, 3-, 5-, or 6-tuple of numbers.\n-    \"\"\"\n-    obj = pubkey.construct(tuple, [2, 3, 5, 6], RSAobj())\n-    if len(tuple) >= 5:\n-        # Ensure p is smaller than q\n-        if obj.p > obj.q:\n-            (obj.p, obj.q) = (obj.q, obj.p)\n-\n-    if len(tuple) == 5:\n-        # u not supplied, so we're going to have to compute it.\n-        obj.u = pubkey.inverse(obj.p, obj.q)\n-\n-    return obj\n-\n-\n-class RSAobj(pubkey.CryptoPubkey):\n-    keydata = ['n', 'e', 'd', 'p', 'q', 'u']\n-\n-    def _encrypt(self, plaintext, K=''):\n-        if self.n <= plaintext:\n-            raise pubkey.CryptoPubkeyError('Plaintext too large')\n-        return (pow(plaintext, self.e, self.n),)\n-\n-    def _decrypt(self, ciphertext):\n-        if (not hasattr(self, 'd')):\n-            raise pubkey.CryptoPubkeyError('Private key not available in this object')\n-        if self.n <= ciphertext[0]:\n-            raise pubkey.CryptoPubkeyError('Ciphertext too large')\n-        return pow(ciphertext[0], self.d, self.n)\n-\n-    def _sign(self, M, K=''):\n-        return (self._decrypt((M,)),)\n-\n-    def _verify(self, M, sig):\n-        m2 = self._encrypt(sig[0])\n-        if m2[0] == M:\n-            return 1\n-        else:\n-            return 0\n-\n-    def _blind(self, M, B):\n-        tmp = pow(B, self.e, self.n)\n-        return (M * tmp) % self.n\n-\n-    def _unblind(self, M, B):\n-        tmp = pubkey.inverse(B, self.n)\n-        return (M * tmp) % self.n\n-\n-    def can_blind(self):\n-        \"\"\"can_blind() : bool\n-        Return a Boolean value recording whether this algorithm can\n-        blind data.  (This does not imply that this\n-        particular key object has the private information required to\n-        to blind a message.)\n-        \"\"\"\n-        return 1\n-\n-    def size(self):\n-        \"\"\"size() : int\n-        Return the maximum number of bits that can be handled by this key.\n-        \"\"\"\n-        return number.size(self.n) - 1\n-\n-    def has_private(self):\n-        \"\"\"has_private() : bool\n-        Return a Boolean denoting whether the object contains\n-        private components.\n-        \"\"\"\n-        if hasattr(self, 'd'):\n-            return 1\n-        else:\n-            return 0\n-\n-    def publickey(self):\n-        \"\"\"publickey(): RSAobj\n-        Return a new key object containing only the public key information.\n-        \"\"\"\n-        return construct((self.n, self.e))\n-\n-\n-class RSAobj_c(pubkey.CryptoPubkey):\n-    keydata = ['n', 'e', 'd', 'p', 'q', 'u']\n-\n-    def __init__(self, key):\n-        self.key = key\n-\n-    def __getstate__(self):\n-        d = {}\n-        for k in self.keydata:\n-            if hasattr(self.key, k):\n-                d[k] = getattr(self.key, k)\n-        return d\n-\n-    def __setstate__(self, state):\n-        n, e = state['n'], state['e']\n-        if not state.has_key('d'):\n-            self.key = _fastmath.rsa_construct(n, e)\n-        else:\n-            d = state['d']\n-            if not state.has_key('q'):\n-                self.key = _fastmath.rsa_construct(n, e, d)\n-            else:\n-                p, q, u = state['p'], state['q'], state['u']\n-                self.key = _fastmath.rsa_construct(n, e, d, p, q, u)\n-\n-    def _encrypt(self, plain, K):\n-        return (self.key._encrypt(plain),)\n-\n-    def _decrypt(self, cipher):\n-        return self.key._decrypt(cipher[0])\n-\n-    def _sign(self, M, K):\n-        return (self.key._sign(M),)\n-\n-    def _verify(self, M, sig):\n-        return self.key._verify(M, sig[0])\n-\n-    def _blind(self, M, B):\n-        return self.key._blind(M, B)\n-\n-    def _unblind(self, M, B):\n-        return self.key._unblind(M, B)\n-\n-    def can_blind(self):\n-        return 1\n-\n-    def size(self):\n-        return self.key.size()\n-\n-    def has_private(self):\n-        return self.key.has_private()\n-\n-    def publickey(self):\n-        return construct_c((self.key.n, self.key.e))\n-\n-\n-def generate_c(bits, randfunc, progress_func=None):\n-    # Generate the prime factors of n\n-    if progress_func:\n-        progress_func('p,q\\n')\n-\n-    p = q = 1L\n-    while number.size(p * q) < bits:\n-        p = pubkey.getPrime(bits / 2, randfunc)\n-        q = pubkey.getPrime(bits / 2, randfunc)\n-\n-    # p shall be smaller than q (for calc of u)\n-    if p > q:\n-        (p, q) = (q, p)\n-    if progress_func:\n-        progress_func('u\\n')\n-    u = pubkey.inverse(p, q)\n-    n = p * q\n-\n-    e = 65537L\n-    if progress_func:\n-        progress_func('d\\n')\n-    d = pubkey.inverse(e, (p - 1) * (q - 1))\n-    key = _fastmath.rsa_construct(n, e, d, p, q, u)\n-    obj = RSAobj_c(key)\n-\n-    ##    print p\n-    ##    print q\n-    ##    print number.size(p), number.size(q), number.size(q*p),\n-    ##    print obj.size(), bits\n-    assert bits <= 1 + obj.size(), \"Generated key is too small\"\n-    return obj\n-\n-\n-def construct_c(tuple):\n-    key = apply(_fastmath.rsa_construct, tuple)\n-    return RSAobj_c(key)\n-\n-\n-object = RSAobj\n-\n-generate_py = generate\n-construct_py = construct\n-\n-if _fastmath:\n-    #print \"using C version of RSA\"\n-    generate = generate_c\n-    construct = construct_c\n-    error = _fastmath.error\ndiff --git a/src/xmlsec/rsa_x509_pem/Crypto/PublicKey/__init__.py b/src/xmlsec/rsa_x509_pem/Crypto/PublicKey/__init__.py\ndeleted file mode 100755\n--- a/src/xmlsec/rsa_x509_pem/Crypto/PublicKey/__init__.py\n+++ /dev/null\n@@ -1,17 +0,0 @@\n-\"\"\"Public-key encryption and signature algorithms.\n-\n-Public-key encryption uses two different keys, one for encryption and\n-one for decryption.  The encryption key can be made public, and the\n-decryption key is kept private.  Many public-key algorithms can also\n-be used to sign messages, and some can *only* be used for signatures.\n-\n-Crypto.PublicKey.DSA      Digital Signature Algorithm. (Signature only)\n-Crypto.PublicKey.ElGamal  (Signing and encryption)\n-Crypto.PublicKey.RSA      (Signing, encryption, and blinding)\n-Crypto.PublicKey.qNEW     (Signature only)\n-\n-\"\"\"\n-\n-__all__ = ['RSA', 'DSA', 'ElGamal', 'qNEW']\n-__revision__ = \"$Id: __init__.py,v 1.4 2003/04/03 20:27:13 akuchling Exp $\"\n-\ndiff --git a/src/xmlsec/rsa_x509_pem/Crypto/PublicKey/number.py b/src/xmlsec/rsa_x509_pem/Crypto/PublicKey/number.py\ndeleted file mode 100755\n--- a/src/xmlsec/rsa_x509_pem/Crypto/PublicKey/number.py\n+++ /dev/null\n@@ -1,214 +0,0 @@\n-#\n-#   number.py : Number-theoretic functions\n-#\n-#  Part of the Python Cryptography Toolkit\n-#\n-# Distribute and use freely; there are no restrictions on further\n-# dissemination and usage except those imposed by the laws of your\n-# country of residence.  This software is provided \"as is\" without\n-# warranty of fitness for use or suitability for any purpose, express\n-# or implied. Use at your own risk or not at all.\n-#\n-\n-__revision__ = \"$Id: number.py,v 1.13 2003/04/04 18:21:07 akuchling Exp $\"\n-\n-bignum = long\n-try:\n-    from Crypto.PublicKey import _fastmath\n-except ImportError:\n-    _fastmath = None\n-\n-# Commented out and replaced with faster versions below\n-## def long2str(n):\n-##     s=''\n-##     while n>0:\n-##         s=chr(n & 255)+s\n-##         n=n>>8\n-##     return s\n-\n-## import types\n-## def str2long(s):\n-##     if type(s)!=types.StringType: return s   # Integers will be left alone\n-##     return reduce(lambda x,y : x*256+ord(y), s, 0L)\n-\n-def size(N):\n-    \"\"\"size(N:long) : int\n-    Returns the size of the number N in bits.\n-    \"\"\"\n-    bits, power = 0, 1L\n-    while N >= power:\n-        bits += 1\n-        power = power << 1\n-    return bits\n-\n-\n-def getRandomNumber(N, randfunc):\n-    \"\"\"getRandomNumber(N:int, randfunc:callable):long\n-    Return an N-bit random number.\"\"\"\n-\n-    S = randfunc(N / 8)\n-    odd_bits = N % 8\n-    if odd_bits != 0:\n-        char = ord(randfunc(1)) >> (8 - odd_bits)\n-        S = chr(char) + S\n-    value = bytes_to_long(S)\n-    value |= 2L ** (N - 1)                # Ensure high bit is set\n-    assert size(value) >= N\n-    return value\n-\n-\n-def GCD(x, y):\n-    \"\"\"GCD(x:long, y:long): long\n-    Return the GCD of x and y.\n-    \"\"\"\n-    x = abs(x)\n-    y = abs(y)\n-    while x > 0:\n-        x, y = y % x, x\n-    return y\n-\n-\n-def inverse(u, v):\n-    \"\"\"inverse(u:long, u:long):long\n-    Return the inverse of u mod v.\n-    \"\"\"\n-    u3, v3 = long(u), long(v)\n-    u1, v1 = 1L, 0L\n-    while v3 > 0:\n-        q = u3 / v3\n-        u1, v1 = v1, u1 - v1 * q\n-        u3, v3 = v3, u3 - v3 * q\n-    while u1 < 0:\n-        u1 = u1 + v\n-    return u1\n-\n-# Given a number of bits to generate and a random generation function,\n-# find a prime number of the appropriate size.\n-\n-def getPrime(N, randfunc):\n-    \"\"\"getPrime(N:int, randfunc:callable):long\n-    Return a random N-bit prime number.\n-    \"\"\"\n-\n-    number = getRandomNumber(N, randfunc) | 1\n-    while (not isPrime(number)):\n-        number = number + 2\n-    return number\n-\n-\n-def isPrime(N):\n-    \"\"\"isPrime(N:long):bool\n-    Return true if N is prime.\n-    \"\"\"\n-    if N == 1:\n-        return 0\n-    if N in sieve:\n-        return 1\n-    for i in sieve:\n-        if (N % i) == 0:\n-            return 0\n-\n-    # Use the accelerator if available\n-    if _fastmath is not None:\n-        return _fastmath.isPrime(N)\n-\n-    # Compute the highest bit that's set in N\n-    N1 = N - 1L\n-    n = 1L\n-    while (n < N):\n-        n = n << 1L\n-    n = n >> 1L\n-\n-    # Rabin-Miller test\n-    for c in sieve[:7]:\n-        a = long(c)\n-        d = 1L\n-        t = n\n-        while (t):  # Iterate over the bits in N1\n-            x = (d * d) % N\n-            if x == 1L and d != 1L and d != N1:\n-                return 0  # Square root of 1 found\n-            if N1 & t:\n-                d = (x * a) % N\n-            else:\n-                d = x\n-            t = t >> 1L\n-        if d != 1L:\n-            return 0\n-    return 1\n-\n-# Small primes used for checking primality; these are all the primes\n-# less than 256.  This should be enough to eliminate most of the odd\n-# numbers before needing to do a Rabin-Miller test at all.\n-\n-sieve = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59,\n-         61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127,\n-         131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193,\n-         197, 199, 211, 223, 227, 229, 233, 239, 241, 251]\n-\n-# Improved conversion functions contributed by Barry Warsaw, after\n-# careful benchmarking\n-\n-import struct\n-\n-\n-def long_to_bytes(n, blocksize=0):\n-    \"\"\"long_to_bytes(n:long, blocksize:int) : string\n-    Convert a long integer to a byte string.\n-\n-    If optional blocksize is given and greater than zero, pad the front of the\n-    byte string with binary zeros so that the length is a multiple of\n-    blocksize.\n-    \"\"\"\n-    # after much testing, this algorithm was deemed to be the fastest\n-    s = ''\n-    n = long(n)\n-    pack = struct.pack\n-    while n > 0:\n-        s = pack('>I', n & 0xffffffffL) + s\n-        n = n >> 32\n-        # strip off leading zeros\n-    for i in range(len(s)):\n-        if s[i] != '\\000':\n-            break\n-    else:\n-        # only happens when n == 0\n-        s = '\\000'\n-        i = 0\n-    s = s[i:]\n-    # add back some pad bytes.  this could be done more efficiently w.r.t. the\n-    # de-padding being done above, but sigh...\n-    if blocksize > 0 and len(s) % blocksize:\n-        s = (blocksize - len(s) % blocksize) * '\\000' + s\n-    return s\n-\n-\n-def bytes_to_long(s):\n-    \"\"\"bytes_to_long(string) : long\n-    Convert a byte string to a long integer.\n-\n-    This is (essentially) the inverse of long_to_bytes().\n-    \"\"\"\n-    acc = 0L\n-    unpack = struct.unpack\n-    length = len(s)\n-    if length % 4:\n-        extra = (4 - length % 4)\n-        s = '\\000' * extra + s\n-        length = length + extra\n-    for i in range(0, length, 4):\n-        acc = (acc << 32) + unpack('>I', s[i:i + 4])[0]\n-    return acc\n-\n-# For backwards compatibility...\n-import warnings\n-\n-\n-def long2str(n, blocksize=0):\n-    warnings.warn(\"long2str() has been replaced by long_to_bytes()\")\n-    return long_to_bytes(n, blocksize)\n-\n-\n-def str2long(s):\n-    warnings.warn(\"str2long() has been replaced by bytes_to_long()\")\n-    return bytes_to_long(s)\ndiff --git a/src/xmlsec/rsa_x509_pem/Crypto/PublicKey/pubkey.py b/src/xmlsec/rsa_x509_pem/Crypto/PublicKey/pubkey.py\ndeleted file mode 100755\n--- a/src/xmlsec/rsa_x509_pem/Crypto/PublicKey/pubkey.py\n+++ /dev/null\n@@ -1,226 +0,0 @@\n-#\n-#   pubkey.py : Internal functions for public key operations\n-#\n-#  Part of the Python Cryptography Toolkit\n-#\n-# Distribute and use freely; there are no restrictions on further\n-# dissemination and usage except those imposed by the laws of your\n-# country of residence.  This software is provided \"as is\" without\n-# warranty of fitness for use or suitability for any purpose, express\n-# or implied. Use at your own risk or not at all.\n-#\n-\n-__revision__ = \"$Id: pubkey.py,v 1.11 2003/04/03 20:36:14 akuchling Exp $\"\n-\n-import types, warnings\n-from .number import bignum, bytes_to_long, long_to_bytes, getPrime, inverse\n-\n-class CryptoPubkeyError(Exception):\n-    pass\n-\n-\n-def construct(tuple, sizes, obj):\n-    if len(tuple) not in sizes:\n-        raise pubkey.CryptoPubkeyError('argument for construct() wrong length')\n-    for i in range(len(tuple)):\n-        field = obj.keydata[i]\n-        setattr(obj, field, tuple[i])\n-    return obj\n-\n-\n-# Basic public key class\n-class CryptoPubkey:\n-    def __init__(self):\n-        pass\n-\n-    def __getattr__(self, attr):\n-        if attr in self.keydata:\n-            return getattr(self.key, attr)\n-        else:\n-            if self.__dict__.has_key(attr):\n-                self.__dict__[attr]\n-            else:\n-                raise AttributeError('%s instance has no attribute %s' % (self.__class__, attr))\n-\n-    def __getstate__(self):\n-        \"\"\"To keep key objects platform-independent, the key data is\n-        converted to standard Python long integers before being\n-        written out.  It will then be reconverted as necessary on\n-        restoration.\"\"\"\n-        d = self.__dict__\n-        for key in self.keydata:\n-            if d.has_key(key):\n-                d[key] = long(d[key])\n-        return d\n-\n-    def __setstate__(self, d):\n-        \"\"\"On unpickling a key object, the key data is converted to the big\n-number representation being used, whether that is Python long\n-integers, MPZ objects, or whatever.\"\"\"\n-        for key in self.keydata:\n-            if d.has_key(key):\n-                self.__dict__[key] = bignum(d[key])\n-\n-    def _encrypt(self, _plaintext, _K):\n-        raise NotImplementedError(\"Subclass should implement _encrypt\")\n-    def _decrypt(self, _ciphertext):\n-        raise NotImplementedError(\"Subclass should implement _decrypt\")\n-    def _sign(self, _M, _K):\n-        raise NotImplementedError(\"Subclass should implement _sign\")\n-    def _verify(self, _M, _signature):\n-        raise NotImplementedError(\"Subclass should implement _verify\")\n-    def _blind(self, _M, _B):\n-        raise NotImplementedError(\"Subclass should implement _blind\")\n-    def _unblind(self, _M, _B):\n-        raise NotImplementedError(\"Subclass should implement _unblind\")\n-\n-    def encrypt(self, plaintext, K):\n-        \"\"\"encrypt(plaintext:string|long, K:string|long) : tuple\n-        Encrypt the string or integer plaintext.  K is a random\n-        parameter required by some algorithms.\n-        \"\"\"\n-        wasString = 0\n-        if isinstance(plaintext, types.StringType):\n-            plaintext = bytes_to_long(plaintext)\n-            wasString = 1\n-        if isinstance(K, types.StringType):\n-            K = bytes_to_long(K)\n-        ciphertext = self._encrypt(plaintext, K)\n-        if wasString:\n-            return tuple(map(long_to_bytes, ciphertext))\n-        else:\n-            return ciphertext\n-\n-    def decrypt(self, ciphertext):\n-        \"\"\"decrypt(ciphertext:tuple|string|long): string\n-        Decrypt 'ciphertext' using this key.\n-        \"\"\"\n-        wasString = 0\n-        if not isinstance(ciphertext, types.TupleType):\n-            ciphertext = (ciphertext,)\n-        if isinstance(ciphertext[0], types.StringType):\n-            ciphertext = tuple(map(bytes_to_long, ciphertext))\n-            wasString = 1\n-        plaintext = self._decrypt(ciphertext)\n-        if wasString:\n-            return long_to_bytes(plaintext)\n-        else:\n-            return plaintext\n-\n-    def sign(self, M, K):\n-        \"\"\"sign(M : string|long, K:string|long) : tuple\n-        Return a tuple containing the signature for the message M.\n-        K is a random parameter required by some algorithms.\n-        \"\"\"\n-        if (not self.has_private()):\n-            raise CryptoPubkeyError('Private key not available in this object')\n-        if isinstance(M, types.StringType):\n-            M = bytes_to_long(M)\n-        if isinstance(K, types.StringType):\n-            K = bytes_to_long(K)\n-        return self._sign(M, K)\n-\n-    def verify(self, M, signature):\n-        \"\"\"verify(M:string|long, signature:tuple) : bool\n-        Verify that the signature is valid for the message M;\n-        returns true if the signature checks out.\n-        \"\"\"\n-        if isinstance(M, types.StringType):\n-            M = bytes_to_long(M)\n-        return self._verify(M, signature)\n-\n-    # alias to compensate for the old validate() name\n-    def validate(self, M, signature):\n-        warnings.warn(\"validate() method name is obsolete; use verify()\",\n-                      DeprecationWarning)\n-\n-    def blind(self, M, B):\n-        \"\"\"blind(M : string|long, B : string|long) : string|long\n-        Blind message M using blinding factor B.\n-        \"\"\"\n-        wasString = 0\n-        if isinstance(M, types.StringType):\n-            M = bytes_to_long(M)\n-            wasString = 1\n-        if isinstance(B, types.StringType):\n-            B = bytes_to_long(B)\n-        blindedmessage = self._blind(M, B)\n-        if wasString:\n-            return long_to_bytes(blindedmessage)\n-        else:\n-            return blindedmessage\n-\n-    def unblind(self, M, B):\n-        \"\"\"unblind(M : string|long, B : string|long) : string|long\n-        Unblind message M using blinding factor B.\n-        \"\"\"\n-        wasString = 0\n-        if isinstance(M, types.StringType):\n-            M = bytes_to_long(M)\n-            wasString = 1\n-        if isinstance(B, types.StringType):\n-            B = bytes_to_long(B)\n-        unblindedmessage = self._unblind(M, B)\n-        if wasString:\n-            return long_to_bytes(unblindedmessage)\n-        else:\n-            return unblindedmessage\n-\n-\n-    # The following methods will usually be left alone, except for\n-    # signature-only algorithms.  They both return Boolean values\n-    # recording whether this key's algorithm can sign and encrypt.\n-    def can_sign(self):\n-        \"\"\"can_sign() : bool\n-        Return a Boolean value recording whether this algorithm can\n-        generate signatures.  (This does not imply that this\n-        particular key object has the private information required to\n-        to generate a signature.)\n-        \"\"\"\n-        return 1\n-\n-    def can_encrypt(self):\n-        \"\"\"can_encrypt() : bool\n-        Return a Boolean value recording whether this algorithm can\n-        encrypt data.  (This does not imply that this\n-        particular key object has the private information required to\n-        to decrypt a message.)\n-        \"\"\"\n-        return 1\n-\n-    def can_blind(self):\n-        \"\"\"can_blind() : bool\n-        Return a Boolean value recording whether this algorithm can\n-        blind data.  (This does not imply that this\n-        particular key object has the private information required to\n-        to blind a message.)\n-        \"\"\"\n-        return 0\n-\n-    # The following methods will certainly be overridden by\n-    # subclasses.\n-\n-    def size(self):\n-        \"\"\"size() : int\n-        Return the maximum number of bits that can be handled by this key.\n-        \"\"\"\n-        return 0\n-\n-    def has_private(self):\n-        \"\"\"has_private() : bool\n-        Return a Boolean denoting whether the object contains\n-        private components.\n-        \"\"\"\n-        return 0\n-\n-    def publickey(self):\n-        \"\"\"publickey(): object\n-        Return a new key object containing only the public information.\n-        \"\"\"\n-        return self\n-\n-    def __eq__(self, other):\n-        \"\"\"__eq__(other): 0, 1\n-        Compare us to other for equality.\n-        \"\"\"\n-        return self.__getstate__() == other.__getstate__()\ndiff --git a/src/xmlsec/rsa_x509_pem/Crypto/PublicKey/qNEW.py b/src/xmlsec/rsa_x509_pem/Crypto/PublicKey/qNEW.py\ndeleted file mode 100755\n--- a/src/xmlsec/rsa_x509_pem/Crypto/PublicKey/qNEW.py\n+++ /dev/null\n@@ -1,167 +0,0 @@\n-#\n-#   qNEW.py : The q-NEW signature algorithm.\n-#\n-#  Part of the Python Cryptography Toolkit\n-#\n-# Distribute and use freely; there are no restrictions on further\n-# dissemination and usage except those imposed by the laws of your\n-# country of residence.    This software is provided \"as is\" without\n-# warranty of fitness for use or suitability for any purpose, express\n-# or implied. Use at your own risk or not at all.\n-#\n-\n-__revision__ = \"$Id: qNEW.py,v 1.8 2003/04/04 15:13:35 akuchling Exp $\"\n-\n-from . import pubkey\n-from .number import bytes_to_long, long_to_bytes, getPrime, isPrime\n-from Crypto.Hash import SHA # XXX Crypto.Hash is NOT bundled with xmlsec\n-\n-\n-HASHBITS = 160   # Size of SHA digests\n-\n-\n-def generate(bits, randfunc, progress_func=None):\n-    \"\"\"generate(bits:int, randfunc:callable, progress_func:callable)\n-\n-    Generate a qNEW key of length 'bits', using 'randfunc' to get\n-    random data and 'progress_func', if present, to display\n-    the progress of the key generation.\n-    \"\"\"\n-    obj = qNEWobj()\n-\n-    # Generate prime numbers p and q.  q is a 160-bit prime\n-    # number.  p is another prime number (the modulus) whose bit\n-    # size is chosen by the caller, and is generated so that p-1\n-    # is a multiple of q.\n-    #\n-    # Note that only a single seed is used to\n-    # generate p and q; if someone generates a key for you, you can\n-    # use the seed to duplicate the key generation.  This can\n-    # protect you from someone generating values of p,q that have\n-    # some special form that's easy to break.\n-    if progress_func:\n-        progress_func('p,q\\n')\n-    while (1):\n-        obj.q = getPrime(160, randfunc)\n-        #           assert pow(2, 159L)<obj.q<pow(2, 160L)\n-        obj.seed = S = long_to_bytes(obj.q)\n-        C, N, V = 0, 2, {}\n-        # Compute b and n such that bits-1 = b + n*HASHBITS\n-        n = (bits - 1) / HASHBITS\n-        b = (bits - 1) % HASHBITS\n-        powb = 2L << b\n-        powL1 = pow(long(2), bits - 1)\n-        while C < 4096:\n-            # The V array will contain (bits-1) bits of random\n-            # data, that are assembled to produce a candidate\n-            # value for p.\n-            for k in range(0, n + 1):\n-                V[k] = bytes_to_long(SHA.new(S + str(N) + str(k)).digest())\n-            p = V[n] % powb\n-            for k in range(n - 1, -1, -1):\n-                p = (p << long(HASHBITS) ) + V[k]\n-            p = p + powL1         # Ensure the high bit is set\n-\n-            # Ensure that p-1 is a multiple of q\n-            p = p - (p % (2 * obj.q) - 1)\n-\n-            # If p is still the right size, and it's prime, we're done!\n-            if powL1 <= p and isPrime(p):\n-                break\n-\n-            # Otherwise, increment the counter and try again\n-            C, N = C + 1, N + n + 1\n-        if C < 4096:\n-            break   # Ended early, so exit the while loop\n-        if progress_func:\n-            progress_func('4096 values of p tried\\n')\n-\n-    obj.p = p\n-    power = (p - 1) / obj.q\n-\n-    # Next parameter: g = h**((p-1)/q) mod p, such that h is any\n-    # number <p-1, and g>1.  g is kept; h can be discarded.\n-    if progress_func:\n-        progress_func('h,g\\n')\n-    while (1):\n-        h = bytes_to_long(randfunc(bits)) % (p - 1)\n-        g = pow(h, power, p)\n-        if 1 < h < p - 1 and g > 1:\n-            break\n-    obj.g = g\n-\n-    # x is the private key information, and is\n-    # just a random number between 0 and q.\n-    # y=g**x mod p, and is part of the public information.\n-    if progress_func:\n-        progress_func('x,y\\n')\n-    while (1):\n-        x = bytes_to_long(randfunc(20))\n-        if 0 < x < obj.q:\n-            break\n-    obj.x, obj.y = x, pow(g, x, p)\n-\n-    return obj\n-\n-# Construct a qNEW object\n-def construct(tuple):\n-    \"\"\"construct(tuple:(long,long,long,long)|(long,long,long,long,long)\n-    Construct a qNEW object from a 4- or 5-tuple of numbers.\n-    \"\"\"\n-    return pubkey.construct(tuple, [4, 5], qNEWobj())\n-\n-\n-class qNEWobj(pubkey.CryptoPubkey):\n-    keydata = ['p', 'q', 'g', 'y', 'x']\n-\n-    def _sign(self, M, K=''):\n-        if (self.q <= K):\n-            raise pubkey.CryptoPubkeyError('K is greater than q')\n-        if M < 0:\n-            raise pubkey.CryptoPubkeyError('Illegal value of M (<0)')\n-        if M >= pow(2, 161L):\n-            raise pubkey.CryptoPubkeyError('Illegal value of M (too large)')\n-        r = pow(self.g, K, self.p) % self.q\n-        s = (K - (r * M * self.x % self.q)) % self.q\n-        return (r, s)\n-\n-    def _verify(self, M, sig):\n-        r, s = sig\n-        if r <= 0 or r >= self.q or s <= 0 or s >= self.q:\n-            return 0\n-        if M < 0:\n-            raise pubkey.CryptoPubkeyError('Illegal value of M (<0)')\n-        if M <= 0 or M >= pow(2, 161L):\n-            return 0\n-        v1 = pow(self.g, s, self.p)\n-        v2 = pow(self.y, M * r, self.p)\n-        v = ((v1 * v2) % self.p)\n-        v = v % self.q\n-        if v == r:\n-            return 1\n-        return 0\n-\n-    def size(self):\n-        \"Return the maximum number of bits that can be handled by this key.\"\n-        return 160\n-\n-    def has_private(self):\n-        \"\"\"Return a Boolean denoting whether the object contains\n-        private components.\"\"\"\n-        return hasattr(self, 'x')\n-\n-    def can_sign(self):\n-        \"\"\"Return a Boolean value recording whether this algorithm can generate signatures.\"\"\"\n-        return 1\n-\n-    def can_encrypt(self):\n-        \"\"\"Return a Boolean value recording whether this algorithm can encrypt data.\"\"\"\n-        return 0\n-\n-    def publickey(self):\n-        \"\"\"Return a new key object containing only the public information.\"\"\"\n-        return construct((self.p, self.q, self.g, self.y))\n-\n-\n-object = qNEWobj\n-\ndiff --git a/src/xmlsec/rsa_x509_pem/Crypto/__init__.py b/src/xmlsec/rsa_x509_pem/Crypto/__init__.py\ndeleted file mode 100755\n--- a/src/xmlsec/rsa_x509_pem/Crypto/__init__.py\n+++ /dev/null\n@@ -1,25 +0,0 @@\n-\n-\"\"\"Python Cryptography Toolkit\n-\n-A collection of cryptographic modules implementing various algorithms\n-and protocols.\n-\n-Subpackages:\n-Crypto.Cipher             Secret-key encryption algorithms (AES, DES, ARC4)\n-Crypto.Hash               Hashing algorithms (MD5, SHA, HMAC)\n-Crypto.Protocol           Cryptographic protocols (Chaffing, all-or-nothing\n-                          transform).   This package does not contain any\n-                          network protocols.\n-Crypto.PublicKey          Public-key encryption and signature algorithms\n-                          (RSA, DSA)\n-Crypto.Util               Various useful modules and functions (long-to-string\n-                          conversion, random number generation, number\n-                          theoretic functions)\n-\"\"\"\n-\n-__all__ = ['Cipher', 'Hash', 'Protocol', 'PublicKey', 'Util']\n-\n-__version__ = '2.0.1'\n-__revision__ = \"$Id: __init__.py,v 1.12 2005/06/14 01:20:22 akuchling Exp $\"\n-\n-\ndiff --git a/src/xmlsec/rsa_x509_pem/__init__.py b/src/xmlsec/rsa_x509_pem/__init__.py\ndeleted file mode 100644\n--- a/src/xmlsec/rsa_x509_pem/__init__.py\n+++ /dev/null\n@@ -1,87 +0,0 @@\n-#!/usr/bin/python\n-# -*- coding: utf-8 -*-\n-# Copyright \u00a92011 Andrew D Yates\n-# andrewyates.name@gmail.com\n-#\n-# Modified and redistributed as part of pyXMLSecurity by leifj@mnt.se\n-# with permission from the original author\n-#\n-\"\"\"Package module into well organized interface.\n-\"\"\"\n-from .Crypto.PublicKey import RSA\n-from .Crypto.PublicKey.number import bytes_to_long as btl\n-from .Crypto.PublicKey.number import long_to_bytes as ltb\n-from . import rsa_pem\n-from . import x509_pem\n-\n-# *_parse accepts file data to be parsed as a single parameter\n-# >>> key_dict = rsa_parse(open(\"my_key.pem\").read())\n-# ... cert_dict = cert_parse(open(\"my_cert.pem\").read())\n-rsa_parse = rsa_pem.parse\n-x509_parse = x509_pem.parse\n-\n-RSAKey = RSA.RSAobj\n-\n-\n-def parse(data):\n-    \"\"\"Return parsed dictionary from parsed PEM file; based on header.\n-\n-  Args:\n-    data: str of PEM file data\n-  Returns:\n-    {str:str} as returned from appropriate *_parse parser\n-  \"\"\"\n-    if \"RSA PRIVATE\" in data:\n-        pdict = rsa_pem.parse(data)\n-    elif \"CERTIFICATE\" in data:\n-        pdict = x509_pem.parse(data)\n-    else:\n-        raise Exception(\"PEM data type not supported.\")\n-    return pdict\n-\n-\n-def get_key(parse_dict):\n-    \"\"\"Return RSA object from parsed PEM key file dictionary.\n-\n-  Args:\n-    parse_dict: {str:str} as returned by `parse`\n-  Returns:\n-    `RSAKey` RSA key object as specified by `parse_dict`\n-  \"\"\"\n-    if parse_dict['type'] == \"RSA PRIVATE\":\n-        key_tuple = rsa_pem.dict_to_tuple(parse_dict)\n-    elif parse_dict['type'] == \"X509 CERTIFICATE\":\n-        key_tuple = x509_pem.dict_to_tuple(parse_dict)\n-    else:\n-        raise Exception(\"parse_dict type '%s' not supported.\" % parse_dict['type'])\n-    key = RSA.construct(key_tuple)\n-    return key\n-\n-\n-def f_public(key):\n-    \"\"\"Return a convenient public key function.\n-\n-  Args:\n-    key: `RSAKey` as returned by get_key(parse_dict).\n-  Returns:\n-    function(msg) => str of RSA() using `key`\n-  \"\"\"\n-    return lambda x: key.encrypt(x, None)[0]\n-\n-\n-def f_private(key):\n-    \"\"\"Return a convenient public key function.\n-\n-  Args:\n-    key: `RSAKey` as returned by get_key(parse_dict).\n-  Returns:\n-    function(msg) => str of RSA^-1() using `key`\n-  \"\"\"\n-    return key.decrypt\n-\n-def f_sign(key):\n-    b_len = (key.size() + 1)/8\n-    def _sign(msg):\n-       (sig,) = key.sign(btl(msg),None)\n-       return ltb(sig,b_len)\n-    return _sign\ndiff --git a/src/xmlsec/rsa_x509_pem/pyasn1/__init__.py b/src/xmlsec/rsa_x509_pem/pyasn1/__init__.py\ndeleted file mode 100644\n--- a/src/xmlsec/rsa_x509_pem/pyasn1/__init__.py\n+++ /dev/null\n@@ -1 +0,0 @@\n-majorVersionId = '1'\ndiff --git a/src/xmlsec/rsa_x509_pem/pyasn1/codec/__init__.py b/src/xmlsec/rsa_x509_pem/pyasn1/codec/__init__.py\ndeleted file mode 100644\ndiff --git a/src/xmlsec/rsa_x509_pem/pyasn1/codec/ber/__init__.py b/src/xmlsec/rsa_x509_pem/pyasn1/codec/ber/__init__.py\ndeleted file mode 100644\ndiff --git a/src/xmlsec/rsa_x509_pem/pyasn1/codec/ber/decoder.py b/src/xmlsec/rsa_x509_pem/pyasn1/codec/ber/decoder.py\ndeleted file mode 100644\n--- a/src/xmlsec/rsa_x509_pem/pyasn1/codec/ber/decoder.py\n+++ /dev/null\n@@ -1,572 +0,0 @@\n-# BER decoder\n-import types\n-from ...type import tag, univ, char, useful\n-from ..ber import eoo\n-from ... import error\n-\n-\n-class AbstractDecoder:\n-    protoComponent = None\n-\n-    def _createComponent(self, tagSet, asn1Spec):\n-        if asn1Spec is None:\n-            return self.protoComponent.clone(tagSet=tagSet)\n-        else:\n-            return asn1Spec.clone()\n-\n-    def valueDecoder(self, substrate, asn1Spec, tagSet,\n-                     length, state, decodeFun):\n-        raise error.PyAsn1Error('Decoder not implemented for %s' % tagSet)\n-\n-    def indefLenValueDecoder(self, substrate, asn1Spec, tagSet,\n-                             length, state, decodeFun):\n-        raise error.PyAsn1Error('Indefinite length mode decoder not implemented for %s' % tagSet)\n-\n-\n-class EndOfOctetsDecoder(AbstractDecoder):\n-    def valueDecoder(self, substrate, asn1Spec, tagSet,\n-                     length, state, decodeFun):\n-        return eoo.endOfOctets, substrate\n-\n-\n-class IntegerDecoder(AbstractDecoder):\n-    protoComponent = univ.Integer(0)\n-\n-    def _valueFilter(self, value):\n-        try:\n-            return int(value)\n-        except OverflowError:\n-            return value\n-\n-    def valueDecoder(self, substrate, asn1Spec, tagSet, length,\n-                     state, decodeFun):\n-        if not substrate:\n-            raise error.PyAsn1Error('Empty substrate')\n-        octets = map(ord, substrate)\n-        if octets[0] & 0x80:\n-            value = -1L\n-        else:\n-            value = 0L\n-        for octet in octets:\n-            value = value << 8 | octet\n-        value = self._valueFilter(value)\n-        return self._createComponent(tagSet, asn1Spec).clone(value), substrate\n-\n-\n-class BooleanDecoder(IntegerDecoder):\n-    protoComponent = univ.Boolean(0)\n-\n-    def _valueFilter(self, value):\n-        if value:\n-            return 1\n-        else:\n-            return 0\n-\n-\n-class BitStringDecoder(AbstractDecoder):\n-    protoComponent = univ.BitString(())\n-\n-    def valueDecoder(self, substrate, asn1Spec, tagSet, length,\n-                     state, decodeFun):\n-        r = self._createComponent(tagSet, asn1Spec)  # XXX use default tagset\n-        if tagSet[0][1] == tag.tagFormatSimple:     # XXX what tag to check?\n-            if not substrate:\n-                raise error.PyAsn1Error('Missing initial octet')\n-            trailingBits = ord(substrate[0])\n-            if trailingBits > 7:\n-                raise error.PyAsn1Error(\n-                    'Trailing bits overflow %s' % trailingBits\n-                )\n-            substrate = substrate[1:]\n-            lsb = p = 0\n-            l = len(substrate) - 1\n-            b = []\n-            while p <= l:\n-                if p == l:\n-                    lsb = trailingBits\n-                j = 7\n-                o = ord(substrate[p])\n-                while j >= lsb:\n-                    b.append((o >> j) & 0x01)\n-                    j -= 1\n-                p += 1\n-            return r.clone(tuple(b)), ''\n-        if r:\n-            r = r.clone(value=())\n-        if not decodeFun:\n-            return r, substrate\n-        while substrate:\n-            component, substrate = decodeFun(substrate)\n-            r = r + component\n-        return r, substrate\n-\n-    def indefLenValueDecoder(self, substrate, asn1Spec, tagSet,\n-                             length, state, decodeFun):\n-        r = self._createComponent(tagSet, asn1Spec)  # XXX use default tagset\n-        if r:\n-            r = r.clone(value='')\n-        if not decodeFun:\n-            return r, substrate\n-        while substrate:\n-            component, substrate = decodeFun(substrate)\n-            if component == eoo.endOfOctets:\n-                break\n-            r = r + component\n-        else:\n-            raise error.SubstrateUnderrunError(\n-                'No EOO seen before substrate ends'\n-            )\n-        return r, substrate\n-\n-\n-class OctetStringDecoder(AbstractDecoder):\n-    protoComponent = univ.OctetString('')\n-\n-    def valueDecoder(self, substrate, asn1Spec, tagSet, length,\n-                     state, decodeFun):\n-        r = self._createComponent(tagSet, asn1Spec)  # XXX use default tagset\n-        if tagSet[0][1] == tag.tagFormatSimple:      # XXX what tag to check?\n-            return r.clone(str(substrate)), ''\n-        if r:\n-            r = r.clone(value='')\n-        if not decodeFun:\n-            return r, substrate\n-        while substrate:\n-            component, substrate = decodeFun(substrate)\n-            r = r + component\n-        return r, substrate\n-\n-    def indefLenValueDecoder(self, substrate, asn1Spec, tagSet,\n-                             length, state, decodeFun):\n-        r = self._createComponent(tagSet, asn1Spec)  # XXX use default tagset\n-        if r:\n-            r = r.clone(value='')\n-        if not decodeFun:\n-            return r, substrate\n-        while substrate:\n-            component, substrate = decodeFun(substrate)\n-            if component == eoo.endOfOctets:\n-                break\n-            r = r + component\n-        else:\n-            raise error.SubstrateUnderrunError(\n-                'No EOO seen before substrate ends'\n-            )\n-        return r, substrate\n-\n-\n-class NullDecoder(AbstractDecoder):\n-    protoComponent = univ.Null('')\n-\n-    def valueDecoder(self, substrate, asn1Spec, tagSet,\n-                     length, state, decodeFun):\n-        r = self._createComponent(tagSet, asn1Spec)  # XXX use default tagset\n-        if substrate:\n-            raise error.PyAsn1Error('Unexpected substrate for Null')\n-        return r, substrate\n-\n-\n-class ObjectIdentifierDecoder(AbstractDecoder):\n-    protoComponent = univ.ObjectIdentifier(())\n-\n-    def valueDecoder(self, substrate, asn1Spec, tagSet, length,\n-                     state, decodeFun):\n-        r = self._createComponent(tagSet, asn1Spec)  # XXX use default tagset\n-        if not substrate:\n-            raise error.PyAsn1Error('Empty substrate')\n-        oid = []\n-        index = 0\n-        # Get the first subId\n-        subId = ord(substrate[index])\n-        oid.append(int(subId / 40))\n-        oid.append(int(subId % 40))\n-\n-        index += 1\n-        substrateLen = len(substrate)\n-\n-        while index < substrateLen:\n-            subId = ord(substrate[index])\n-            if subId < 128:\n-                oid.append(subId)\n-                index += 1\n-            else:\n-                # Construct subid from a number of octets\n-                nextSubId = subId\n-                subId = 0\n-                while nextSubId >= 128 and index < substrateLen:\n-                    subId = (subId << 7) + (nextSubId & 0x7F)\n-                    index += 1\n-                    nextSubId = ord(substrate[index])\n-                if index == substrateLen:\n-                    raise error.SubstrateUnderrunError('Short substrate for OID %s' % oid)\n-                subId = (subId << 7) + nextSubId\n-                oid.append(subId)\n-                index += 1\n-        return r.clone(tuple(oid)), substrate[index:]\n-\n-\n-class SequenceDecoder(AbstractDecoder):\n-    protoComponent = univ.Sequence()\n-\n-    def _getAsn1SpecByPosition(self, t, idx):\n-        if t.getComponentType() is not None:\n-            if hasattr(t, 'getComponentTypeMapNearPosition'):\n-                return t.getComponentTypeMapNearPosition(idx)  # Sequence\n-            elif hasattr(t, 'getComponentType'):  # XXX\n-                return t.getComponentType()  # SequenceOf\n-                # or no asn1Specs\n-\n-    def _getPositionByType(self, t, c, idx):\n-        if t.getComponentType() is not None:\n-            if hasattr(t, 'getComponentPositionNearType'):\n-                effectiveTagSet = getattr(\n-                    c, 'getEffectiveTagSet', c.getTagSet\n-                )()\n-                return t.getComponentPositionNearType(effectiveTagSet, idx)  # Sequence\n-        return idx  # SequenceOf or w/o asn1Specs\n-\n-    def valueDecoder(self, substrate, asn1Spec, tagSet,\n-                     length, state, decodeFun):\n-        r = self._createComponent(tagSet, asn1Spec)\n-        idx = 0\n-        if not decodeFun:\n-            return r, substrate\n-        while substrate:\n-            asn1Spec = self._getAsn1SpecByPosition(r, idx)\n-            component, substrate = decodeFun(substrate, asn1Spec)\n-            idx = self._getPositionByType(r, component, idx)\n-            r.setComponentByPosition(idx, component)\n-            idx += 1\n-        if hasattr(r, 'setDefaultComponents'):\n-            r.setDefaultComponents()\n-        r.verifySizeSpec()\n-        return r, substrate\n-\n-    def indefLenValueDecoder(self, substrate, asn1Spec, tagSet,\n-                             length, state, decodeFun):\n-        r = self._createComponent(tagSet, asn1Spec)\n-        idx = 0\n-        while substrate:\n-            try:\n-                asn1Spec = self._getAsn1SpecByPosition(r, idx)\n-            except error.PyAsn1Error:\n-                asn1Spec = None  # XXX\n-            if not decodeFun:\n-                return r, substrate\n-            component, substrate = decodeFun(substrate, asn1Spec)\n-            if component == eoo.endOfOctets:\n-                break\n-            idx = self._getPositionByType(r, component, idx)\n-            r.setComponentByPosition(idx, component)\n-            idx += 1\n-        else:\n-            raise error.SubstrateUnderrunError(\n-                'No EOO seen before substrate ends'\n-            )\n-        if hasattr(r, 'setDefaultComponents'):\n-            r.setDefaultComponents()\n-        r.verifySizeSpec()\n-        return r, substrate\n-\n-\n-class SetDecoder(SequenceDecoder):\n-    protoComponent = univ.Set()\n-\n-    def _getAsn1SpecByPosition(self, t, idx):\n-        if t.getComponentType() is not None:\n-            if hasattr(t, 'getComponentTypeMap'):\n-                return t.getComponentTypeMap()  # Set/SetOf\n-                # or no asn1Specs\n-\n-    def _getPositionByType(self, t, c, idx):\n-        if t.getComponentType() is not None:\n-            if hasattr(t, 'getComponentPositionByType') and t.getComponentType():\n-                effectiveTagSet = getattr(c, 'getEffectiveTagSet', c.getTagSet)()\n-                return t.getComponentPositionByType(effectiveTagSet) # Set\n-        return idx  # SetOf or w/o asn1Specs\n-\n-\n-class ChoiceDecoder(AbstractDecoder):\n-    protoComponent = univ.Choice()\n-\n-    def valueDecoder(self, substrate, asn1Spec, tagSet,\n-                     length, state, decodeFun):\n-        r = self._createComponent(tagSet, asn1Spec)\n-        if not decodeFun:\n-            return r, substrate\n-        if r.getTagSet() == tagSet:  # explicitly tagged Choice\n-            component, substrate = decodeFun(substrate, r.getComponentTypeMap())\n-        else:\n-            component, substrate = decodeFun(substrate, r.getComponentTypeMap(), tagSet, length, state)\n-        effectiveTagSet = getattr(component, 'getEffectiveTagSet', component.getTagSet)()\n-        r.setComponentByType(effectiveTagSet, component)\n-        return r, substrate\n-\n-    indefLenValueDecoder = valueDecoder\n-\n-\n-# character string types\n-class UTF8StringDecoder(OctetStringDecoder):\n-    protoComponent = char.UTF8String()\n-\n-\n-class NumericStringDecoder(OctetStringDecoder):\n-    protoComponent = char.NumericString()\n-\n-\n-class PrintableStringDecoder(OctetStringDecoder):\n-    protoComponent = char.PrintableString()\n-\n-\n-class TeletexStringDecoder(OctetStringDecoder):\n-    protoComponent = char.TeletexString()\n-\n-\n-class VideotexStringDecoder(OctetStringDecoder):\n-    protoComponent = char.VideotexString()\n-\n-\n-class IA5StringDecoder(OctetStringDecoder):\n-    protoComponent = char.IA5String()\n-\n-\n-class GraphicStringDecoder(OctetStringDecoder):\n-    protoComponent = char.GraphicString()\n-\n-\n-class VisibleStringDecoder(OctetStringDecoder):\n-    protoComponent = char.VisibleString()\n-\n-\n-class GeneralStringDecoder(OctetStringDecoder):\n-    protoComponent = char.GeneralString()\n-\n-\n-class UniversalStringDecoder(OctetStringDecoder):\n-    protoComponent = char.UniversalString()\n-\n-\n-class BMPStringDecoder(OctetStringDecoder):\n-    protoComponent = char.BMPString()\n-\n-\n-# \"useful\" types\n-class GeneralizedTimeDecoder(OctetStringDecoder):\n-    protoComponent = useful.GeneralizedTime()\n-\n-\n-class UTCTimeDecoder(OctetStringDecoder):\n-    protoComponent = useful.UTCTime()\n-\n-\n-codecMap = {\n-    eoo.endOfOctets.tagSet: EndOfOctetsDecoder(),\n-    univ.Integer.tagSet: IntegerDecoder(),\n-    univ.Boolean.tagSet: BooleanDecoder(),\n-    univ.BitString.tagSet: BitStringDecoder(),\n-    univ.OctetString.tagSet: OctetStringDecoder(),\n-    univ.Null.tagSet: NullDecoder(),\n-    univ.ObjectIdentifier.tagSet: ObjectIdentifierDecoder(),\n-    univ.Enumerated.tagSet: IntegerDecoder(),\n-    univ.Sequence.tagSet: SequenceDecoder(),\n-    univ.Set.tagSet: SetDecoder(),\n-    univ.Choice.tagSet: ChoiceDecoder(),\n-    # character string types\n-    char.UTF8String.tagSet: UTF8StringDecoder(),\n-    char.NumericString.tagSet: NumericStringDecoder(),\n-    char.PrintableString.tagSet: PrintableStringDecoder(),\n-    char.TeletexString.tagSet: TeletexStringDecoder(),\n-    char.VideotexString.tagSet: VideotexStringDecoder(),\n-    char.IA5String.tagSet: IA5StringDecoder(),\n-    char.GraphicString.tagSet: GraphicStringDecoder(),\n-    char.VisibleString.tagSet: VisibleStringDecoder(),\n-    char.GeneralString.tagSet: GeneralStringDecoder(),\n-    char.UniversalString.tagSet: UniversalStringDecoder(),\n-    char.BMPString.tagSet: BMPStringDecoder(),\n-    # useful types\n-    useful.GeneralizedTime.tagSet: GeneralizedTimeDecoder(),\n-    useful.UTCTime.tagSet: UTCTimeDecoder()\n-}\n-\n-(stDecodeTag, stDecodeLength, stGetValueDecoder, stGetValueDecoderByAsn1Spec,\n-    stGetValueDecoderByTag, stTryAsExplicitTag, stDecodeValue, stDumpRawValue,\n-    stErrorCondition, stStop) = range(10)\n-\n-\n-class Decoder:\n-    defaultErrorState = stErrorCondition\n-    defaultRawDecoder = OctetStringDecoder()\n-\n-    def __init__(self, codecMap):\n-        self.__codecMap = codecMap\n-\n-    def __call__(self, substrate, asn1Spec=None, tagSet=None,\n-                 length=None, state=stDecodeTag, recursiveFlag=1):\n-        # Decode tag & length\n-        while state != stStop:\n-            if state == stDecodeTag:\n-                # Decode tag\n-                if not substrate:\n-                    raise error.SubstrateUnderrunError(\n-                        'Short octet stream on tag decoding'\n-                    )\n-                t = ord(substrate[0])\n-                tagClass = t & 0xC0\n-                tagFormat = t & 0x20\n-                tagId = t & 0x1F\n-                substrate = substrate[1:]\n-                if tagId == 0x1F:\n-                    tagId = 0L\n-                    while 1:\n-                        if not substrate:\n-                            raise error.SubstrateUnderrunError(\n-                                'Short octet stream on long tag decoding'\n-                            )\n-                        t = ord(substrate[0])\n-                        tagId = tagId << 7 | (t & 0x7F)\n-                        substrate = substrate[1:]\n-                        if not t & 0x80:\n-                            break\n-                lastTag = tag.Tag(\n-                    tagClass=tagClass, tagFormat=tagFormat, tagId=tagId\n-                )\n-                if tagSet is None:\n-                    tagSet = tag.TagSet((), lastTag)  # base tag not recovered\n-                else:\n-                    tagSet = lastTag + tagSet\n-                state = stDecodeLength\n-            if state == stDecodeLength:\n-                # Decode length\n-                if not substrate:\n-                    raise error.SubstrateUnderrunError(\n-                        'Short octet stream on length decoding'\n-                    )\n-                firstOctet = ord(substrate[0])\n-                if firstOctet == 128:\n-                    size = 1\n-                    length = -1\n-                elif firstOctet < 128:\n-                    length, size = firstOctet, 1\n-                else:\n-                    size = firstOctet & 0x7F\n-                    # encoded in size bytes\n-                    length = 0\n-                    lengthString = substrate[1:size + 1]\n-                    # missing check on maximum size, which shouldn't be a\n-                    # problem, we can handle more than is possible\n-                    if len(lengthString) != size:\n-                        raise error.SubstrateUnderrunError(\n-                            '%s<%s at %s' %\n-                            (size, len(lengthString), tagSet)\n-                        )\n-                    for char in lengthString:\n-                        length = (length << 8) | ord(char)\n-                    size += 1\n-                state = stGetValueDecoder\n-                substrate = substrate[size:]\n-                if length != -1 and len(substrate) < length:\n-                    raise error.SubstrateUnderrunError(\n-                        '%d-octet short' % (length - len(substrate))\n-                    )\n-            if state == stGetValueDecoder:\n-                if asn1Spec is None:\n-                    state = stGetValueDecoderByTag\n-                else:\n-                    state = stGetValueDecoderByAsn1Spec\n-                    #\n-                    # There're two ways of creating subtypes in ASN.1 what influences\n-                    # decoder operation. These methods are:\n-                    # 1) Either base types used in or no IMPLICIT tagging has been\n-                    #    applied on subtyping.\n-                    # 2) Subtype syntax drops base type information (by means of\n-                    #    IMPLICIT tagging.\n-                # The first case allows for complete tag recovery from substrate\n-            # while the second one requires original ASN.1 type spec for\n-            # decoding.\n-            #\n-            # In either case a set of tags (tagSet) is coming from substrate\n-            # in an incremental, tag-by-tag fashion (this is the case of\n-            # EXPLICIT tag which is most basic). Outermost tag comes first\n-            # from the wire.\n-            #            \n-            if state == stGetValueDecoderByTag:\n-                concreteDecoder = self.__codecMap.get(tagSet)\n-                if concreteDecoder:\n-                    state = stDecodeValue\n-                else:\n-                    concreteDecoder = self.__codecMap.get(tagSet[:1])\n-                    if concreteDecoder:\n-                        state = stDecodeValue\n-                    else:\n-                        state = stTryAsExplicitTag\n-            if state == stGetValueDecoderByAsn1Spec:\n-                if tagSet == eoo.endOfOctets.getTagSet():\n-                    concreteDecoder = self.__codecMap[tagSet]\n-                    state = stDecodeValue\n-                    continue\n-                if type(asn1Spec) == types.DictType:\n-                    __chosenSpec = asn1Spec.get(tagSet)\n-                elif asn1Spec is not None:\n-                    __chosenSpec = asn1Spec\n-                else:\n-                    __chosenSpec = None\n-                if __chosenSpec is None or not \\\n-                    __chosenSpec.getTypeMap().has_key(tagSet):\n-                    state = stTryAsExplicitTag\n-                else:\n-                    # use base type for codec lookup to recover untagged types\n-                    baseTag = __chosenSpec.getTagSet().getBaseTag()\n-                    if baseTag: # XXX ugly\n-                        baseTagSet = tag.TagSet(baseTag, baseTag)\n-                    else:\n-                        baseTagSet = tag.TagSet()\n-                    concreteDecoder = self.__codecMap.get(# tagged subtype\n-                        baseTagSet\n-                    )\n-                    if concreteDecoder:\n-                        asn1Spec = __chosenSpec\n-                        state = stDecodeValue\n-                    else:\n-                        state = stTryAsExplicitTag\n-            if state == stTryAsExplicitTag:\n-                if tagSet and \\\n-                                tagSet[0][1] == tag.tagFormatConstructed and \\\n-                                tagSet[0][0] != tag.tagClassUniversal:\n-                    # Assume explicit tagging\n-                    state = stDecodeTag\n-                else:\n-                    state = self.defaultErrorState\n-            if state == stDecodeValue:\n-                if recursiveFlag:\n-                    decodeFun = self\n-                else:\n-                    decodeFun = None\n-                if length == -1:  # indef length\n-                    value, substrate = concreteDecoder.indefLenValueDecoder(\n-                        substrate, asn1Spec, tagSet, length,\n-                        stGetValueDecoder, decodeFun\n-                    )\n-                else:\n-                    value, _substrate = concreteDecoder.valueDecoder(\n-                        substrate[:length], asn1Spec, tagSet,\n-                        length, stGetValueDecoder, decodeFun\n-                    )\n-                    if recursiveFlag:\n-                        substrate = substrate[length:]\n-                    else:\n-                        substrate = _substrate\n-                state = stStop\n-            if state == stDumpRawValue:\n-                concreteDecoder = self.defaultRawDecoder\n-                state = stDecodeValue\n-            if state == stErrorCondition:\n-                raise error.PyAsn1Error(\n-                    '%s not in asn1Spec: %s' % (tagSet, asn1Spec)\n-                )\n-        return value, substrate\n-\n-\n-decode = Decoder(codecMap)\n-\n-# XXX\n-# non-recursive decoding; return position rather than substrate\ndiff --git a/src/xmlsec/rsa_x509_pem/pyasn1/codec/ber/encoder.py b/src/xmlsec/rsa_x509_pem/pyasn1/codec/ber/encoder.py\ndeleted file mode 100644\n--- a/src/xmlsec/rsa_x509_pem/pyasn1/codec/ber/encoder.py\n+++ /dev/null\n@@ -1,280 +0,0 @@\n-# BER encoder\n-import string\n-from ...type import base, tag, univ, char, useful\n-from ..ber import eoo\n-from ... import error\n-\n-\n-class Error(Exception):\n-    pass\n-\n-\n-class AbstractItemEncoder:\n-    supportIndefLenMode = 1\n-\n-    def encodeTag(self, t, isConstructed):\n-        v = t[0] | t[1]\n-        if isConstructed:\n-            v |= tag.tagFormatConstructed\n-        if t[2] < 31:\n-            return chr(v | t[2])\n-        else:\n-            longTag = t[2]\n-            s = chr(longTag & 0x7f)\n-            longTag >>= 7\n-            while longTag:\n-                s = chr(0x80 | (longTag & 0x7f)) + s\n-                longTag >>= 7\n-            return chr(v | 0x1F) + s\n-\n-    def encodeLength(self, length, defMode):\n-        if not defMode and self.supportIndefLenMode:\n-            return '\\x80'\n-        if length < 0x80:\n-            return chr(length)\n-        else:\n-            substrate = ''\n-            while length:\n-                substrate = chr(length & 0xff) + substrate\n-                length >>= 8\n-            if len(substrate) > 126:\n-                raise Error('Length octets overflow (%d)' % len(substrate))\n-            return chr(0x80 | len(substrate)) + substrate\n-\n-    def encodeValue(self, encodeFun, value, defMode, maxChunkSize):\n-        raise Error('Not implemented')\n-\n-    def _encodeEndOfOctets(self, encodeFun, defMode):\n-        if defMode or not self.supportIndefLenMode:\n-            return ''\n-        else:\n-            return encodeFun(eoo.endOfOctets, defMode)\n-\n-    def encode(self, encodeFun, value, defMode, maxChunkSize):\n-        substrate, isConstructed = self.encodeValue(\n-            encodeFun, value, defMode, maxChunkSize\n-        )\n-        tagSet = value.getTagSet()\n-        if tagSet:\n-            if not isConstructed:  # primitive form implies definite mode\n-                defMode = 1\n-            return self.encodeTag(\n-                tagSet[-1], isConstructed\n-            ) + self.encodeLength(\n-                len(substrate), defMode\n-            ) + substrate + self._encodeEndOfOctets(encodeFun, defMode)\n-        else:\n-            return substrate  # untagged value\n-\n-\n-class EndOfOctetsEncoder(AbstractItemEncoder):\n-    def encodeValue(self, encodeFun, value, defMode, maxChunkSize):\n-        return '', 0\n-\n-\n-class ExplicitlyTaggedItemEncoder(AbstractItemEncoder):\n-    def encodeValue(self, encodeFun, value, defMode, maxChunkSize):\n-        if isinstance(value, base.AbstractConstructedAsn1Item):\n-            value = value.clone(tagSet=value.getTagSet()[:-1],\n-                                cloneValueFlag=1)\n-        else:\n-            value = value.clone(tagSet=value.getTagSet()[:-1])\n-        return encodeFun(value, defMode, maxChunkSize), 1\n-\n-\n-explicitlyTaggedItemEncoder = ExplicitlyTaggedItemEncoder()\n-\n-\n-class IntegerEncoder(AbstractItemEncoder):\n-    supportIndefLenMode = 0\n-\n-    def encodeValue(self, encodeFun, value, defMode, maxChunkSize):\n-        octets = []\n-        value = long(value)  # to save on ops on asn1 type\n-        while 1:\n-            octets.insert(0, value & 0xff)\n-            if value == 0 or value == -1:\n-                break\n-            value >>= 8\n-        if value == 0 and octets[0] & 0x80:\n-            octets.insert(0, 0)\n-        while len(octets) > 1 and \\\n-                (octets[0] == 0 and octets[1] & 0x80 == 0 or \\\n-                             octets[0] == 0xff and octets[1] & 0x80 != 0):\n-            del octets[0]\n-        return string.join(map(chr, octets), ''), 0\n-\n-\n-class BitStringEncoder(AbstractItemEncoder):\n-    def encodeValue(self, encodeFun, value, defMode, maxChunkSize):\n-        if not maxChunkSize or len(value) <= maxChunkSize * 8:\n-            r = {}\n-            l = len(value)\n-            p = 0\n-            j = 7\n-            while p < l:\n-                i, j = divmod(p, 8)\n-                r[i] = r.get(i, 0) | value[p] << (7 - j)\n-                p = p + 1\n-            keys = r.keys()\n-            keys.sort()\n-            return chr(7 - j) + string.join(\n-                map(lambda k, r=r: chr(r[k]), keys), ''\n-            ), 0\n-        else:\n-            pos = 0\n-            substrate = ''\n-            while 1:\n-                # count in octets\n-                v = value.clone(value[pos * 8:pos * 8 + maxChunkSize * 8])\n-                if not v:\n-                    break\n-                substrate = substrate + encodeFun(v, defMode, maxChunkSize)\n-                pos = pos + maxChunkSize\n-            return substrate, 1\n-\n-\n-class OctetStringEncoder(AbstractItemEncoder):\n-    def encodeValue(self, encodeFun, value, defMode, maxChunkSize):\n-        if not maxChunkSize or len(value) <= maxChunkSize:\n-            return str(value), 0\n-        else:\n-            pos = 0\n-            substrate = ''\n-            while 1:\n-                v = value.clone(value[pos:pos + maxChunkSize])\n-                if not v:\n-                    break\n-                substrate = substrate + encodeFun(v, defMode, maxChunkSize)\n-                pos = pos + maxChunkSize\n-            return substrate, 1\n-\n-\n-class NullEncoder(AbstractItemEncoder):\n-    supportIndefLenMode = 0\n-\n-    def encodeValue(self, encodeFun, value, defMode, maxChunkSize):\n-        return '', 0\n-\n-\n-class ObjectIdentifierEncoder(AbstractItemEncoder):\n-    supportIndefLenMode = 0\n-\n-    def encodeValue(self, encodeFun, value, defMode, maxChunkSize):\n-        oid = tuple(value)\n-        if len(oid) < 2:\n-            raise error.PyAsn1Error('Short OID %s' % value)\n-\n-        # Build the first twos\n-        index = 0\n-        subid = oid[index] * 40\n-        subid = subid + oid[index + 1]\n-        if 0 > subid > 0xff:\n-            raise error.PyAsn1Error(\n-                'Initial sub-ID overflow %s in OID %s' % (oid[index:], value)\n-            )\n-        octets = [chr(subid)]\n-        index += 2\n-\n-        # Cycle through subids\n-        for subid in oid[index:]:\n-            if subid > -1 and subid < 128:\n-                # Optimize for the common case\n-                octets.append(chr(subid & 0x7f))\n-            elif subid < 0 or subid > 0xFFFFFFFFL:\n-                raise error.PyAsn1Error('SubId overflow %s in %s' % (subid, value))\n-            else:\n-                # Pack large Sub-Object IDs\n-                res = [chr(subid & 0x7f)]\n-                subid >>= 7\n-                while subid > 0:\n-                    res.insert(0, chr(0x80 | (subid & 0x7f)))\n-                    subid >>= 7\n-                    # Convert packed Sub-Object ID to string and add packed\n-                    # it to resulted Object ID\n-                octets.append(string.join(res, ''))\n-        return string.join(octets, ''), 0\n-\n-\n-class SequenceOfEncoder(AbstractItemEncoder):\n-    def encodeValue(self, encodeFun, value, defMode, maxChunkSize):\n-        if hasattr(value, 'setDefaultComponents'):\n-            value.setDefaultComponents()\n-        value.verifySizeSpec()\n-        substrate = ''\n-        idx = len(value)\n-        while idx > 0:\n-            idx -= 1\n-            if value[idx] is None:  # Optional component\n-                continue\n-            if hasattr(value, 'getDefaultComponentByPosition'):\n-                if value.getDefaultComponentByPosition(idx) == value[idx]:\n-                    continue\n-            substrate = encodeFun(\n-                value[idx], defMode, maxChunkSize\n-            ) + substrate\n-        return substrate, 1\n-\n-\n-codecMap = {\n-    eoo.endOfOctets.tagSet: EndOfOctetsEncoder(),\n-    univ.Boolean.tagSet: IntegerEncoder(),\n-    univ.Integer.tagSet: IntegerEncoder(),\n-    univ.BitString.tagSet: BitStringEncoder(),\n-    univ.OctetString.tagSet: OctetStringEncoder(),\n-    univ.Null.tagSet: NullEncoder(),\n-    univ.ObjectIdentifier.tagSet: ObjectIdentifierEncoder(),\n-    univ.Enumerated.tagSet: IntegerEncoder(),\n-    # Sequence & Set have same tags as SequenceOf & SetOf\n-    univ.SequenceOf.tagSet: SequenceOfEncoder(),\n-    univ.SetOf.tagSet: SequenceOfEncoder(),\n-    univ.Choice.tagSet: SequenceOfEncoder(),\n-    # character string types\n-    char.UTF8String.tagSet: OctetStringEncoder(),\n-    char.NumericString.tagSet: OctetStringEncoder(),\n-    char.PrintableString.tagSet: OctetStringEncoder(),\n-    char.TeletexString.tagSet: OctetStringEncoder(),\n-    char.VideotexString.tagSet: OctetStringEncoder(),\n-    char.IA5String.tagSet: OctetStringEncoder(),\n-    char.GraphicString.tagSet: OctetStringEncoder(),\n-    char.VisibleString.tagSet: OctetStringEncoder(),\n-    char.GeneralString.tagSet: OctetStringEncoder(),\n-    char.UniversalString.tagSet: OctetStringEncoder(),\n-    char.BMPString.tagSet: OctetStringEncoder(),\n-    # useful types\n-    useful.GeneralizedTime.tagSet: OctetStringEncoder(),\n-    useful.UTCTime.tagSet: OctetStringEncoder()\n-}\n-\n-\n-class Encoder:\n-    def __init__(self, _codecMap):\n-        self.__codecMap = _codecMap\n-        self.__emptyTagSet = tag.TagSet()\n-\n-    def __call__(self, value, defMode=1, maxChunkSize=0):\n-        tagSet = value.getTagSet()\n-        if len(tagSet) > 1:\n-            concreteEncoder = explicitlyTaggedItemEncoder\n-        else:\n-            concreteEncoder = self.__codecMap.get(tagSet)\n-            if not concreteEncoder:\n-                # XXX\n-                baseTagSet = tagSet.getBaseTag()\n-                if baseTagSet:\n-                    concreteEncoder = self.__codecMap.get(\n-                        tag.TagSet(baseTagSet, baseTagSet)\n-                    )\n-                else:\n-                    concreteEncoder = self.__codecMap.get(\n-                        self.__emptyTagSet\n-                    )\n-        if concreteEncoder:\n-            return concreteEncoder.encode(\n-                self, value, defMode, maxChunkSize\n-            )\n-        else:\n-            raise Error('No encoder for %s' % value)\n-\n-\n-encode = Encoder(codecMap)\ndiff --git a/src/xmlsec/rsa_x509_pem/pyasn1/codec/ber/eoo.py b/src/xmlsec/rsa_x509_pem/pyasn1/codec/ber/eoo.py\ndeleted file mode 100644\n--- a/src/xmlsec/rsa_x509_pem/pyasn1/codec/ber/eoo.py\n+++ /dev/null\n@@ -1,11 +0,0 @@\n-from ...type import base, tag\n-\n-\n-class EndOfOctets(base.AbstractSimpleAsn1Item):\n-    defaultValue = 0\n-    tagSet = tag.initTagSet(\n-        tag.Tag(tag.tagClassUniversal, tag.tagFormatSimple, 0x00)\n-    )\n-\n-\n-endOfOctets = EndOfOctets()\ndiff --git a/src/xmlsec/rsa_x509_pem/pyasn1/codec/cer/__init__.py b/src/xmlsec/rsa_x509_pem/pyasn1/codec/cer/__init__.py\ndeleted file mode 100644\ndiff --git a/src/xmlsec/rsa_x509_pem/pyasn1/codec/cer/decoder.py b/src/xmlsec/rsa_x509_pem/pyasn1/codec/cer/decoder.py\ndeleted file mode 100644\n--- a/src/xmlsec/rsa_x509_pem/pyasn1/codec/cer/decoder.py\n+++ /dev/null\n@@ -1,34 +0,0 @@\n-# CER decoder\n-from ...type import univ\n-from ..ber import decoder\n-from ... import error\n-\n-\n-class BooleanDecoder(decoder.AbstractDecoder):\n-    protoComponent = univ.Boolean(0)\n-\n-    def valueDecoder(self, substrate, asn1Spec, tagSet, length,\n-                     state, decodeFun):\n-        if not substrate:\n-            raise error.PyAsn1Error('Empty substrate')\n-        byte = ord(substrate[0])\n-        if byte == 0xff:\n-            value = 1\n-        elif byte == 0x00:\n-            value = 0\n-        return self._createComponent(\n-            tagSet, asn1Spec\n-        ).clone(value), substrate[1:]\n-\n-\n-codecMap = decoder.codecMap.copy()\n-codecMap.update({\n-    univ.Boolean.tagSet: BooleanDecoder(),\n-})\n-\n-\n-class Decoder(decoder.Decoder):\n-    pass\n-\n-\n-decode = Decoder(codecMap)\ndiff --git a/src/xmlsec/rsa_x509_pem/pyasn1/codec/cer/encoder.py b/src/xmlsec/rsa_x509_pem/pyasn1/codec/cer/encoder.py\ndeleted file mode 100644\n--- a/src/xmlsec/rsa_x509_pem/pyasn1/codec/cer/encoder.py\n+++ /dev/null\n@@ -1,92 +0,0 @@\n-# CER encoder\n-import string\n-from ...type import univ\n-from ..ber import encoder\n-\n-\n-class BooleanEncoder(encoder.IntegerEncoder):\n-    def encodeValue(self, encodeFun, client, defMode, maxChunkSize):\n-        if client == 0:\n-            substrate = '\\000'\n-        else:\n-            substrate = '\\777'\n-        return substrate, 0\n-\n-\n-class BitStringEncoder(encoder.BitStringEncoder):\n-    def encodeValue(self, encodeFun, client, defMode, maxChunkSize):\n-        return encoder.BitStringEncoder.encodeValue(\n-            self, encodeFun, client, defMode, 1000\n-        )\n-\n-\n-class OctetStringEncoder(encoder.OctetStringEncoder):\n-    def encodeValue(self, encodeFun, client, defMode, maxChunkSize):\n-        return encoder.OctetStringEncoder.encodeValue(\n-            self, encodeFun, client, defMode, 1000\n-        )\n-\n-# specialized RealEncoder here\n-# specialized GeneralStringEncoder here\n-# specialized GeneralizedTimeEncoder here\n-# specialized UTCTimeEncoder here\n-\n-class SetOfEncoder(encoder.SequenceOfEncoder):\n-    def _cmpSetComponents(self, c1, c2):\n-        return cmp(\n-            getattr(c1, 'getMinimalTagSet', c1.getTagSet)(),\n-            getattr(c2, 'getMinimalTagSet', c2.getTagSet)()\n-        )\n-\n-    def encodeValue(self, encodeFun, client, defMode, maxChunkSize):\n-        if hasattr(client, 'setDefaultComponents'):\n-            client.setDefaultComponents()\n-        client.verifySizeSpec()\n-        substrate = ''\n-        idx = len(client)\n-        # This is certainly a hack but how else do I distinguish SetOf\n-        # from Set if they have the same tags&constraints?\n-        if hasattr(client, 'getDefaultComponentByPosition'):\n-            # Set\n-            comps = []\n-            while idx > 0:\n-                idx = idx - 1\n-                if client[idx] is None:  # Optional component\n-                    continue\n-                if client.getDefaultComponentByPosition(idx) == client[idx]:\n-                    continue\n-                comps.append(client[idx])\n-            comps.sort(self._cmpSetComponents)\n-            for c in comps:\n-                substrate = substrate + encodeFun(c, defMode, maxChunkSize)\n-        else:\n-            # SetOf\n-            compSubs = []\n-            while idx > 0:\n-                idx = idx - 1\n-                compSubs.append(\n-                    encodeFun(client[idx], defMode, maxChunkSize)\n-                )\n-            compSubs.sort()  # perhaps padding's not needed\n-            substrate = string.join(compSubs, '')\n-        return substrate, 1\n-\n-\n-codecMap = encoder.codecMap.copy()\n-codecMap.update({\n-    univ.Boolean.tagSet: BooleanEncoder(),\n-    univ.BitString.tagSet: BitStringEncoder(),\n-    univ.OctetString.tagSet: OctetStringEncoder(),\n-    # Set & SetOf have same tags\n-    univ.SetOf().tagSet: SetOfEncoder()\n-})\n-\n-\n-class Encoder(encoder.Encoder):\n-    def __call__(self, client, defMode=0, maxChunkSize=0):\n-        return encoder.Encoder.__call__(self, client, defMode, maxChunkSize)\n-\n-\n-encode = Encoder(codecMap)\n-\n-# EncoderFactory queries class instance and builds a map of tags -> encoders\ndiff --git a/src/xmlsec/rsa_x509_pem/pyasn1/codec/der/__init__.py b/src/xmlsec/rsa_x509_pem/pyasn1/codec/der/__init__.py\ndeleted file mode 100644\ndiff --git a/src/xmlsec/rsa_x509_pem/pyasn1/codec/der/decoder.py b/src/xmlsec/rsa_x509_pem/pyasn1/codec/der/decoder.py\ndeleted file mode 100644\n--- a/src/xmlsec/rsa_x509_pem/pyasn1/codec/der/decoder.py\n+++ /dev/null\n@@ -1,5 +0,0 @@\n-# DER decoder\n-from ...type import univ\n-from ..cer import decoder\n-\n-decode = decoder.Decoder(decoder.codecMap)\ndiff --git a/src/xmlsec/rsa_x509_pem/pyasn1/codec/der/encoder.py b/src/xmlsec/rsa_x509_pem/pyasn1/codec/der/encoder.py\ndeleted file mode 100644\n--- a/src/xmlsec/rsa_x509_pem/pyasn1/codec/der/encoder.py\n+++ /dev/null\n@@ -1,29 +0,0 @@\n-# DER encoder\n-from ...type import univ\n-from ..cer import encoder\n-\n-\n-class SetOfEncoder(encoder.SetOfEncoder):\n-    def _cmpSetComponents(self, c1, c2):\n-        return cmp(\n-            getattr(c1, 'getEffectiveTagSet', c1.getTagSet)(),\n-            getattr(c2, 'getEffectiveTagSet', c2.getTagSet)()\n-        )\n-\n-\n-codecMap = encoder.codecMap.copy()\n-codecMap.update({\n-    # Overload CER encodrs with BER ones (a bit hackerish XXX)\n-    univ.BitString.tagSet: encoder.encoder.BitStringEncoder(),\n-    univ.OctetString.tagSet: encoder.encoder.OctetStringEncoder(),\n-    # Set & SetOf have same tags\n-    univ.SetOf().tagSet: SetOfEncoder()\n-})\n-\n-\n-class Encoder(encoder.Encoder):\n-    def __call__(self, client, defMode=1, maxChunkSize=0):\n-        return encoder.Encoder.__call__(self, client, defMode, maxChunkSize)\n-\n-\n-encode = Encoder(codecMap)\ndiff --git a/src/xmlsec/rsa_x509_pem/pyasn1/error.py b/src/xmlsec/rsa_x509_pem/pyasn1/error.py\ndeleted file mode 100644\n--- a/src/xmlsec/rsa_x509_pem/pyasn1/error.py\n+++ /dev/null\n@@ -1,10 +0,0 @@\n-class PyAsn1Error(Exception):\n-    pass\n-\n-\n-class ValueConstraintError(PyAsn1Error):\n-    pass\n-\n-\n-class SubstrateUnderrunError(PyAsn1Error):\n-    pass\ndiff --git a/src/xmlsec/rsa_x509_pem/pyasn1/type/__init__.py b/src/xmlsec/rsa_x509_pem/pyasn1/type/__init__.py\ndeleted file mode 100644\ndiff --git a/src/xmlsec/rsa_x509_pem/pyasn1/type/base.py b/src/xmlsec/rsa_x509_pem/pyasn1/type/base.py\ndeleted file mode 100644\n--- a/src/xmlsec/rsa_x509_pem/pyasn1/type/base.py\n+++ /dev/null\n@@ -1,322 +0,0 @@\n-# Base classes for ASN.1 types\n-#\n-# Modified to support name-based indexes in __getitem__ (leifj@mnt.se)\n-#\n-try:\n-    from sys import version_info\n-except ImportError:\n-    version_info = (0, 0)   # a really early version\n-from operator import getslice, setslice, delslice\n-from string import join\n-from types import SliceType\n-from . import constraint, namedval\n-from .. import error\n-import warnings\n-\n-\n-def deprecated(func):\n-    \"\"\"This is a decorator which can be used to mark functions\n-    as deprecated. It will result in a warning being emitted\n-    when the function is used.\"\"\"\n-\n-    def new_func(*args, **kwargs):\n-        warnings.warn(\"Call to deprecated function {}.\".format(func.__name__),\n-                      category=DeprecationWarning)\n-        return func(*args, **kwargs)\n-\n-    new_func.__name__ = func.__name__\n-    new_func.__doc__ = func.__doc__\n-    new_func.__dict__.update(func.__dict__)\n-\n-    return new_func\n-\n-\n-class Asn1Item:\n-    pass\n-\n-\n-class Asn1ItemBase(Asn1Item):\n-    # Set of tags for this ASN.1 type\n-    tagSet = ()\n-\n-    # A list of constraint.Constraint instances for checking values\n-    subtypeSpec = constraint.ConstraintsIntersection()\n-\n-    def __init__(self, tagSet=None, subtypeSpec=None):\n-        if tagSet is None:\n-            self._tagSet = self.tagSet\n-        else:\n-            self._tagSet = tagSet\n-        if subtypeSpec is None:\n-            self._subtypeSpec = self.subtypeSpec\n-        else:\n-            self._subtypeSpec = subtypeSpec\n-\n-    def _verifySubtypeSpec(self, value, idx=None):\n-        self._subtypeSpec(value, idx)\n-\n-    def getSubtypeSpec(self):\n-        return self._subtypeSpec\n-\n-    def getTagSet(self):\n-        return self._tagSet\n-\n-    def getTypeMap(self):\n-        return {self._tagSet: self}\n-\n-    def isSameTypeWith(self, other):\n-        return self is other or \\\n-               self._tagSet == other.getTagSet() and \\\n-               self._subtypeSpec == other.getSubtypeSpec()\n-\n-    def isSuperTypeOf(self, other):\n-        \"\"\"Returns true if argument is a ASN1 subtype of ourselves\"\"\"\n-        return self._tagSet.isSuperTagSetOf(other.getTagSet()) and self._subtypeSpec.isSuperTypeOf(other.getSubtypeSpec())\n-\n-    def tagsToTagSet(self, implicitTag, explicitTag):\n-        if implicitTag is not None:\n-            tagSet = self._tagSet.tagImplicitly(implicitTag)\n-        elif explicitTag is not None:\n-            tagSet = self._tagSet.tagExplicitly(explicitTag)\n-        else:\n-            tagSet = self._tagSet\n-        return tagSet\n-\n-class __NoValue:\n-    def __getattr__(self, attr):\n-        raise error.PyAsn1Error('No value for %s()' % attr)\n-\n-\n-noValue = __NoValue()\n-\n-# Base class for \"simple\" ASN.1 objects. These are immutable.\n-class AbstractSimpleAsn1Item(Asn1ItemBase):\n-    defaultValue = noValue\n-\n-    def __init__(self, value=None, tagSet=None, subtypeSpec=None):\n-        Asn1ItemBase.__init__(self, tagSet, subtypeSpec)\n-        if value is None or value is noValue:\n-            value = self.defaultValue\n-        if value is None or value is noValue:\n-            self.__hashedValue = value = noValue\n-        else:\n-            value = self.prettyIn(value)\n-            self._verifySubtypeSpec(value)\n-            self.__hashedValue = hash(value)\n-        self._value = value\n-\n-    def __repr__(self):\n-        if self._value is noValue:\n-            return self.__class__.__name__ + '()'\n-        else:\n-            return self.__class__.__name__ + '(' + repr(\n-                self.prettyOut(self._value)\n-            ) + ')'\n-\n-    def __str__(self):\n-        return str(self._value)\n-\n-    def __cmp__(self, value):\n-        return cmp(self._value, value)\n-\n-    def __hash__(self):\n-        return self.__hashedValue\n-\n-    def __nonzero__(self):\n-        if self._value:\n-            return 1\n-        else:\n-            return 0\n-\n-    def clone(self, value=None, tagSet=None, subtypeSpec=None):\n-        if value is None and tagSet is None and subtypeSpec is None:\n-            return self\n-        if value is None:\n-            value = self._value\n-        if tagSet is None:\n-            tagSet = self._tagSet\n-        if subtypeSpec is None:\n-            subtypeSpec = self._subtypeSpec\n-        return self.__class__(value, tagSet, subtypeSpec)\n-\n-    def subtype(self, value=None, implicitTag=None, explicitTag=None,\n-                subtypeSpec=None):\n-        if value is None:\n-            value = self._value\n-        tagSet = self.tagsToTagSet(implicitTag, explicitTag)\n-        if subtypeSpec is None:\n-            subtypeSpec = self._subtypeSpec\n-        else:\n-            subtypeSpec = subtypeSpec + self._subtypeSpec\n-        return self.__class__(value, tagSet, subtypeSpec)\n-\n-    def prettyIn(self, value):\n-        return value\n-\n-    def prettyOut(self, value):\n-        return str(value)\n-\n-    def prettyPrint(self, scope=0):\n-        return self.prettyOut(self._value)\n-\n-    @deprecated\n-    def prettyPrinter(self, scope=0):\n-        return self.prettyPrint(scope)\n-\n-\n-class AbstractNumerableAsn1Item(AbstractSimpleAsn1Item):\n-\n-    namedValues = namedval.NamedValues()\n-\n-    def __init__(self, value=None, tagSet=None, subtypeSpec=None,\n-                 namedValues=None):\n-        if namedValues is None:\n-            self.__namedValues = self.namedValues\n-        else:\n-            self.__namedValues = namedValues\n-        AbstractSimpleAsn1Item.__init__(\n-            self, value, tagSet, subtypeSpec\n-        )\n-\n-    @property\n-    def named_values(self):\n-        return self.__namedValues\n-\n-    def clone(self, value=None, tagSet=None, subtypeSpec=None,\n-              namedValues=None):\n-        if value is None and tagSet is None and subtypeSpec is None and namedValues is None:\n-            return self\n-        if value is None:\n-            value = self._value\n-        if tagSet is None:\n-            tagSet = self._tagSet\n-        if subtypeSpec is None:\n-            subtypeSpec = self._subtypeSpec\n-        if namedValues is None:\n-            namedValues = self.__namedValues\n-        return self.__class__(value, tagSet, subtypeSpec, namedValues)\n-\n-    def subtype(self, value=None, implicitTag=None, explicitTag=None,\n-                subtypeSpec=None, namedValues=None):\n-        if value is None:\n-            value = self._value\n-        tagSet = self.tagsToTagSet(implicitTag, explicitTag)\n-        if subtypeSpec is None:\n-            subtypeSpec = self._subtypeSpec\n-        else:\n-            subtypeSpec = subtypeSpec + self._subtypeSpec\n-        if namedValues is None:\n-            namedValues = self.__namedValues\n-        else:\n-            namedValues = namedValues + self.__namedValues\n-        return self.__class__(value, tagSet, subtypeSpec, namedValues)\n-\n-#\n-# Constructed types:\n-# * There are five of them: Sequence, SequenceOf/SetOf, Set and Choice\n-# * ASN1 types and values are represened by Python class instances\n-# * Value initialization is made for defaulted components only\n-# * Primary method of component addressing is by-position. Data model for base\n-#   type is Python sequence. Additional type-specific addressing methods\n-#   may be implemented for particular types.\n-# * SequenceOf and SetOf types do not implement any additional methods\n-# * Sequence, Set and Choice types also implement by-identifier addressing\n-# * Sequence, Set and Choice types also implement by-asn1-type (tag) addressing\n-# * Sequence and Set types may include optional and defaulted\n-#   components\n-# * Constructed types hold a reference to component types used for value\n-#   verification and ordering.\n-# * Component type is a scalar type for SequenceOf/SetOf types and a list\n-#   of types for Sequence/Set/Choice.\n-#\n-\n-class AbstractConstructedAsn1Item(Asn1ItemBase):\n-    componentType = None\n-    sizeSpec = constraint.ConstraintsIntersection()\n-\n-    def __init__(self, componentType=None, tagSet=None,\n-                 subtypeSpec=None, sizeSpec=None):\n-        Asn1ItemBase.__init__(self, tagSet, subtypeSpec)\n-        if componentType is None:\n-            self._componentType = self.componentType\n-        else:\n-            self._componentType = componentType\n-        if sizeSpec is None:\n-            self._sizeSpec = self.sizeSpec\n-        else:\n-            self._sizeSpec = sizeSpec\n-        self._componentValues = []\n-\n-    def __repr__(self):\n-        r = self.__class__.__name__ + '()'\n-        for idx in range(len(self)):\n-            if self._componentValues[idx] is None:\n-                continue\n-            r += '.setComponentByPosition(%s, %s)' % (idx, repr(self._componentValues[idx]))\n-        return r\n-\n-    def __cmp__(self, other):\n-        return cmp(self._componentValues, other)\n-\n-    def getComponentTypeMap(self):\n-        raise error.PyAsn1Error('Method not implemented')\n-\n-    def _cloneComponentValues(self, myClone, cloneValueFlag):\n-        pass\n-\n-    def clone(self, tagSet=None, subtypeSpec=None, sizeSpec=None,\n-              cloneValueFlag=None):\n-        if tagSet is None:\n-            tagSet = self._tagSet\n-        if subtypeSpec is None:\n-            subtypeSpec = self._subtypeSpec\n-        if sizeSpec is None:\n-            sizeSpec = self._sizeSpec\n-        r = self.__class__(self._componentType, tagSet, subtypeSpec, sizeSpec)\n-        if cloneValueFlag:\n-            self._cloneComponentValues(r, cloneValueFlag)\n-        return r\n-\n-    def subtype(self, implicitTag=None, explicitTag=None, subtypeSpec=None,\n-                sizeSpec=None, cloneValueFlag=None):\n-        tagSet = self.tagsToTagSet(implicitTag, explicitTag)\n-        if subtypeSpec is None:\n-            subtypeSpec = self._subtypeSpec\n-        else:\n-            subtypeSpec = subtypeSpec + self._subtypeSpec\n-        if sizeSpec is None:\n-            sizeSpec = self._sizeSpec\n-        else:\n-            sizeSpec = sizeSpec + self._sizeSpec\n-        r = self.__class__(self._componentType, tagSet, subtypeSpec, sizeSpec)\n-        if cloneValueFlag:\n-            self._cloneComponentValues(r, cloneValueFlag)\n-        return r\n-\n-    def _verifyComponent(self, idx, value):\n-        pass\n-\n-    def verifySizeSpec(self):\n-        self._sizeSpec(self)\n-\n-    def getComponentByPosition(self, idx):\n-        raise error.PyAsn1Error('Method not implemented')\n-\n-    def setComponentByPosition(self, idx, value):\n-        raise error.PyAsn1Error('Method not implemented')\n-\n-    def getComponentType(self):\n-        return self._componentType\n-\n-    def __getitem__(self, idx):\n-        if type(idx) is int:\n-            return self._componentValues[idx]\n-        else:\n-            return self.getComponentByName(idx)\n-\n-\n-    def __len__(self):\n-        return len(self._componentValues)\n-\n-    def clear(self):\n-        self._componentValues = []\ndiff --git a/src/xmlsec/rsa_x509_pem/pyasn1/type/char.py b/src/xmlsec/rsa_x509_pem/pyasn1/type/char.py\ndeleted file mode 100644\n--- a/src/xmlsec/rsa_x509_pem/pyasn1/type/char.py\n+++ /dev/null\n@@ -1,68 +0,0 @@\n-# ASN.1 \"character string\" types\n-from . import univ, tag\n-\n-\n-class UTF8String(univ.OctetString):\n-    tagSet = univ.OctetString.tagSet.tagImplicitly(\n-        tag.Tag(tag.tagClassUniversal, tag.tagFormatSimple, 12)\n-    )\n-\n-\n-class NumericString(univ.OctetString):\n-    tagSet = univ.OctetString.tagSet.tagImplicitly(\n-        tag.Tag(tag.tagClassUniversal, tag.tagFormatSimple, 18)\n-    )\n-\n-\n-class PrintableString(univ.OctetString):\n-    tagSet = univ.OctetString.tagSet.tagImplicitly(\n-        tag.Tag(tag.tagClassUniversal, tag.tagFormatSimple, 19)\n-    )\n-\n-\n-class TeletexString(univ.OctetString):\n-    tagSet = univ.OctetString.tagSet.tagImplicitly(\n-        tag.Tag(tag.tagClassUniversal, tag.tagFormatSimple, 20)\n-    )\n-\n-\n-class VideotexString(univ.OctetString):\n-    tagSet = univ.OctetString.tagSet.tagImplicitly(\n-        tag.Tag(tag.tagClassUniversal, tag.tagFormatSimple, 21)\n-    )\n-\n-\n-class IA5String(univ.OctetString):\n-    tagSet = univ.OctetString.tagSet.tagImplicitly(\n-        tag.Tag(tag.tagClassUniversal, tag.tagFormatSimple, 22)\n-    )\n-\n-\n-class GraphicString(univ.OctetString):\n-    tagSet = univ.OctetString.tagSet.tagImplicitly(\n-        tag.Tag(tag.tagClassUniversal, tag.tagFormatSimple, 25)\n-    )\n-\n-\n-class VisibleString(univ.OctetString):\n-    tagSet = univ.OctetString.tagSet.tagImplicitly(\n-        tag.Tag(tag.tagClassUniversal, tag.tagFormatSimple, 26)\n-    )\n-\n-\n-class GeneralString(univ.OctetString):\n-    tagSet = univ.OctetString.tagSet.tagImplicitly(\n-        tag.Tag(tag.tagClassUniversal, tag.tagFormatSimple, 27)\n-    )\n-\n-\n-class UniversalString(univ.OctetString):\n-    tagSet = univ.OctetString.tagSet.tagImplicitly(\n-        tag.Tag(tag.tagClassUniversal, tag.tagFormatSimple, 28)\n-    )\n-\n-\n-class BMPString(univ.OctetString):\n-    tagSet = univ.OctetString.tagSet.tagImplicitly(\n-        tag.Tag(tag.tagClassUniversal, tag.tagFormatSimple, 30)\n-    )\ndiff --git a/src/xmlsec/rsa_x509_pem/pyasn1/type/constraint.py b/src/xmlsec/rsa_x509_pem/pyasn1/type/constraint.py\ndeleted file mode 100644\n--- a/src/xmlsec/rsa_x509_pem/pyasn1/type/constraint.py\n+++ /dev/null\n@@ -1,224 +0,0 @@\n-\"\"\"\n-   ASN.1 subtype constraints classes.\n-\n-   Constraints are relatively rare, but every ASN1 object\n-   is doing checks all the time for whether they have any\n-   constraints and whether they are applicable to the object.\n-\n-   What we're going to do is define objects/functions that\n-   can be called unconditionally if they are present, and that\n-   are simply not present if there are no constraints.\n-\n-   Original concept and code by Mike C. Fletcher.\n-\"\"\"\n-import types\n-import string\n-from .. import error\n-\n-\n-class AbstractConstraint:\n-    \"\"\"Abstract base-class for constraint objects\n-\n-       Constraints should be stored in a simple sequence in the\n-       namespace of their client Asn1Item sub-classes.\n-    \"\"\"\n-\n-    def __init__(self, *values):\n-        self._valueMap = {}\n-        self._setValues(values)\n-        self.__hashedValues = None\n-\n-    def __call__(self, value, idx=None):\n-        try:\n-            self._testValue(value, idx)\n-        except error.ValueConstraintError, why:\n-            raise error.ValueConstraintError('%s failed at: %s' % (\n-                self, why\n-            ))\n-\n-    def __repr__(self):\n-        return '%s(%s)' % (\n-            self.__class__.__name__,\n-            string.join(map(lambda x: str(x), self._values), ', ')\n-        )\n-\n-    # __cmp__ must accompany __hash__\n-    def __cmp__(self, other):\n-        return self is other and 0 or cmp(\n-            (self.__class__, self._values), other\n-        )\n-\n-    def __eq__(self, other):\n-        return self is other or not cmp(\n-            (self.__class__, self._values), other\n-        )\n-\n-    def __hash__(self):\n-        if self.__hashedValues is None:\n-            self.__hashedValues = hash((self.__class__, self._values))\n-        return self.__hashedValues\n-\n-    def _setValues(self, values):\n-        self._values = values\n-\n-    def _testValue(self, value, idx):\n-        raise error.ValueConstraintError(value)\n-\n-    # Constraints derivation logic\n-    def getValueMap(self):\n-        return self._valueMap\n-\n-    def isSuperTypeOf(self, otherConstraint):\n-        return otherConstraint.getValueMap().has_key(self) or \\\n-               otherConstraint is self or otherConstraint == self\n-\n-    def isSubTypeOf(self, otherConstraint):\n-        return self._valueMap.has_key(otherConstraint) or \\\n-               otherConstraint is self or otherConstraint == self\n-\n-\n-class SingleValueConstraint(AbstractConstraint):\n-    \"\"\"Value must be part of defined values constraint\"\"\"\n-\n-    def _testValue(self, value, idx):\n-        # XXX index vals for performance?\n-        if value not in self._values:\n-            raise error.ValueConstraintError(value)\n-\n-\n-class ContainedSubtypeConstraint(AbstractConstraint):\n-    \"\"\"Value must satisfy all of defined set of constraints\"\"\"\n-\n-    def _testValue(self, value, idx):\n-        for c in self._values:\n-            c(value, idx)\n-\n-\n-class ValueRangeConstraint(AbstractConstraint):\n-    \"\"\"Value must be within start and stop values (inclusive)\"\"\"\n-\n-    def _testValue(self, value, idx):\n-        if value < self.start or value > self.stop:\n-            raise error.ValueConstraintError(value)\n-\n-    def _setValues(self, values):\n-        if len(values) != 2:\n-            raise error.PyAsn1Error(\n-                '%s: bad constraint values' % (self.__class__.__name__,)\n-            )\n-        self.start, self.stop = values\n-        if self.start > self.stop:\n-            raise error.PyAsn1Error(\n-                '%s: screwed constraint values (start > stop): %s > %s' % (\n-                    self.__class__.__name__,\n-                    self.start, self.stop\n-                )\n-            )\n-        AbstractConstraint._setValues(self, values)\n-\n-\n-class ValueSizeConstraint(ValueRangeConstraint):\n-    \"\"\"len(value) must be within start and stop values (inclusive)\"\"\"\n-\n-    def _testValue(self, value, idx):\n-        l = len(value)\n-        if l < self.start or l > self.stop:\n-            raise error.ValueConstraintError(value)\n-\n-\n-class PermittedAlphabetConstraint(SingleValueConstraint):\n-    pass\n-\n-# This is a bit kludgy, meaning two op modes within a single constraing\n-class InnerTypeConstraint(AbstractConstraint):\n-    \"\"\"Value must satisfy type and presense constraints\"\"\"\n-\n-    def _testValue(self, value, idx):\n-        if self.__singleTypeConstraint:\n-            self.__singleTypeConstraint(value)\n-        elif self.__multipleTypeConstraint:\n-            if not self.__multipleTypeConstraint.has_key(idx):\n-                raise error.ValueConstraintError(value)\n-            constraint, status = self.__multipleTypeConstraint[idx]\n-            if status == 'ABSENT':   # XXX presense is not checked!\n-                raise error.ValueConstraintError(value)\n-            constraint(value)\n-\n-    def _setValues(self, values):\n-        self.__multipleTypeConstraint = {}\n-        self.__singleTypeConstraint = None\n-        for v in values:\n-            if type(v) == types.TupleType:\n-                self.__multipleTypeConstraint[v[0]] = v[1], v[2]\n-            else:\n-                self.__singleTypeConstraint = v\n-        AbstractConstraint._setValues(self, values)\n-\n-# Boolean ops on constraints \n-\n-class ConstraintsExclusion(AbstractConstraint):\n-    \"\"\"Value must not fit the single constraint\"\"\"\n-\n-    def _testValue(self, value, idx):\n-        try:\n-            self._values[0](value, idx)\n-        except error.ValueConstraintError:\n-            return\n-        else:\n-            raise error.ValueConstraintError(value)\n-\n-    def _setValues(self, values):\n-        if len(values) != 1:\n-            raise error.PyAsn1Error('Single constraint expected')\n-        AbstractConstraint._setValues(self, values)\n-\n-\n-class AbstractConstraintSet(AbstractConstraint):\n-    \"\"\"Value must not satisfy the single constraint\"\"\"\n-\n-    def __getitem__(self, idx):\n-        return self._values[idx]\n-\n-    def __add__(self, value):\n-        return self.__class__(self, value)\n-\n-    def __radd__(self, value):\n-        return self.__class__(self, value)\n-\n-    def __len__(self):\n-        return len(self._values)\n-\n-    # Constraints inclusion in sets\n-\n-    def _setValues(self, values):\n-        self._values = values\n-        for v in values:\n-            self._valueMap[v] = 1\n-            self._valueMap.update(v.getValueMap())\n-\n-\n-class ConstraintsIntersection(AbstractConstraintSet):\n-    \"\"\"Value must satisfy all constraints\"\"\"\n-\n-    def _testValue(self, value, idx):\n-        for v in self._values:\n-            v(value, idx)\n-\n-\n-class ConstraintsUnion(AbstractConstraintSet):\n-    \"\"\"Value must satisfy at least one constraint\"\"\"\n-\n-    def _testValue(self, value, idx):\n-        for v in self._values:\n-            try:\n-                v(value, idx)\n-            except error.ValueConstraintError:\n-                pass\n-            else:\n-                return\n-        raise error.ValueConstraintError(\n-            'all of %s failed for %s' % (self._values, value)\n-        )\n-\n-# XXX\n-# add tests for type check\ndiff --git a/src/xmlsec/rsa_x509_pem/pyasn1/type/error.py b/src/xmlsec/rsa_x509_pem/pyasn1/type/error.py\ndeleted file mode 100644\n--- a/src/xmlsec/rsa_x509_pem/pyasn1/type/error.py\n+++ /dev/null\n@@ -1,4 +0,0 @@\n-from ..error import PyAsn1Error\n-\n-class ValueConstraintError(PyAsn1Error):\n-    pass\ndiff --git a/src/xmlsec/rsa_x509_pem/pyasn1/type/namedtype.py b/src/xmlsec/rsa_x509_pem/pyasn1/type/namedtype.py\ndeleted file mode 100644\n--- a/src/xmlsec/rsa_x509_pem/pyasn1/type/namedtype.py\n+++ /dev/null\n@@ -1,159 +0,0 @@\n-# NamedType specification for constructed types\n-from .. import error\n-\n-\n-class NamedType:\n-    isOptional = 0\n-    isDefaulted = 0\n-\n-    def __init__(self, name, t):\n-        self.__name = name\n-        self.__type = t\n-\n-    def __repr__(self):\n-        return '%s(%s, %s)' % (\n-            self.__class__.__name__, repr(self.__name), repr(self.__type)\n-        )\n-\n-    def getType(self):\n-        return self.__type\n-\n-    def getName(self):\n-        return self.__name\n-\n-    def __getitem__(self, idx):\n-        if idx == 0:\n-            return self.__name\n-        if idx == 1:\n-            return self.__type\n-        raise IndexError()\n-\n-\n-class OptionalNamedType(NamedType):\n-    isOptional = 1\n-\n-\n-class DefaultedNamedType(NamedType):\n-    isDefaulted = 1\n-\n-\n-class NamedTypes:\n-    def __init__(self, *namedTypes):\n-        self.__namedTypes = namedTypes\n-        self.__minTagSet = None\n-        self.__typeMap = {}\n-        self.__tagMap = {}\n-        self.__nameMap = {}\n-        self.__ambigiousTypes = {}\n-\n-    def __repr__(self):\n-        r = '%s(' % self.__class__.__name__\n-        for n in self.__namedTypes:\n-            r = r + '%s, ' % repr(n)\n-        return r + ')'\n-\n-    def __getitem__(self, idx):\n-        return self.__namedTypes[idx]\n-\n-    def __nonzero__(self):\n-        if self.__namedTypes:\n-            return 1\n-        else:\n-            return 0\n-\n-    def __len__(self):\n-        return len(self.__namedTypes)\n-\n-    def getTypeByPosition(self, idx):\n-        try:\n-            return self.__namedTypes[idx].getType()\n-        except IndexError:\n-            raise error.PyAsn1Error('Type position out of range')\n-\n-    def getPositionByType(self, tagSet):\n-        if not self.__tagMap:\n-            idx = len(self.__namedTypes)\n-            while idx > 0:\n-                idx = idx - 1\n-                for t in self.__namedTypes[idx].getType().getTypeMap().keys():\n-                    if self.__tagMap.has_key(t):\n-                        raise error.PyAsn1Error('Duplicate type %s' % t)\n-                    self.__tagMap[t] = idx\n-        try:\n-            return self.__tagMap[tagSet]\n-        except KeyError:\n-            raise error.PyAsn1Error('Type %s not found' % tagSet)\n-\n-    def getNameByPosition(self, idx):\n-        try:\n-            return self.__namedTypes[idx].getName()\n-        except IndexError:\n-            raise error.PyAsn1Error('Type position out of range')\n-\n-    def getPositionByName(self, name):\n-        if not self.__nameMap:\n-            idx = len(self.__namedTypes)\n-            while idx > 0:\n-                idx = idx - 1\n-                n = self.__namedTypes[idx].getName()\n-                if self.__nameMap.has_key(n):\n-                    raise error.PyAsn1Error('Duplicate name %s' % n)\n-                self.__nameMap[n] = idx\n-        try:\n-            return self.__nameMap[name]\n-        except KeyError:\n-            raise error.PyAsn1Error('Name %s not found' % name)\n-\n-    def __buildAmbigiousTagMap(self):\n-        ambigiousTypes = ()\n-        idx = len(self.__namedTypes)\n-        while idx > 0:\n-            idx = idx - 1\n-            t = self.__namedTypes[idx]\n-            if t.isOptional or t.isDefaulted:\n-                ambigiousTypes = (t, ) + ambigiousTypes\n-            else:\n-                ambigiousTypes = (t, )\n-            self.__ambigiousTypes[idx] = apply(NamedTypes, ambigiousTypes)\n-\n-    def getTypeMapNearPosition(self, idx):\n-        if not self.__ambigiousTypes:\n-            self.__buildAmbigiousTagMap()\n-        try:\n-            return self.__ambigiousTypes[idx].getTypeMap()\n-        except KeyError:\n-            raise error.PyAsn1Error('Type position out of range')\n-\n-    def getPositionNearType(self, tagSet, idx):\n-        if not self.__ambigiousTypes:\n-            self.__buildAmbigiousTagMap()\n-        try:\n-            return idx + self.__ambigiousTypes[idx].getPositionByType(tagSet)\n-        except KeyError:\n-            raise error.PyAsn1Error('Type position out of range')\n-\n-    def genMinTagSet(self):\n-        if self.__minTagSet is None:\n-            for t in self.__namedTypes:\n-                __type = t.getType()\n-                tagSet = getattr(__type, 'getMinTagSet', __type.getTagSet)()\n-                if self.__minTagSet is None or tagSet < self.__minTagSet:\n-                    self.__minTagSet = tagSet\n-        return self.__minTagSet\n-\n-    def getTypeMap(self, uniq=None):\n-        if not self.__typeMap:\n-            for t in self.__namedTypes:\n-                __type = t.getType()\n-                typeMap = __type.getTypeMap()\n-                if uniq:\n-                    for k in typeMap.keys():\n-                        if self.__typeMap.has_key(k):\n-                            raise error.PyAsn1Error(\n-                                'Duplicate type %s in map %s' % (k, self.__typeMap)\n-                            )\n-                        self.__typeMap[k] = __type\n-                else:\n-                    for k in typeMap.keys():\n-                        self.__typeMap[k] = __type\n-        return self.__typeMap\ndiff --git a/src/xmlsec/rsa_x509_pem/pyasn1/type/namedval.py b/src/xmlsec/rsa_x509_pem/pyasn1/type/namedval.py\ndeleted file mode 100644\n--- a/src/xmlsec/rsa_x509_pem/pyasn1/type/namedval.py\n+++ /dev/null\n@@ -1,53 +0,0 @@\n-# ASN.1 named integers\n-from  types import TupleType\n-from .. import error\n-\n-__all__ = ['NamedValues']\n-\n-\n-class NamedValues:\n-    def __init__(self, *namedValues):\n-        self.nameToValIdx = {}\n-        self.valToNameIdx = {}\n-        self.namedValues = ()\n-        automaticVal = 1\n-        for namedValue in namedValues:\n-            if type(namedValue) == TupleType:\n-                name, val = namedValue\n-            else:\n-                name = namedValue\n-                val = automaticVal\n-            if self.nameToValIdx.has_key(name):\n-                raise error.PyAsn1Error('Duplicate name %s' % name)\n-            self.nameToValIdx[name] = val\n-            if self.valToNameIdx.has_key(val):\n-                raise error.PyAsn1Error('Duplicate value %s' % name)\n-            self.valToNameIdx[val] = name\n-            self.namedValues = self.namedValues + ((name, val),)\n-            automaticVal = automaticVal + 1\n-\n-    def __str__(self):\n-        return str(self.namedValues)\n-\n-    def getName(self, value):\n-        return self.valToNameIdx.get(value)\n-\n-    def getValue(self, name):\n-        return self.nameToValIdx.get(name)\n-\n-    def __getitem__(self, i):\n-        return self.namedValues[i]\n-\n-    def __len__(self):\n-        return len(self.namedValues)\n-\n-    def __add__(self, namedValues):\n-        return apply(self.__class__, self.namedValues + namedValues)\n-\n-    def __radd__(self, namedValues):\n-        return apply(self.__class__, namedValues + tuple(self))\n-\n-    def clone(self, *namedValues):\n-        return apply(self.__class__, tuple(self) + namedValues)\n-\n-# XXX clone/subtype?\ndiff --git a/src/xmlsec/rsa_x509_pem/pyasn1/type/tag.py b/src/xmlsec/rsa_x509_pem/pyasn1/type/tag.py\ndeleted file mode 100644\n--- a/src/xmlsec/rsa_x509_pem/pyasn1/type/tag.py\n+++ /dev/null\n@@ -1,145 +0,0 @@\n-# ASN.1 types tags\n-try:\n-    from sys import version_info\n-except ImportError:\n-    version_info = (0, 0)   # a really early version\n-from operator import getslice\n-from types import SliceType\n-from string import join\n-from .. import error\n-\n-tagClassUniversal = 0x00\n-tagClassApplication = 0x40\n-tagClassContext = 0x80\n-tagClassPrivate = 0xC0\n-\n-tagFormatSimple = 0x00\n-tagFormatConstructed = 0x20\n-\n-tagCategoryImplicit = 0x01\n-tagCategoryExplicit = 0x02\n-tagCategoryUntagged = 0x04\n-\n-\n-class Tag:\n-    def __init__(self, tagClass, tagFormat, tagId):\n-        if tagId < 0:\n-            raise error.PyAsn1Error(\n-                'Negative tag ID (%s) not allowed' % tagId\n-            )\n-        self.__tag = (tagClass, tagFormat, tagId)\n-        self.__uniqTag = (tagClass, tagId)\n-        self.__hashedUniqTag = hash(self.__uniqTag)\n-\n-    def __repr__(self):\n-        return '%s(tagClass=%s, tagFormat=%s, tagId=%s)' % (\n-            (self.__class__.__name__,) + self.__tag\n-        )\n-\n-    def __cmp__(self, other):\n-        return cmp(self.__uniqTag, other)\n-\n-    def __eq__(self, other):\n-        return self is other or self.__hashedUniqTag == other\n-\n-    def __ne__(self, other):\n-        return not (self is other) and self.__hashedUniqTag != other\n-\n-    def __hash__(self):\n-        return self.__hashedUniqTag\n-\n-    def __getitem__(self, idx):\n-        return self.__tag[idx]\n-\n-    def __and__(self, (tagClass, tagFormat, tagId)):\n-        return self.__class__(\n-            self.__tag & tagClass, self.__tag & tagFormat, self.__tag & tagId\n-        )\n-\n-    def __or__(self, (tagClass, tagFormat, tagId)):\n-        return self.__class__(\n-            self.__tag[0] | tagClass, self.__tag[1] | tagFormat, self.__tag[2] | tagId\n-        )\n-\n-\n-class TagSet:\n-    def __init__(self, baseTag=(), *superTags):\n-        self.__baseTag = baseTag\n-        self.__superTags = superTags\n-        self.__hashedSuperTags = hash(superTags)\n-        self.__lenOfSuperTags = len(superTags)\n-\n-    def __repr__(self):\n-        return '%s(%s)' % (\n-            self.__class__.__name__,\n-            join(map(lambda x: repr(x), self.__superTags), ', ')\n-        )\n-\n-    def __add__(self, superTag):\n-        return apply(\n-            self.__class__, (self.__baseTag,) + self.__superTags + (superTag,)\n-        )\n-\n-    def __radd__(self, superTag):\n-        return apply(\n-            self.__class__, (self.__baseTag, superTag) + self.__superTags\n-        )\n-\n-    def tagExplicitly(self, superTag):\n-        tagClass, tagFormat, tagId = superTag\n-        if tagClass == tagClassUniversal:\n-            raise error.PyAsn1Error(\n-                'Can\\'t tag with UNIVERSAL-class tag'\n-            )\n-        if tagFormat != tagFormatConstructed:\n-            superTag = Tag(tagClass, tagFormatConstructed, tagId)\n-        return self + superTag\n-\n-    def tagImplicitly(self, superTag):\n-        tagClass, tagFormat, tagId = superTag\n-        if self.__superTags:\n-            superTag = Tag(tagClass, self.__superTags[-1][1], tagId)\n-        return self[:-1] + superTag\n-\n-    def getBaseTag(self):\n-        return self.__baseTag\n-\n-    def __getitem__(self, idx):\n-        if type(idx) == SliceType:\n-            return apply(self.__class__,\n-                         (self.__baseTag,) + getslice(self.__superTags,\n-                                                      idx.start, idx.stop))\n-        return self.__superTags[idx]\n-\n-    if version_info < (2, 0):\n-        def __getslice__(self, i, j):\n-            return self[max(0, i):max(0, j):]\n-\n-    def __cmp__(self, other):\n-        return cmp(self.__superTags, other)\n-\n-    def __eq__(self, other):\n-        return self is other or self.__hashedSuperTags == other\n-\n-    def __ne__(self, other):\n-        return not (self is other) and self.__hashedSuperTags != other\n-\n-    def __hash__(self):\n-        return self.__hashedSuperTags\n-\n-    def __len__(self):\n-        return self.__lenOfSuperTags\n-\n-    def isSuperTagSetOf(self, tagSet):\n-        if len(tagSet) < self.__lenOfSuperTags:\n-            return\n-        idx = self.__lenOfSuperTags - 1\n-        while idx >= 0:\n-            if self.__superTags[idx] != tagSet[idx]:\n-                return\n-            idx = idx - 1\n-        return 1\n-\n-\n-def initTagSet(tag):\n-    return TagSet(tag, tag)\ndiff --git a/src/xmlsec/rsa_x509_pem/pyasn1/type/univ.py b/src/xmlsec/rsa_x509_pem/pyasn1/type/univ.py\ndeleted file mode 100644\n--- a/src/xmlsec/rsa_x509_pem/pyasn1/type/univ.py\n+++ /dev/null\n@@ -1,662 +0,0 @@\n-# ASN.1 \"universal\" data types\n-#\n-# Modified to support __items__ (leifj@mnt.se)\n-#\n-import string\n-import types\n-import operator\n-from . import base, tag, constraint, namedtype, namedval\n-from .. import error\n-\n-\n-# \"Simple\" ASN.1 types (yet incomplete)\n-\n-\n-class Integer(base.AbstractNumerableAsn1Item):\n-    tagSet = tag.initTagSet(\n-        tag.Tag(tag.tagClassUniversal, tag.tagFormatSimple, 0x02)\n-    )\n-\n-    #    def __coerce__(self, other): return long(self), long(other)\n-    def __and__(self, value):\n-        return self.clone(self._value & value)\n-\n-    def __rand__(self, value):\n-        return self.clone(value & self._value)\n-\n-    def __or__(self, value):\n-        return self.clone(self._value | value)\n-\n-    def __ror__(self, value):\n-        return self.clone(value | self._value)\n-\n-    def __xor__(self, value):\n-        return self.clone(self._value ^ value)\n-\n-    def __rxor__(self, value):\n-        return self.clone(value ^ self._value)\n-\n-    def __add__(self, value):\n-        return self.clone(self._value + value)\n-\n-    def __radd__(self, value):\n-        return self.clone(value + self._value)\n-\n-    def __sub__(self, value):\n-        return self.clone(self._value - value)\n-\n-    def __rsub__(self, value):\n-        return self.clone(value - self._value)\n-\n-    def __mul__(self, value):\n-        return self.clone(self._value * value)\n-\n-    def __rmul__(self, value):\n-        return self.clone(value * self._value)\n-\n-    def __div__(self, value):\n-        return self.clone(self._value / value)\n-\n-    def __rdiv__(self, value):\n-        return self.clone(value / self._value)\n-\n-    def __mod__(self, value):\n-        return self.clone(self._value % value)\n-\n-    def __rmod__(self, value):\n-        return self.clone(value % self._value)\n-\n-    def __pow__(self, value, modulo=None):\n-        return self.clone(pow(self._value, value, modulo))\n-\n-    def __rpow__(self, value):\n-        return self.clone(pow(value, self._value))\n-\n-    def __lshift__(self, value):\n-        return self.clone(self._value << value)\n-\n-    def __rshift__(self, value):\n-        return self.clone(self._value >> value)\n-\n-    def __int__(self):\n-        return int(self._value)\n-\n-    def __long__(self):\n-        return long(self._value)\n-\n-    def __float__(self):\n-        return float(self._value)\n-\n-    def __abs__(self):\n-        return abs(self._value)\n-\n-    def __index__(self):\n-        return int(self._value)\n-\n-    def prettyIn(self, value):\n-        if type(value) != types.StringType:\n-            return long(value)\n-        r = self.named_values.getValue(value)\n-        if r is not None:\n-            return r\n-        try:\n-            return string.atoi(value)\n-        except:\n-            try:\n-                return string.atol(value)\n-            except:\n-                raise error.PyAsn1Error(\n-                    'Can\\'t coerce %s into integer' % value\n-                )\n-\n-    def prettyOut(self, value):\n-        r = self.named_values.getName(value)\n-        if r is not None:\n-            return '%s(%s)' % (r, value)\n-        else:\n-            return str(value)\n-\n-\n-class Boolean(Integer):\n-    tagSet = tag.initTagSet(\n-        tag.Tag(tag.tagClassUniversal, tag.tagFormatSimple, 0x01),\n-    )\n-    subtypeSpec = Integer.subtypeSpec + constraint.SingleValueConstraint(0, 1)\n-    namedValues = Integer.namedValues.clone(('False', 0), ('True', 1))\n-\n-\n-class BitString(base.AbstractNumerableAsn1Item):\n-    tagSet = tag.initTagSet(\n-        tag.Tag(tag.tagClassUniversal, tag.tagFormatSimple, 0x03)\n-    )\n-\n-    def __str__(self):\n-        return str(tuple(self))\n-\n-    # Immutable sequence object protocol\n-\n-    def __len__(self):\n-        return len(self._value)\n-\n-    def __getitem__(self, i):\n-        if type(i) == types.SliceType:\n-            return self.clone(operator.getslice(self._value, i.start, i.stop))\n-        else:\n-            return self._value[i]\n-\n-    def __add__(self, value):\n-        return self.clone(self._value + value)\n-\n-    def __radd__(self, value):\n-        return self.clone(value + self._value)\n-\n-    def __mul__(self, value):\n-        return self.clone(self._value * value)\n-\n-    def __rmul__(self, value):\n-        return self.__mul__(value)\n-\n-    # They won't be defined if version is at least 2.0 final\n-    if base.version_info < (2, 0):\n-        def __getslice__(self, i, j):\n-            return self[max(0, i):max(0, j):]\n-\n-    def prettyIn(self, value):\n-        r = []\n-        if not value:\n-            return ()\n-        elif type(value) != types.StringType:\n-            return value\n-        elif value[0] == '\\'':\n-            if value[-2:] == '\\'B':\n-                for v in value[1:-2]:\n-                    r.append(int(v))\n-            elif value[-2:] == '\\'H':\n-                for v in value[1:-2]:\n-                    i = 4\n-                    v = string.atoi(v, 16)\n-                    while i:\n-                        i = i - 1\n-                        r.append((v >> i) & 0x01)\n-            else:\n-                raise error.PyAsn1Error(\n-                    'Bad bitstring value notation %s' % value\n-                )\n-        else:\n-            for i in string.split(value, ','):\n-                i = self.named_values.getValue(i)\n-                if i is None:\n-                    raise error.PyAsn1Error(\n-                        'Unknown identifier \\'%s\\'' % i\n-                    )\n-                if i >= len(r):\n-                    r.extend([0] * (i - len(r) + 1))\n-                r[i] = 1\n-        return tuple(r)\n-\n-    def prettyOut(self, value):\n-        return '\\'%s\\'B' % string.join(map(str, value), '')\n-\n-\n-class OctetString(base.AbstractSimpleAsn1Item):\n-    tagSet = tag.initTagSet(\n-        tag.Tag(tag.tagClassUniversal, tag.tagFormatSimple, 0x04)\n-    )\n-\n-    def prettyOut(self, value):\n-        return str(value)\n-\n-    def prettyIn(self, value):\n-        return str(value)\n-\n-    # Immutable sequence object protocol\n-\n-    def __len__(self):\n-        return len(self._value)\n-\n-    def __getitem__(self, i):\n-        if type(i) == types.SliceType:\n-            return self.clone(operator.getslice(self._value, i.start, i.stop))\n-        else:\n-            return self._value[i]\n-\n-    def __add__(self, value):\n-        return self.clone(self._value + value)\n-\n-    def __radd__(self, value):\n-        return self.clone(value + self._value)\n-\n-    def __mul__(self, value):\n-        return self.clone(self._value * value)\n-\n-    def __rmul__(self, value):\n-        return self.__mul__(value)\n-\n-    # They won't be defined if version is at least 2.0 final\n-    if base.version_info < (2, 0):\n-        def __getslice__(self, i, j):\n-            return self[max(0, i):max(0, j):]\n-\n-\n-class Null(OctetString):\n-    defaultValue = ''  # This is tightly constrained\n-    tagSet = tag.initTagSet(\n-        tag.Tag(tag.tagClassUniversal, tag.tagFormatSimple, 0x05)\n-    )\n-    subtypeSpec = OctetString.subtypeSpec + constraint.SingleValueConstraint('')\n-\n-\n-class ObjectIdentifier(base.AbstractSimpleAsn1Item):\n-    tagSet = tag.initTagSet(\n-        tag.Tag(tag.tagClassUniversal, tag.tagFormatSimple, 0x06)\n-    )\n-\n-    def __add__(self, other):\n-        return self.clone(self._value + other)\n-\n-    def __radd__(self, other):\n-        return self.clone(other + self._value)\n-\n-    # Sequence object protocol\n-\n-    def __len__(self):\n-        return len(self._value)\n-\n-    def __getitem__(self, i):\n-        if type(i) == types.SliceType:\n-            return self.clone(\n-                operator.getslice(self._value, i.start, i.stop)\n-            )\n-        else:\n-            return self._value[i]\n-\n-    # They won't be defined if version is at least 2.0 final\n-    if base.version_info < (2, 0):\n-        def __getslice__(self, i, j):\n-            return self[max(0, i):max(0, j):]\n-\n-    def index(self, suboid):\n-        return self._value.index(suboid)\n-\n-    def isPrefixOf(self, value):\n-        \"\"\"Returns true if argument OID resides deeper in the OID tree\"\"\"\n-        l = len(self._value)\n-        if l <= len(value):\n-            if self._value[:l] == value[:l]:\n-                return 1\n-        return 0\n-\n-    def prettyIn(self, value):\n-        \"\"\"Dotted -> tuple of numerics OID converter\"\"\"\n-        if isinstance(value, self.__class__):\n-            return tuple(value)\n-        elif type(value) is types.StringType:\n-            r = []\n-            for element in filter(None, string.split(value, '.')):\n-                try:\n-                    r.append(string.atoi(element, 0))\n-                except string.atoi_error:\n-                    try:\n-                        r.append(string.atol(element, 0))\n-                    except string.atol_error, why:\n-                        raise error.PyAsn1Error(\n-                            'Malformed Object ID %s at %s: %s' %\n-                            (str(value), self.__class__.__name__, why)\n-                        )\n-            value = tuple(r)\n-        elif type(value) is types.TupleType:\n-            pass\n-        else:\n-            value = tuple(value)\n-\n-        if filter(lambda x: x < 0, value):\n-            raise error.PyAsn1Error(\n-                'Negative sub-ID in %s at %s' % (value, self.__class__.__name__)\n-            )\n-\n-        return value\n-\n-    def prettyOut(self, value):\n-        \"\"\"Tuple of numerics -> dotted string OID converter\"\"\"\n-        r = []\n-        for subOid in value:\n-            r.append(str(subOid))\n-            if r[-1] and r[-1][-1] == 'L':\n-                r[-1][-1] = r[-1][:-1]\n-        return string.join(r, '.')\n-\n-\n-class Real(base.AbstractSimpleAsn1Item):\n-    tagSet = tag.initTagSet(\n-        tag.Tag(tag.tagClassUniversal, tag.tagFormatSimple, 0x09)\n-    )\n-\n-\n-class Enumerated(Integer):\n-    tagSet = tag.initTagSet(\n-        tag.Tag(tag.tagClassUniversal, tag.tagFormatSimple, 0x0A)\n-    )\n-\n-\n-# \"Structured\" ASN.1 types\n-\n-class SetOf(base.AbstractConstructedAsn1Item):\n-    componentType = None\n-    tagSet = tag.initTagSet(\n-        tag.Tag(tag.tagClassUniversal, tag.tagFormatConstructed, 0x11)\n-    )\n-\n-    def _cloneComponentValues(self, myClone, cloneValueFlag):\n-        idx = 0\n-        l = len(self._componentValues)\n-        while idx < l:\n-            c = self._componentValues[idx]\n-            if c is not None:\n-                if isinstance(c, base.AbstractConstructedAsn1Item):\n-                    myClone.setComponentByPosition(\n-                        idx, c.clone(cloneValueFlag=cloneValueFlag)\n-                    )\n-                else:\n-                    myClone.setComponentByPosition(idx, c.clone())\n-            idx = idx + 1\n-\n-    def _verifyComponent(self, idx, value):\n-        if self._componentType is not None and \\\n-                not self._componentType.isSuperTypeOf(value):\n-            raise error.PyAsn1Error('Component type error %s' % value)\n-\n-    def getComponentByPosition(self, idx):\n-        return self._componentValues[idx]\n-\n-    def setComponentByPosition(self, idx, value=None):\n-        l = len(self._componentValues)\n-        if idx >= l:\n-            self._componentValues = self._componentValues + (idx - l + 1) * [None]\n-        if value is None:\n-            if self._componentValues[idx] is None:\n-                if self._componentType is None:\n-                    raise error.PyAsn1Error('Component type not defined')\n-                self._componentValues[idx] = self._componentType.clone()\n-            return self\n-        elif type(value) != types.InstanceType:\n-            if self._componentType is None:\n-                raise error.PyAsn1Error('Component type not defined')\n-            if isinstance(self._componentType, base.AbstractSimpleAsn1Item):\n-                value = self._componentType.clone(value=value)\n-            else:\n-                raise error.PyAsn1Error('Instance value required')\n-        if self._componentType is not None:\n-            self._verifyComponent(idx, value)\n-        self._verifySubtypeSpec(value, idx)\n-        self._componentValues[idx] = value\n-        return self\n-\n-    def getComponentTypeMap(self):\n-        if self._componentType is not None:\n-            return self._componentType.getTypeMap()\n-\n-    def prettyPrint(self, scope=0):\n-        scope = scope + 1\n-        r = self.__class__.__name__ + ':\\n'\n-        for idx in range(len(self._componentValues)):\n-            r = r + ' ' * scope + self._componentValues[idx].prettyPrint(scope)\n-        return r\n-\n-\n-class SequenceOf(SetOf):\n-    tagSet = tag.initTagSet(\n-        tag.Tag(tag.tagClassUniversal, tag.tagFormatConstructed, 0x10)\n-    )\n-\n-\n-class SequenceAndSetBase(base.AbstractConstructedAsn1Item):\n-    componentType = namedtype.NamedTypes()\n-\n-    def _cloneComponentValues(self, myClone, cloneValueFlag):\n-        idx = 0\n-        l = len(self._componentValues)\n-        while idx < l:\n-            c = self._componentValues[idx]\n-            if c is not None:\n-                if isinstance(c, base.AbstractConstructedAsn1Item):\n-                    myClone.setComponentByPosition(\n-                        idx, c.clone(cloneValueFlag=cloneValueFlag)\n-                    )\n-                else:\n-                    myClone.setComponentByPosition(idx, c.clone())\n-            idx = idx + 1\n-\n-    def _verifyComponent(self, idx, value):\n-        componentType = self._componentType\n-        if componentType:\n-            if idx >= len(componentType):\n-                raise error.PyAsn1Error(\n-                    'Component type error out of range'\n-                )\n-            t = componentType[idx].getType()\n-            if not t.isSuperTypeOf(value):\n-                raise error.PyAsn1Error('Component type error %s vs %s' %\n-                                        (repr(t), repr(value)))\n-\n-    def getComponentByName(self, name):\n-        return self.getComponentByPosition(\n-            self._componentType.getPositionByName(name)\n-        )\n-\n-    def setComponentByName(self, name, value=None):\n-        return self.setComponentByPosition(\n-            self._componentType.getPositionByName(name), value\n-        )\n-\n-    def getComponentByPosition(self, idx):\n-        try:\n-            return self._componentValues[idx]\n-        except IndexError:\n-            if idx < len(self._componentType):\n-                return\n-            raise\n-\n-    def setComponentByPosition(self, idx, value=None):\n-        l = len(self._componentValues)\n-        if idx >= l:\n-            self._componentValues = self._componentValues + (idx - l + 1) * [None]\n-        if value is None:\n-            if self._componentValues[idx] is None:\n-                self._componentValues[idx] = self._componentType.getTypeByPosition(idx).clone()\n-            return self\n-        elif type(value) != types.InstanceType:\n-            t = self._componentType.getTypeByPosition(idx)\n-            if isinstance(t, base.AbstractSimpleAsn1Item):\n-                value = t.clone(value=value)\n-            else:\n-                raise error.PyAsn1Error('Instance value required')\n-        if self._componentType:\n-            self._verifyComponent(idx, value)\n-        self._verifySubtypeSpec(value, idx)\n-        self._componentValues[idx] = value\n-        return self\n-\n-    def getDefaultComponentByPosition(self, idx):\n-        if self._componentType and self._componentType[idx].isDefaulted:\n-            return self._componentType[idx].getType()\n-\n-    def getComponentType(self):\n-        if self._componentType:\n-            return self._componentType\n-\n-    def setDefaultComponents(self):\n-        idx = len(self._componentType)\n-        while idx:\n-            idx = idx - 1\n-            if self._componentType[idx].isDefaulted:\n-                if self.getComponentByPosition(idx) is None:\n-                    self.setComponentByPosition(idx)\n-            elif not self._componentType[idx].isOptional:\n-                if self.getComponentByPosition(idx) is None:\n-                    raise error.PyAsn1Error(\n-                        'Uninitialized component #%s at %s' % (idx, repr(self))\n-                    )\n-\n-    def prettyPrint(self, scope=0):\n-        scope = scope + 1\n-        r = self.__class__.__name__ + ':\\n'\n-        for idx in range(len(self._componentValues)):\n-            if self._componentValues[idx] is not None:\n-                r = r + ' ' * scope\n-                componentType = self.getComponentType()\n-                if componentType is None:\n-                    r = r + '??'\n-                else:\n-                    r = r + componentType.getNameByPosition(idx)\n-                r = '%s=%s\\n' % (\n-                    r, self._componentValues[idx].prettyPrint(scope)\n-                )\n-        return r\n-\n-    def __items__(self):\n-        return [self._componentValues[idx] for idx in range(len(self._componentValues))]\n-\n-\n-class Sequence(SequenceAndSetBase):\n-    tagSet = tag.initTagSet(\n-        tag.Tag(tag.tagClassUniversal, tag.tagFormatConstructed, 0x10)\n-    )\n-\n-    def getComponentTypeMapNearPosition(self, idx):\n-        return self._componentType.getTypeMapNearPosition(idx)\n-\n-    def getComponentPositionNearType(self, tagSet, idx):\n-        return self._componentType.getPositionNearType(tagSet, idx)\n-\n-\n-class Set(SequenceAndSetBase):\n-    tagSet = tag.initTagSet(\n-        tag.Tag(tag.tagClassUniversal, tag.tagFormatConstructed, 0x11)\n-    )\n-\n-    def getComponentByType(self, tagSet, innerFlag=0):\n-        c = self.getComponentByPosition(\n-            self._componentType.getPositionByType(tagSet)\n-        )\n-        if innerFlag and hasattr(c, 'getComponent'):\n-            # get inner component by inner tagSet\n-            return c.getComponent(1)\n-        else:\n-            # get outer component by inner tagSet\n-            return c\n-\n-    def setComponentByType(self, tagSet, value=None, innerFlag=0):\n-        idx = self._componentType.getPositionByType(tagSet)\n-        t = self._componentType.getTypeByPosition(idx)\n-        if innerFlag:  # set inner component by inner tagSet\n-            if t.getTagSet():\n-                self.setComponentByPosition(idx, value)\n-            else:\n-                t = self.setComponentByPosition(idx).getComponentByPosition(idx)\n-                t.setComponentByType(tagSet, value, innerFlag)\n-        else:  # set outer component by inner tagSet\n-            self.setComponentByPosition(idx, value)\n-\n-    def getComponentTypeMap(self):\n-        return self._componentType.getTypeMap(1)\n-\n-    def getComponentPositionByType(self, tagSet):\n-        return self._componentType.getPositionByType(tagSet)\n-\n-\n-class Choice(Set):\n-    tagSet = tag.TagSet()  # untagged\n-    sizeSpec = constraint.ConstraintsIntersection(\n-        constraint.ValueSizeConstraint(1, 1)\n-    )\n-\n-    def __cmp__(self, other):\n-        if self._componentValues:\n-            return cmp(self._componentValues[self._currentIdx], other)\n-        return -1\n-\n-    def verifySizeSpec(self):\n-        self._sizeSpec(\n-            ' ' * int(self.getComponent() is not None)  # hackerish XXX\n-        )\n-\n-    def _cloneComponentValues(self, myClone, cloneValueFlag):\n-        try:\n-            c = self.getComponent()\n-        except error.PyAsn1Error:\n-            pass\n-        else:\n-            tagSet = getattr(c, 'getEffectiveTagSet', c.getTagSet)()\n-            if isinstance(c, base.AbstractConstructedAsn1Item):\n-                myClone.setComponentByType(\n-                    tagSet, c.clone(cloneValueFlag=cloneValueFlag)\n-                )\n-            else:\n-                myClone.setComponentByType(tagSet, c.clone())\n-\n-    def setComponentByPosition(self, idx, value=None):\n-        l = len(self._componentValues)\n-        if idx >= l:\n-            self._componentValues = self._componentValues + (idx - l + 1) * [None]\n-        if hasattr(self, '_currentIdx'):\n-            self._componentValues[self._currentIdx] = None\n-        if value is None:\n-            if self._componentValues[idx] is None:\n-                self._componentValues[idx] = self._componentType.getTypeByPosition(idx).clone()\n-                self._currentIdx = idx\n-            return self\n-        elif type(value) != types.InstanceType:\n-            value = self._componentType.getTypeByPosition(idx).clone(\n-                value=value\n-            )\n-        if self._componentType:\n-            self._verifyComponent(idx, value)\n-        self._verifySubtypeSpec(value, idx)\n-        self._componentValues[idx] = value\n-        self._currentIdx = idx\n-        return self\n-\n-    def getMinTagSet(self):\n-        if self._tagSet:\n-            return self._tagSet\n-        else:\n-            return self._componentType.genMinTagSet()\n-\n-    def getEffectiveTagSet(self):\n-        if self._tagSet:\n-            return self._tagSet\n-        else:\n-            c = self.getComponent()\n-            return getattr(c, 'getEffectiveTagSet', c.getTagSet)()\n-\n-    def getTypeMap(self):\n-        if self._tagSet:\n-            return Set.getTypeMap(self)\n-        else:\n-            return Set.getComponentTypeMap(self)\n-\n-    def getComponent(self, innerFlag=0):\n-        if hasattr(self, '_currentIdx'):\n-            c = self._componentValues[self._currentIdx]\n-            if innerFlag and hasattr(c, 'getComponent'):\n-                return c.getComponent(innerFlag)\n-            else:\n-                return c\n-        else:\n-            raise error.PyAsn1Error('Component not chosen')\n-\n-    def getName(self, innerFlag=0):\n-        if hasattr(self, '_currentIdx'):\n-            if innerFlag:\n-                c = self._componentValues[self._currentIdx]\n-                if hasattr(c, 'getComponent'):\n-                    return c.getName(innerFlag)\n-            return self._componentType.getNameByPosition(self._currentIdx)\n-        else:\n-            raise error.PyAsn1Error('Component not chosen')\n-\n-    def setDefaultComponents(self):\n-        pass\n-\n-# XXX\n-# coercion rules?\ndiff --git a/src/xmlsec/rsa_x509_pem/pyasn1/type/useful.py b/src/xmlsec/rsa_x509_pem/pyasn1/type/useful.py\ndeleted file mode 100644\n--- a/src/xmlsec/rsa_x509_pem/pyasn1/type/useful.py\n+++ /dev/null\n@@ -1,14 +0,0 @@\n-# ASN.1 \"useful\" types\n-from . import char, tag\n-\n-\n-class GeneralizedTime(char.VisibleString):\n-    tagSet = char.VisibleString.tagSet.tagImplicitly(\n-        tag.Tag(tag.tagClassUniversal, tag.tagFormatSimple, 24)\n-    )\n-\n-\n-class UTCTime(char.VisibleString):\n-    tagSet = char.VisibleString.tagSet.tagImplicitly(\n-        tag.Tag(tag.tagClassUniversal, tag.tagFormatSimple, 23)\n-    )\ndiff --git a/src/xmlsec/rsa_x509_pem/rsa_pem.py b/src/xmlsec/rsa_x509_pem/rsa_pem.py\ndeleted file mode 100644\n--- a/src/xmlsec/rsa_x509_pem/rsa_pem.py\n+++ /dev/null\n@@ -1,156 +0,0 @@\n-#!/usr/bin/python\n-# -*- coding: utf-8 -*-\n-# Copyright \u00a92011 Andrew D. Yates\n-# andrewyates.name@gmail.com\n-#\n-# Modified and redistributed as part of pyXMLSecurity by leifj@mnt.se\n-# with permission from the original author\n-#\n-\"\"\"Generate RSA Key from PEM data.\n-\n-See examples/sshkey.py from pyasn1 for reference.\n-\n-Much of this module has been adapted from the pyasn1\n-source code example \"pyasn1/examples/sshkey.py\" [pyasn1].\n-\n-USE:\n-\n-.. code-block:: python\n-\n-data = open(\"cert.pem\").read()\n-dict = rsa_pem.parse(data)\n-n = dict['modulus']\n-e = dict['publicExponent']\n-d = dict['privateExponent']\n-\n-\n-REFERENCES:\n-\n-pyasn1\n-\"ASN.1 tools for Python\"\n-http://pyasn1.sourceforge.net/\n-\"\"\"\n-from .pyasn1.type import univ, namedtype, namedval\n-from .pyasn1.codec.der import decoder\n-from .utils import SingleAccessCallable\n-\n-der_decode = SingleAccessCallable(decoder.decode)\n-\n-from . import sequence_parser\n-\n-MAX = 16\n-\n-\n-class RSAPrivateParser(sequence_parser.SequenceParser):\n-    \"\"\"PKCS#1 compliant RSA private key structure.\n-  \"\"\"\n-    componentType = namedtype.NamedTypes(\n-        namedtype.NamedType('version', univ.Integer(namedValues=namedval.NamedValues(('two-prime', 0), ('multi', 1)))),\n-        # n\n-        namedtype.NamedType('modulus', univ.Integer()),\n-        # e\n-        namedtype.NamedType('publicExponent', univ.Integer()),\n-        # d\n-        namedtype.NamedType('privateExponent', univ.Integer()),\n-        # p\n-        namedtype.NamedType('prime1', univ.Integer()),\n-        # q\n-        namedtype.NamedType('prime2', univ.Integer()),\n-        # dp\n-        namedtype.NamedType('exponent1', univ.Integer()),\n-        # dq\n-        namedtype.NamedType('exponent2', univ.Integer()),\n-        # u or inverseQ\n-        namedtype.NamedType('coefficient', univ.Integer()),\n-    )\n-\n-\n-def parse(data, password=None):\n-    \"\"\"Return a simple dictionary of labeled numeric key elements from key data.\n-\n-  TO DO:\n-    support DSA signatures\n-    include support for encrypted private keys e.g. DES3\n-\n-  Args:\n-    data: str of bytes read from PEM encoded key file\n-    password: str of password to decrypt key [not supported]\n-  Returns:\n-    {str: value} of labeled RSA key elements s.t.:\n-      ['version'] = int of 0 or 1 meaning \"two-key\" or \"multi\" respectively\n-      ['modulus'] = int of RSA key value `n`\n-      ['publicExponent'] = int of RSA key value `e`\n-      ['privateExponent'] = int of RSA key value `d` [optional]\n-      ['prime1'] = int of RSA key value `p` [optional]\n-      ['prime2'] = int of RSA key value `q` [optional]\n-      ['exponent1'] = int of RSA key value `dp` [optional]\n-      ['exponent2'] = int of RSA key value `dq` [optional]\n-      ['coefficient'] = int of RSA key value `u` or `inverseQ` [optional]\n-      ['body'] = str of key DER binary in base64\n-      ['type'] = str of \"RSA PRIVATE\"\n-  \"\"\"\n-    lines = []\n-    ktype = None\n-    encryption = False\n-    # read in key lines from keydata string\n-    for s in data.splitlines():\n-        # skip file headers\n-        if '-----' == s[:5] and \"BEGIN\" in s:\n-            # Detect RSA or DSA keys\n-            if \"RSA\" in s:\n-                ktype = \"RSA\"\n-            elif \"DSA\" in s:\n-                ktype = \"DSA\"\n-            else:\n-                ktype = s.replace(\"-----\", \"\")\n-\n-        # skip cryptographic headers\n-        elif \":\" in s or \" \" in s:\n-            # detect encryption, if any\n-            if \"DEK-Info: \" == s[0:10]:\n-                encryption = s[10:]\n-        else:\n-            # include this b64 data for decoding\n-            lines.append(s.strip())\n-\n-    body = ''.join(lines)\n-    raw_data = body.decode(\"base64\")\n-\n-    # Private Key cipher (Not Handled)\n-    if encryption:\n-        raise NotImplementedError(\"Symmetric encryption is not supported. DEK-Info: %s\" % encryption)\n-\n-    # decode data string using RSA\n-    if ktype == 'RSA':\n-        asn1Spec = RSAPrivateParser()\n-    else:\n-        raise NotImplementedError(\"Only RSA is supported. Type was %s.\" % ktype)\n-\n-    key = der_decode(raw_data, asn1Spec=asn1Spec)[0]\n-\n-    # generate return dict base from key dict\n-    kdict = key.dict()\n-    # add base64 encoding and type to return dictionary\n-    kdict['body'] = body\n-    kdict['type'] = \"RSA PRIVATE\"\n-\n-    return kdict\n-\n-\n-def dict_to_tuple(dict):\n-    \"\"\"Return RSA PyCrypto tuple from parsed rsa private dict.\n-\n-  Args:\n-    dict: dict of {str: value} returned from `parse`\n-  Returns:\n-    tuple of (int) of RSA private key integers for PyCrypto key construction\n-  \"\"\"\n-    tuple = (\n-        dict['modulus'],\n-        dict['publicExponent'],\n-        dict['privateExponent'],\n-        dict['prime1'],\n-        dict['prime2'],\n-        dict['coefficient'],\n-    )\n-    return tuple\ndiff --git a/src/xmlsec/rsa_x509_pem/sequence_parser.py b/src/xmlsec/rsa_x509_pem/sequence_parser.py\ndeleted file mode 100644\n--- a/src/xmlsec/rsa_x509_pem/sequence_parser.py\n+++ /dev/null\n@@ -1,38 +0,0 @@\n-#!/usr/bin/python\n-# -*- coding: utf-8 -*-\n-# Copyright \u00a92011 Andrew D. Yates\n-# andrewyates.name@gmail.com\n-#\n-# Modified and redistributed as part of pyXMLSecurity by leifj@mnt.se\n-# with permission from the original author\n-#\n-\"\"\"Self-descriptive PEM decoder for 'univ.Sequence'.\n-\"\"\"\n-from .pyasn1.type import univ\n-\n-\n-class SequenceParser(univ.Sequence):\n-    \"\"\"Base type for self-reporting PEM binary format templates.\n-  x509_pem and rsa_pem use this like a \"Key Parser\" base class.\n-\n-  Properties:\n-    componentType: `namedtype.NamedTypes` instance; defined per child class\n-  \"\"\"\n-    # OVERRIDE\n-    componentType = None\n-\n-    def dict(self):\n-        \"\"\"Return simple dictionary of labeled key elements as simple types.\n-\n-    Returns:\n-      {str, value} where `value` is simple type like `long`\n-    \"\"\"\n-        sdict = {}\n-        for i in range(len(self._componentValues)):\n-            if self._componentValues[i] is not None:\n-                componentType = self.getComponentType()\n-                if componentType is not None:\n-                    name = componentType.getNameByPosition(i)\n-                    value = self._componentValues[i]._value\n-                    sdict[name] = value\n-        return sdict\ndiff --git a/src/xmlsec/rsa_x509_pem/utils.py b/src/xmlsec/rsa_x509_pem/utils.py\ndeleted file mode 100644\n--- a/src/xmlsec/rsa_x509_pem/utils.py\n+++ /dev/null\n@@ -1,40 +0,0 @@\n-__author__ = 'leifj'\n-\n-from multiprocessing import RLock\n-from threading import local\n-\n-\n-def _lock_for_object(o):\n-    thread_local = local()\n-    locks = getattr(thread_local, \"locks\", None)\n-\n-    if locks is None:\n-        thread_local.locks = dict()\n-\n-    if o not in thread_local.locks:\n-        thread_local.locks[o] = RLock()\n-\n-    return thread_local.locks[o]\n-\n-\n-class SingleAccessCallable(object):\n-\n-    def __init__(self, inner):\n-        self._i = inner\n-\n-    def __call__(self, *args, **kwargs):\n-        lock = _lock_for_object(self._i)\n-        locked = False\n-        try:\n-            lock.acquire()\n-            locked = True\n-            res = self._i(*args, **kwargs)\n-            lock.release()\n-            locked = False\n-            return res\n-        finally:\n-            if locked:\n-                try:\n-                    lock.release()\n-                except Error:\n-                    pass\ndiff --git a/src/xmlsec/rsa_x509_pem/x509_pem.py b/src/xmlsec/rsa_x509_pem/x509_pem.py\ndeleted file mode 100644\n--- a/src/xmlsec/rsa_x509_pem/x509_pem.py\n+++ /dev/null\n@@ -1,395 +0,0 @@\n-#!/usr/bin/python\n-# -*- coding: utf-8 -*-\n-# Copyright \u00a92011 Andrew D. Yates\n-# andrewyates.name@gmail.com\n-#\n-# Modified and redistributed as part of pyXMLSecurity by leifj@mnt.se\n-# with permission from the original author\n-#\n-\"\"\"Parse x509 PEM Certificates.\n-\n-The objective of this script is to parse elements from x509\n-certificates in PEM binary format which use RSA cryptographic keys for\n-use in XML digital signature (xmldsig) signatures and\n-verification. Much of this module has been adapted from the pyasn1\n-source code example \"pyasn1/examples/x509.py\" [pyasn1].\n-\n-USE:\n-\n->>> data = open(\"cert.pem\").read()\n-... dict = x509_pem.parse(data)\n-... n, e = dict['modulus'], dict['publicExponent']\n-... subject = dict['subject']\n-\n-REFERENCES:\n-\n-pyasn1\n-\"ASN.1 tools for Python\"\n-http://pyasn1.sourceforge.net/\n-\n-RFC5480\n-\"Elliptic Curve Cryptography Subject Public Key Information\"\n-http://www.ietf.org/rfc/rfc5480.txt\n-\n-X500attr\n-\"2.5.4 - X.500 attribute types\"\n-http://www.alvestrand.no/objectid/2.5.4.html\n-\n-X500email\n-\"1.2.840.113549.1.9.1 - e-mailAddress\"\n-http://www.alvestrand.no/objectid/1.2.840.113549.1.9.1.html\n-\"\"\"\n-import re\n-\n-from .pyasn1.type import tag, namedtype, namedval, univ, constraint, char, useful\n-from .pyasn1.codec.der import decoder\n-from .utils import SingleAccessCallable\n-\n-der_decode = SingleAccessCallable(decoder.decode)\n-\n-from .sequence_parser import SequenceParser\n-\n-\n-MAX = 1024\n-CERT_FILE = \"keys/cacert_pass_helloworld.pem\"\n-\n-RSA_ID = \"1.2.840.113549.1.1.1\"\n-RSA_SHA1_ID = \"1.2.840.113549.1.1.5\"\n-\n-RX_PUBLIC_KEY = re.compile(\"subjectPublicKey='([01]+)'B\")\n-RX_SUBJECT = re.compile(\" +subject=Name:.*?\\n\\n\\n\", re.M | re.S)\n-RX_SUBJECT_ATTR = re.compile(\"\"\"\n-RelativeDistinguishedName:.*?\n-type=(\\S+).*?\n-AttributeValue:\\n\\s+?\n-[^=]+=([^\\n]*)\\n\n-\"\"\", re.M | re.S | re.X)\n-\n-# abbreviated code map\n-X500_CODE_MAP = {\n-    '2.5.4.3': 'CN',  # commonName\n-    '2.5.4.6': 'C',  # countryName\n-    '2.5.4.7': 'L',  # localityName (City)\n-    '2.5.4.8': 'ST',  # stateOrProvinceName (State)\n-    '2.5.4.9': 'STREET',  # streetAddress\n-    '2.5.4.10': 'O',  # organizationName\n-    '2.5.4.11': 'OU',  # organizationalUnitName\n-    '2.5.4.12': 'T',  # title\n-    '1.2.840.113549.1.9.1': 'E',  # e-mailAddress\n-    '2.5.4.17': 'postalAddress'\n-}\n-\n-\n-class DirectoryString(univ.Choice):\n-    componentType = namedtype.NamedTypes(\n-        namedtype.NamedType('teletexString',\n-                            char.TeletexString().subtype(subtypeSpec=constraint.ValueSizeConstraint(1, MAX))),\n-        namedtype.NamedType('printableString',\n-                            char.PrintableString().subtype(subtypeSpec=constraint.ValueSizeConstraint(1, MAX))),\n-        namedtype.NamedType('universalString',\n-                            char.UniversalString().subtype(subtypeSpec=constraint.ValueSizeConstraint(1, MAX))),\n-        namedtype.NamedType('utf8String',\n-                            char.UTF8String().subtype(subtypeSpec=constraint.ValueSizeConstraint(1, MAX))),\n-        namedtype.NamedType('bmpString', char.BMPString().subtype(subtypeSpec=constraint.ValueSizeConstraint(1, MAX))),\n-        namedtype.NamedType('ia5String', char.IA5String().subtype(subtypeSpec=constraint.ValueSizeConstraint(1, MAX)))\n-    )\n-\n-\n-class AttributeValue(DirectoryString):\n-    def __str__(self):\n-        return self[1].__str__()\n-\n-\n-class AttributeType(univ.ObjectIdentifier):\n-    def __str__(self):\n-        oid = '.'.join(\"%d\" % x for x in self)\n-        if oid in X500_CODE_MAP:\n-            return X500_CODE_MAP[oid]\n-        else:\n-            return oid\n-\n-\n-class AttributeTypeAndValue(univ.Sequence):\n-    componentType = namedtype.NamedTypes(\n-        namedtype.NamedType('type', AttributeType()),\n-        namedtype.NamedType('value', AttributeValue())\n-    )\n-\n-    def __str__(self):\n-        return \"%s=%s\" % (self['type'], self['value'])\n-\n-\n-class RelativeDistinguishedName(univ.SetOf):\n-    componentType = AttributeTypeAndValue()\n-\n-    def __str__(self):\n-        return \"+\".join(avp.__str__() for avp in self)\n-\n-\n-class RDNSequence(univ.SequenceOf):\n-    componentType = RelativeDistinguishedName()\n-\n-    def __str__(self):\n-        return \"/\".join([rdn.__str__() for rdn in self])\n-\n-\n-class Name(univ.Choice):\n-    componentType = namedtype.NamedTypes(\n-        namedtype.NamedType('', RDNSequence())\n-    )\n-\n-    def __str__(self):\n-        return self[0].__str__()\n-\n-\n-class AlgorithmIdentifier(univ.Sequence):\n-    componentType = namedtype.NamedTypes(\n-        namedtype.NamedType('algorithm', univ.ObjectIdentifier()),\n-        namedtype.OptionalNamedType('parameters', univ.Null())\n-    )\n-\n-\n-class Extension(univ.Sequence):\n-    componentType = namedtype.NamedTypes(\n-        namedtype.NamedType('extnID', univ.ObjectIdentifier()),\n-        namedtype.DefaultedNamedType('critical', univ.Boolean('False')),\n-        namedtype.NamedType('extnValue', univ.OctetString())\n-    )\n-\n-\n-class Extensions(univ.SequenceOf):\n-    componentType = Extension()\n-    sizeSpec = univ.SequenceOf.sizeSpec + constraint.ValueSizeConstraint(1, MAX)\n-\n-\n-class SubjectPublicKeyInfo(univ.Sequence):\n-    componentType = namedtype.NamedTypes(\n-        namedtype.NamedType('algorithm', AlgorithmIdentifier()),\n-        namedtype.NamedType('subjectPublicKey', univ.BitString())\n-    )\n-\n-\n-class UniqueIdentifier(univ.BitString):\n-    pass\n-\n-\n-class Time(univ.Choice):\n-    componentType = namedtype.NamedTypes(\n-        namedtype.NamedType('utcTime', useful.UTCTime()),\n-        namedtype.NamedType('generalTime', useful.GeneralizedTime())\n-    )\n-\n-\n-class Validity(univ.Sequence):\n-    componentType = namedtype.NamedTypes(\n-        namedtype.NamedType('notBefore', Time()),\n-        namedtype.NamedType('notAfter', Time())\n-    )\n-\n-\n-class CertificateSerialNumber(univ.Integer):\n-    pass\n-\n-\n-class Version(univ.Integer):\n-    namedValues = namedval.NamedValues(\n-        ('v1', 0), ('v2', 1), ('v3', 2)\n-    )\n-\n-\n-class TBSCertificate(univ.Sequence):\n-    componentType = namedtype.NamedTypes(\n-        namedtype.DefaultedNamedType('version', Version('v1', tagSet=Version.tagSet.tagExplicitly(\n-            tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 0)))),\n-        namedtype.NamedType('serialNumber', CertificateSerialNumber()),\n-        namedtype.NamedType('signature', AlgorithmIdentifier()),\n-        namedtype.NamedType('issuer', Name()),\n-        namedtype.NamedType('validity', Validity()),\n-        namedtype.NamedType('subject', Name()),\n-        namedtype.NamedType('subjectPublicKeyInfo', SubjectPublicKeyInfo()),\n-        namedtype.OptionalNamedType('issuerUniqueID', UniqueIdentifier().subtype(\n-            implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 1))),\n-        namedtype.OptionalNamedType('subjectUniqueID', UniqueIdentifier().subtype(\n-            implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 2))),\n-        namedtype.OptionalNamedType('extensions', Extensions().subtype(\n-            explicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 3)))\n-    )\n-\n-\n-class Certificate(univ.Sequence):\n-    componentType = namedtype.NamedTypes(\n-        namedtype.NamedType('tbsCertificate', TBSCertificate()),\n-        namedtype.NamedType('signatureAlgorithm', AlgorithmIdentifier()),\n-        namedtype.NamedType('signatureValue', univ.BitString())\n-    )\n-\n-    def getSubject(self):\n-        return self['tbsCertificate']['subject'][0]\n-\n-    def get_subject(self):\n-        return self.getSubject()\n-\n-    def getIssuer(self):\n-        return self['tbsCertificate']['issuer'][0]\n-\n-    def get_issuer(self):\n-        return self.get_issuer()\n-\n-    def getValidity(self):\n-        return self['tbsCertificate']['validity']\n-\n-    def getNotAfter(self):\n-        return self.getValidity()['notAfter'][0]\n-\n-    def get_notAfter(self):\n-        return self.getNotAfter()\n-\n-    def getNotBefore(self):\n-        return self.getValidity()['notBefore'][0]\n-\n-    def get_notBefore(self):\n-        return self.getNotBefore()\n-\n-    def dict(self):\n-        \"\"\"Return simple dictionary of key elements as simple types.\n-\n-    Note: this only returns the RSA Public key information for this certificate.\n-\n-    Returns:\n-      {str, value} where `value` is simple type like `long`\n-    \"\"\"\n-        cdict = {}\n-\n-        # hack directly from prettyPrint\n-        # we just want to verify that this is RSA-SHA1 and get the public key\n-        text = self.prettyPrint()\n-        if not (RSA_ID in text or RSA_SHA1_ID in text):\n-            raise NotImplementedError(\"Only RSA-SHA1 X509 certificates are supported.\")\n-            # rip out public key binary\n-        bits = RX_PUBLIC_KEY.search(text).group(1)\n-        binhex = hex(int(bits, 2))[2:-1]\n-        bindata = binhex.decode(\"hex\")\n-\n-        # Get X509SubjectName string\n-        # fake this for now; generate later using RX\n-        cdict['subject'] = 'SubjectName'\n-\n-        # re-parse RSA Public Key PEM binary\n-        pubkey = RSAPublicKey()\n-        key = der_decode(bindata, asn1Spec=pubkey)[0]\n-        cdict.update(key.dict())\n-\n-        return cdict\n-\n-\n-class RSAPublicKey(SequenceParser):\n-    componentType = namedtype.NamedTypes(\n-        namedtype.NamedType('modulus', univ.Integer()),\n-        namedtype.NamedType('publicExponent', univ.Integer())\n-    )\n-\n-\n-def rfc2253_name(map):\n-    \"\"\"Return subjectName formatted string from list of pairs.\n-\n-  Args:\n-    map: [(str, str)] pairs such that:\n-      (str, str) = ([x.500 attribute type], value)\n-  Returns:\n-    str of rfc2253 formmated name\n-\n-  Example:\n-   map = [('2.5.4.3', 'Kille, Steve'), ('2.5.4.10', 'Isode')\n-   returs: \"CN=Kille\\, Steve,O=Isode\"\n-  \"\"\"\n-    pairs = []\n-    for code, value in map:\n-        s = \"%s=%s\" % (X500_CODE_MAP.get(code, code), value.replace(',', '\\,'))\n-        pairs.append(s)\n-    name = ','.join(pairs)\n-    return name\n-\n-\n-def parse(data):\n-    \"\"\"Return elements from parsed X509 certificate data.\n-\n-  Args:\n-    data: str of X509 certificate file contents\n-  Returns:\n-    {str: value} of notable certificate elements s.t.:\n-      ['modulus'] = int of included RSA public key\n-      ['publicExponent'] = int of included RSA public key\n-      ['subject'] = str of compiled subject in rfc2253 format\n-      ['body'] = str of X509 DER binary in base64\n-      ['type'] = str of \"X509 PRIVATE\"\n-      ['pem'] = PEM format\n-  \"\"\"\n-    # initialize empty return dictionary\n-    cdict = {}\n-\n-    lines = []\n-    grab = False\n-    for s in data.splitlines():\n-        if '-----' == s[:5] and \"BEGIN\" in s:\n-            if not \"CERTIFICATE\" in s:\n-                raise NotImplementedError(\"Only PEM Certificates are supported. Header: %s\", s)\n-            grab = True\n-        elif '-----' == s[:5] and \"END\" in s:\n-            if not \"CERTIFICATE\" in s:\n-                raise NotImplementedError(\"Only PEM Certificates are supported. Footer: %s\", s)\n-            grab = False\n-        else:\n-            # include this b64 data for decoding\n-            if grab:\n-                lines.append(s.strip())\n-\n-    body = ''.join(lines)\n-    pem = \"-----BEGIN CERTIFICATE-----\\n%s\\n-----END CERTIFICATE-----\\n\" % \"\\n\".join(lines)\n-    raw_data = body.decode(\"base64\")\n-\n-    cert = der_decode(raw_data, asn1Spec=Certificate())[0]\n-\n-    # dump parsed PEM data to text\n-    text = cert.prettyPrint()\n-\n-    # GET RSA KEY\n-    # ===========\n-    if not (RSA_ID in text):\n-        raise NotImplementedError(\"Only RSA X509 certificates are supported.\")\n-        # rip out RSA public key binary\n-    key_bits = RX_PUBLIC_KEY.search(text).group(1)\n-    key_binhex = hex(int(key_bits, 2))[2:-1]\n-    key_bin = key_binhex.decode(\"hex\")\n-    # reparse RSA Public Key PEM binary\n-    key = der_decode(key_bin, asn1Spec=RSAPublicKey())[0]\n-    # add RSA key elements to return dictionary\n-    cdict.update(key.dict())\n-\n-    # GET CERTIFICATE SUBJECT\n-    # =======================\n-    subject_text = RX_SUBJECT.search(text).group(0)\n-    attrs = RX_SUBJECT_ATTR.findall(subject_text)\n-    cdict['subject'] = rfc2253_name(attrs)\n-\n-    # add base64 encoding and type to return dictionary\n-\n-    cdict['body'] = body\n-    cdict['pem'] = pem\n-    cdict['type'] = \"X509 CERTIFICATE\"\n-    cdict['cert'] = cert\n-    return cdict\n-\n-\n-def dict_to_tuple(dict):\n-    \"\"\"Return RSA PyCrypto tuple from parsed X509 dict with public RSA key.\n-\n-  Args:\n-    dict: dict of {str: value} returned from `parse`\n-  Returns:\n-    tuple of (int) of RSA public key integers for PyCrypto key construction\n-  \"\"\"\n-    tuple = (\n-        dict['modulus'],\n-        dict['publicExponent'],\n-    )\n-    return tuple\ndiff --git a/src/xmlsec/utils.py b/src/xmlsec/utils.py\n--- a/src/xmlsec/utils.py\n+++ b/src/xmlsec/utils.py\n@@ -2,9 +2,13 @@\n \n __author__ = 'leifj'\n \n+from cryptography.hazmat.backends import default_backend\n+from cryptography.hazmat.primitives import serialization\n+from cryptography.hazmat.primitives.asymmetric import rsa\n+from cryptography.x509 import load_pem_x509_certificate, load_der_x509_certificate\n from defusedxml import lxml\n from lxml import etree as etree\n-from rsa_x509_pem import parse as pem_parse\n+from PyCryptoShim import RSAobjShim\n from int_to_bytes import int_to_bytes\n from xmlsec.exceptions import XMLSigException\n import htmlentitydefs\n@@ -25,6 +29,14 @@ def parse_xml(data, remove_whitespace=True, remove_comments=True, schema=None):\n \n \n def pem2b64(pem):\n+    \"\"\"\n+    Strip the header and footer of a .pem. BEWARE: Won't work with explanatory\n+    strings above the header.\n+    @params pem A string representing the pem\n+    \"\"\"\n+    # XXX try to use cryptography parser to support things like\n+    # https://tools.ietf.org/html/rfc7468#section-5.2\n+\n     return '\\n'.join(pem.strip().split('\\n')[1:-1])\n \n \n@@ -40,14 +52,44 @@ def b642pem(data):\n     r += \"-----END CERTIFICATE-----\"\n     return r\n \n+def _cert2dict(cert):\n+    \"\"\"\n+    Build cert_dict similar to old rsa_x509_pem backend. Shouldn't\n+    be used by new code.\n+    @param cert A cryptography.x509.Certificate object\n+    \"\"\"\n+    key = cert.public_key()\n+    if not isinstance(key, rsa.RSAPublicKey):\n+        raise XMLSigException(\"We don't support non-RSA public keys at the moment.\")\n+    cdict = dict()\n+    cdict['type'] = \"X509 CERTIFICATE\"\n+    cdict['pem'] = cert.public_bytes(encoding=serialization.Encoding.PEM)\n+    cdict['body'] = b64encode(cert.public_bytes(encoding=serialization.Encoding.DER))\n+    n = key.public_numbers()\n+    cdict['modulus'] = n.n\n+    cdict['publicExponent'] = n.e\n+    cdict['subject'] = cert.subject\n+    cdict['cert'] = RSAobjShim(cert)\n+\n+    return cdict\n \n def pem2cert(pem):\n-    return pem_parse(pem)\n-\n+    \"\"\"\n+    Return cert_dict similar to old rsa_x509_pem backend. Shouldn't\n+    be used by new code.\n+    @param pem The certificate as pem string\n+    \"\"\"\n+    cert = load_pem_x509_certificate(pem, backend=default_backend())\n+    return _cert2dict(cert)\n \n def b642cert(data):\n-    return pem_parse(b642pem(data))\n-\n+    \"\"\"\n+    Return cert_dict similar to old rsa_x509_pem backend. Shouldn't\n+    be used by new code.\n+    @param data The certificate as base64 string (i.e. pem without header/footer)\n+    \"\"\"\n+    cert = load_der_x509_certificate(standard_b64decode(data), backend=default_backend())    \n+    return _cert2dict(cert)\n \n def unescape_xml_entities(text):\n     \"\"\"\n", "test_patch": "diff --git a/src/xmlsec/rsa_x509_pem/test.py b/src/xmlsec/rsa_x509_pem/test.py\ndeleted file mode 100644\n--- a/src/xmlsec/rsa_x509_pem/test.py\n+++ /dev/null\n@@ -1,429 +0,0 @@\n-#!/usr/bin/python\n-# -*- coding: utf-8 -*-\n-# Copyright \u00a92011 Andrew D Yates\n-# andrewyates.name@gmail.com\n-#\n-# Modified and redistributed as part of pyXMLSecurity by leifj@mnt.se\n-# with permission from the original author\n-#\n-\"\"\"Test RSA cryptographic PEM reader modules using example files.\n-\"\"\"\n-from datetime import datetime\n-import unittest\n-import pkg_resources\n-from threading import Thread\n-\n-from .Crypto.PublicKey import RSA\n-\n-from . import rsa_pem\n-from . import x509_pem\n-import xmlsec.rsa_x509_pem.__init__ as top\n-from xmlsec.int_to_bytes import int_to_bytes as itb\n-from xmlsec.int_to_bytes import bytes_to_int as bti\n-from Crypto.PublicKey.number import long_to_bytes as ltb\n-from Crypto.PublicKey.number import bytes_to_long as btl\n-from xmlsec import _signed_value\n-from xmlsec import constants\n-\n-\n-KEY_FILE_PAIRS = (\n-    ('keys/privkey_1_rsa_512.pem', 'keys/rsa_cert_1_512.pem'),\n-    ('keys/privkey_1_rsa_1024.pem', 'keys/rsa_cert_1_1024.pem'),\n-    ('keys/privkey_1_rsa_2048.pem', 'keys/rsa_cert_1_2048.pem'),\n-)\n-\n-RSA_PARTS = (\n-    ('version', long),\n-    ('modulus', long),\n-    ('publicExponent', long),\n-    ('privateExponent', long),\n-    ('prime1', long),\n-    ('prime2', long),\n-    ('exponent1', long),\n-    ('exponent2', long),\n-    ('coefficient', long),\n-    ('body', basestring),\n-    ('type', basestring),\n-)\n-\n-X509_PARTS = (\n-    ('modulus', long),\n-    ('publicExponent', long),\n-    ('subject', basestring),\n-    ('body', basestring),\n-    ('type', basestring),\n-)\n-\n-X509_SUBJECT = \"C=US,ST=Ohio,L=Columbus,CN=Andrew Yates,O=http://github.com/andrewdyates\"\n-\n-MSG1 = \"Hello, World!\"\n-MSG2 = \"This is a test message to sign.\"\n-MSG_LONG = \"\"\"I dedicate this essay to the two-dozen-odd people whose refutations of Cantor\u2019s diagonal\n-argument have come to me either as referee or as editor in the last twenty years or so. Sadly these\n-submissions were all quite unpublishable; I sent them back with what I hope were helpful comments. A\n-few years ago it occurred to me to wonder why so many people devote so much energy to refuting this\n-harmless little argument \u2014 what had it done to make them angry with it? So I started to keep notes\n-of these papers, in the hope that some pattern would emerge. These pages report the results.\"\"\"\n-\n-DUMMY_SIG = (1234567890,)\n-\n-\n-class TestParse(unittest.TestCase):\n-    \"\"\"Test parsing PEM formats into labeled dictionaries.\"\"\"\n-\n-    def setUp(self):\n-        self.data = {}\n-        for key, cert in KEY_FILE_PAIRS:\n-            self.data[key] = pkg_resources.resource_stream(__name__, key).read()\n-            self.data[cert] = pkg_resources.resource_stream(__name__, cert).read()\n-\n-    def test_key_parse(self):\n-        for key, cert in KEY_FILE_PAIRS:\n-            data = self.data[key]\n-            self.assertTrue(data)\n-            kdict = rsa_pem.parse(data)\n-            self.assertTrue(kdict)\n-            # 20 chars is enough of a sanity check\n-            self.assertTrue(kdict['body'][:20] in data)\n-            self.assertEqual(kdict['type'], \"RSA PRIVATE\")\n-\n-    def test_key_parse_elements(self):\n-        for key, cert in KEY_FILE_PAIRS:\n-            data = self.data[key]\n-            kdict = rsa_pem.parse(data)\n-            for part, dtype in RSA_PARTS:\n-                self.assertTrue(part in kdict)\n-                self.assertTrue(isinstance(kdict[part], dtype))\n-\n-    def test_cert_parse(self):\n-        for key, cert in KEY_FILE_PAIRS:\n-            data = self.data[cert]\n-            self.assertTrue(data)\n-            cdict = x509_pem.parse(data)\n-            self.assertTrue(cdict)\n-            # 20 chars is enough of a sanity check\n-            self.assertTrue(cdict['body'][:20] in data)\n-            self.assertEqual(cdict['type'], \"X509 CERTIFICATE\")\n-\n-    def test_parse_haka_cert(self):\n-        haka = pkg_resources.resource_stream(__name__, 'keys/haka-sign-v2.pem').read()\n-        self.assertTrue(haka)\n-        cdict = x509_pem.parse(haka)\n-        self.assertTrue(cdict)\n-\n-    def test_parse_steria_cert(self):\n-        haka = pkg_resources.resource_stream(__name__, 'keys/steria.pem').read()\n-        self.assertTrue(haka)\n-        cdict = x509_pem.parse(haka)\n-        self.assertTrue(cdict)\n-\n-    class DelayedExceptionThread(Thread):\n-\n-        def __init__(self, inner):\n-            self._i = inner\n-            self.exception = None\n-\n-            super(TestParse.DelayedExceptionThread, self).__init__()\n-\n-        def run(self):\n-            try:\n-                self._i()\n-            except Exception, ex:\n-                self.exception = ex\n-\n-    def _thread_it(self, testcase, n=10):\n-        w = []\n-        for i in range(0, n):\n-            w.append(TestParse.DelayedExceptionThread(testcase))\n-        for i in range(0, n):\n-            w[i].start()\n-        for i in range(0, n):\n-            w[i].join()\n-        for i in range(0, n):\n-            assert not(w[i].isAlive())\n-            if w[i].exception is not None:\n-                raise w[i].exception\n-\n-    def test_100_parse_haka_cert(self):\n-        self._thread_it(self.test_parse_haka_cert, n=100)\n-\n-    def test_100_cert_parse(self):\n-        self._thread_it(self.test_cert_parse, n=100)\n-\n-    def test_cert_parse_elements(self):\n-        for key, cert in KEY_FILE_PAIRS:\n-            data = self.data[cert]\n-            cdict = x509_pem.parse(data)\n-            self.assertEqual(cdict['subject'], X509_SUBJECT)\n-            self.assertTrue(cdict['cert'] is not None)\n-            for part, dtype in X509_PARTS:\n-                self.assertTrue(part in cdict)\n-                self.assertTrue(isinstance(cdict[part], dtype))\n-\n-    def test_cert_parse_components(self):\n-        for key, cert in KEY_FILE_PAIRS:\n-            data = self.data[cert]\n-            cdict = x509_pem.parse(data)\n-            self.assertTrue(cdict['cert'] is not None)\n-            c = cdict['cert']\n-            validity = c.getComponentByName('tbsCertificate').getComponentByName('validity')\n-            validity2 = c['tbsCertificate']['validity']\n-            self.assertTrue(validity is not None)\n-            self.assertTrue(validity is validity2)\n-            self.assertEqual(validity['notAfter'], c.getNotAfter())\n-            self.assertTrue(validity.getComponentByName('notBefore').getComponentByPosition(0))\n-            et = datetime.strptime(\"%s\" % c.getNotAfter(), \"%y%m%d%H%M%SZ\")\n-            print et\n-            print \"%s\" % c['tbsCertificate']['subject'][0]\n-\n-\n-class TestGenKey(unittest.TestCase):\n-    \"\"\"Test RSA Keys from parameters parsed from file.\"\"\"\n-\n-    def setUp(self):\n-        self.dicts = {}\n-        for key, cert in KEY_FILE_PAIRS:\n-            self.dicts[key] = rsa_pem.parse(pkg_resources.resource_stream(__name__, key).read())\n-            self.dicts[cert] = x509_pem.parse(pkg_resources.resource_stream(__name__, cert).read())\n-\n-    def test_rsa_tuple_generation(self):\n-        for key, cert in KEY_FILE_PAIRS:\n-            rsa_dict = self.dicts[key]\n-            t = rsa_pem.dict_to_tuple(rsa_dict)\n-            self.assertTrue(t)\n-            self.assertEqual(len(t), 6)\n-\n-    def test_x509_tuple_generation(self):\n-        for key, cert in KEY_FILE_PAIRS:\n-            x509_dict = self.dicts[cert]\n-            t = x509_pem.dict_to_tuple(x509_dict)\n-            self.assertTrue(t)\n-            self.assertEqual(len(t), 2)\n-\n-    def test_rsa_keys(self):\n-        for key, cert in KEY_FILE_PAIRS:\n-            rsa_dict = self.dicts[key]\n-            rsa_t = rsa_pem.dict_to_tuple(rsa_dict)\n-            rsa_key = RSA.construct(rsa_t)\n-            self.assertTrue(rsa_key)\n-            self.assertEqual(rsa_key.e, 65537)\n-\n-    def test_x509_keys(self):\n-        for key, cert in KEY_FILE_PAIRS:\n-            x509_dict = self.dicts[cert]\n-            x509_t = x509_pem.dict_to_tuple(x509_dict)\n-            x509_key = RSA.construct(x509_t)\n-            self.assertTrue(x509_key)\n-            self.assertEqual(x509_key.e, 65537)\n-\n-\n-class TestRSAKey(unittest.TestCase):\n-    \"\"\"Test correct operation of RSA keys generated from key files.\"\"\"\n-\n-    def setUp(self):\n-        self.keys = {}\n-        for key, cert in KEY_FILE_PAIRS:\n-            cdict = rsa_pem.parse(pkg_resources.resource_stream(__name__, key).read())\n-            t = rsa_pem.dict_to_tuple(cdict)\n-            self.keys[key] = RSA.construct(t)\n-\n-            cdict = x509_pem.parse(pkg_resources.resource_stream(__name__, cert).read())\n-            t = x509_pem.dict_to_tuple(cdict)\n-            self.keys[cert] = RSA.construct(t)\n-\n-    def test_seq_sign(self):\n-        from hashlib import sha256\n-        for key_name, v in KEY_FILE_PAIRS:\n-            key = self.keys[key_name]\n-            e_len = (key.size() + 1)/8\n-            for i in range(0,1000):\n-                msg = \"%d\" % i\n-                d = sha256()\n-                d.update(msg)\n-                b_digest = d.digest()\n-                tbs = _signed_value(b_digest, key.size()+1, True, \"sha256\")\n-                (sig,) = key.sign(btl(tbs),None)\n-                buf = ltb(sig, e_len)\n-                buflen = len(buf)\n-                self.assertEquals(buflen,e_len)\n-\n-    def test_key_encryption(self):\n-        for key_name, v in KEY_FILE_PAIRS:\n-            key = self.keys[key_name]\n-            cipher1 = key.encrypt(MSG1, None)\n-            cipher2 = key.encrypt(MSG2, None)\n-            self.assertNotEqual(MSG1, MSG2)\n-            self.assertNotEqual(cipher1, cipher2)\n-\n-    def test_key_decryption(self):\n-        for key_name, v in KEY_FILE_PAIRS:\n-            key = self.keys[key_name]\n-            # Message 1\n-            cipher1 = key.encrypt(MSG1, None)\n-            plain1 = key.decrypt(cipher1)\n-            self.assertEqual(MSG1, plain1)\n-            # Message 2\n-            cipher2 = key.encrypt(MSG2, None)\n-            plain2 = key.decrypt(cipher2)\n-            self.assertEqual(MSG2, plain2)\n-\n-    def test_key_signature(self):\n-        for key_name, v in KEY_FILE_PAIRS:\n-            key = self.keys[key_name]\n-            signature1 = key.sign(MSG1, None)\n-            signature2 = key.sign(MSG2, None)\n-            self.assertNotEqual(MSG1, MSG2)\n-            self.assertNotEqual(signature1, signature2)\n-\n-    def test_key_verification(self):\n-        for key_name, v in KEY_FILE_PAIRS:\n-            key = self.keys[key_name]\n-            # Message 1\n-            signature1 = key.sign(MSG1, None)\n-            verified1 = key.verify(MSG1, signature1)\n-            fail1 = key.verify(MSG2, signature1)\n-            self.assertTrue(verified1)\n-            self.assertFalse(fail1)\n-            # Message 2\n-            signature2 = key.sign(MSG2, None)\n-            verified2 = key.verify(MSG2, signature2)\n-            fail2 = key.verify(MSG1, signature2)\n-            self.assertTrue(verified2)\n-            self.assertFalse(fail1)\n-\n-    def test_too_long(self):\n-        for key_name, cert_name in KEY_FILE_PAIRS:\n-            key = self.keys[key_name]\n-            cert = self.keys[cert_name]\n-            self.assertRaises(Exception, key.encrypt, MSG_LONG, None)\n-            self.assertRaises(Exception, key.decrypt, MSG_LONG)\n-            self.assertRaises(Exception, key.sign, MSG_LONG, None)\n-            self.assertRaises(Exception, cert.encrypt, MSG_LONG, None)\n-\n-    def test_certs_public_only(self):\n-        for k, cert_name in KEY_FILE_PAIRS:\n-            cert = self.keys[cert_name]\n-            self.assertRaises(Exception, cert.sign, MSG_LONG, None)\n-            self.assertRaises(Exception, cert.decrypt, MSG_LONG)\n-\n-    def test_cert_verification(self):\n-        for k, cert_name in KEY_FILE_PAIRS:\n-            cert = self.keys[k]\n-            fail = cert.verify(MSG1, DUMMY_SIG)\n-            self.assertFalse(fail)\n-\n-    def test_bad_sig_types(self):\n-        k, c = KEY_FILE_PAIRS[0]\n-        key = self.keys[k]\n-        self.assertRaises(TypeError, key.verify, MSG1, 1234567890)\n-        self.assertRaises(Exception, key.verify, MSG1, \"1234567890\")\n-        key.verify(MSG1, DUMMY_SIG)\n-\n-    def test_cert_encryption(self):\n-        for k, cert_name in KEY_FILE_PAIRS:\n-            cert = self.keys[cert_name]\n-            cipher1 = cert.encrypt(MSG1, None)\n-            cipher2 = cert.encrypt(MSG2, None)\n-            self.assertNotEqual(MSG1, MSG2)\n-            self.assertNotEqual(cipher1, cipher2)\n-\n-    def test_key_pairs(self):\n-        for key_name, cert_name in KEY_FILE_PAIRS:\n-            key, cert = self.keys[key_name], self.keys[cert_name]\n-            # sign with private, verify with public cert\n-            signature1 = key.sign(MSG1, None)\n-            verified1 = cert.verify(MSG1, signature1)\n-            fail1 = cert.verify(MSG2, signature1)\n-            self.assertTrue(verified1)\n-            self.assertFalse(fail1)\n-            signature2 = key.sign(MSG2, None)\n-            verified2 = cert.verify(MSG2, signature2)\n-            fail2 = cert.verify(MSG1, signature2)\n-            self.assertTrue(verified2)\n-            self.assertFalse(fail2)\n-\n-    def test_mismatch_key_pair(self):\n-        # select mismatched keypair\n-        key_name, cert_name = KEY_FILE_PAIRS[0][0], KEY_FILE_PAIRS[1][1]\n-        key, cert = self.keys[key_name], self.keys[cert_name]\n-        # verify signature failure\n-        signature = key.sign(MSG1, None)\n-        fail_verify = cert.verify(MSG1, signature)\n-        self.assertFalse(fail_verify)\n-        # verify encryption failure\n-        cipher = cert.encrypt(MSG1, None)\n-        try:\n-            plain = key.decrypt(cipher)\n-        except Exception, e:\n-            self.assertTrue(\"Ciphertext too large\" in e, e)\n-        else:\n-            self.assertNotEqual(MSG1, plain)\n-\n-\n-class TestTop(unittest.TestCase):\n-    def test_rsa_parse(self):\n-        self.assertEqual(top.rsa_parse, rsa_pem.parse)\n-        data = pkg_resources.resource_stream(__name__, KEY_FILE_PAIRS[0][0]).read()\n-        rsa_dict = top.parse(data)\n-        self.assertTrue(rsa_dict)\n-\n-    def test_x509_parse(self):\n-        self.assertEqual(top.x509_parse, x509_pem.parse)\n-        data = pkg_resources.resource_stream(__name__, KEY_FILE_PAIRS[0][1]).read()\n-        x509_dict = top.parse(data)\n-        self.assertTrue(x509_dict)\n-\n-    def test_rsa_dict_to_key(self):\n-        data = pkg_resources.resource_stream(__name__, KEY_FILE_PAIRS[0][0]).read()\n-        rsa_dict = top.parse(data)\n-        key = top.get_key(rsa_dict)\n-        self.assertTrue(key)\n-        self.assertTrue(key.e)\n-        self.assertTrue(key.d)\n-\n-    def test_x509_dict_to_key(self):\n-        data = pkg_resources.resource_stream(__name__, KEY_FILE_PAIRS[0][1]).read()\n-        x509_dict = top.parse(data)\n-        key = top.get_key(x509_dict)\n-        self.assertTrue(key)\n-        self.assertTrue(key.e)\n-        # \"lambda\" suppresses exception until called by the test handler\n-        self.assertRaises(AttributeError, lambda: key.d)\n-\n-    def test_RSA_obj(self):\n-        self.assertEqual(top.RSAKey, RSA.RSAobj)\n-\n-\n-class TestFunctionWrappers(unittest.TestCase):\n-    def setUp(self):\n-        self.pubkey = top.get_key(top.parse(pkg_resources.resource_stream(__name__, KEY_FILE_PAIRS[0][1]).read()))\n-        self.privkey = top.get_key(top.parse(pkg_resources.resource_stream(__name__, KEY_FILE_PAIRS[0][0]).read()))\n-\n-    def test_public(self):\n-        f_my_public = top.f_public(self.pubkey)\n-        self.assertTrue(f_my_public(MSG1))\n-        f_my_public2 = top.f_public(self.privkey)\n-        self.assertTrue(f_my_public2(MSG1))\n-\n-    def test_private(self):\n-        f_my_private = top.f_private(self.privkey)\n-        self.assertTrue(f_my_private(MSG1))\n-        f_my_private2 = top.f_private(self.pubkey)\n-        # cannot use private function on a public key\n-        self.assertRaises(Exception, f_my_private2, MSG1)\n-\n-    def test_inverse(self):\n-        f_my_private = top.f_private(self.privkey)\n-        f_my_public = top.f_public(self.privkey)\n-        self.assertEqual(MSG1, f_my_public(f_my_private(MSG1)))\n-        self.assertEqual(MSG1, f_my_private(f_my_public(MSG1)))\n-        self.assertNotEqual(MSG1, f_my_public(f_my_public(MSG1)))\n-        self.assertNotEqual(MSG1, f_my_private(f_my_private(MSG1)))\n-\n-\n-def main():\n-    unittest.main()\n-\n-\n-if __name__ == '__main__':\n-    main()\n", "problem_statement": "", "hints_text": "", "created_at": "2018-08-07T14:26:58Z"}