OXIESEC PANEL
- Current Dir:
/
/
usr
/
lib
/
python3
/
dist-packages
/
josepy
Server IP: 139.59.38.164
Upload:
Create Dir:
Name
Size
Modified
Perms
📁
..
-
03/17/2025 09:32:20 AM
rwxr-xr-x
📄
__init__.py
1.97 KB
04/13/2018 02:47:09 PM
rw-r--r--
📁
__pycache__
-
07/12/2020 04:36:18 PM
rwxr-xr-x
📄
b64.py
1.47 KB
04/13/2018 02:47:09 PM
rw-r--r--
📄
b64_test.py
2.27 KB
04/13/2018 02:47:09 PM
rw-r--r--
📄
errors.py
815 bytes
04/13/2018 02:47:09 PM
rw-r--r--
📄
errors_test.py
463 bytes
04/13/2018 02:47:09 PM
rw-r--r--
📄
interfaces.py
7.56 KB
04/13/2018 02:47:09 PM
rw-r--r--
📄
interfaces_test.py
3.54 KB
04/13/2018 02:47:09 PM
rw-r--r--
📄
json_util.py
15.38 KB
04/13/2018 02:47:09 PM
rw-r--r--
📄
json_util_test.py
13.94 KB
04/13/2018 02:47:09 PM
rw-r--r--
📄
jwa.py
6.01 KB
04/13/2018 02:47:09 PM
rw-r--r--
📄
jwa_test.py
4.54 KB
04/13/2018 02:47:09 PM
rw-r--r--
📄
jwk.py
9.19 KB
04/13/2018 02:47:09 PM
rw-r--r--
📄
jwk_test.py
6.92 KB
04/13/2018 02:47:09 PM
rw-r--r--
📄
jws.py
13.93 KB
04/13/2018 02:47:09 PM
rw-r--r--
📄
jws_test.py
8.32 KB
04/13/2018 02:47:09 PM
rw-r--r--
📄
test_util.py
2.85 KB
04/13/2018 02:47:09 PM
rw-r--r--
📄
util.py
7.3 KB
04/13/2018 02:47:09 PM
rw-r--r--
📄
util_test.py
6.45 KB
04/13/2018 02:47:09 PM
rw-r--r--
Editing: test_util.py
Close
"""Test utilities. .. warning:: This module is not part of the public API. """ import os import unittest import OpenSSL import pkg_resources from cryptography.hazmat.backends import default_backend from cryptography.hazmat.primitives import serialization from josepy import ComparableRSAKey, ComparableX509 def vector_path(*names): """Path to a test vector.""" return pkg_resources.resource_filename( __name__, os.path.join('testdata', *names)) def load_vector(*names): """Load contents of a test vector.""" # luckily, resource_string opens file in binary mode return pkg_resources.resource_string( __name__, os.path.join('testdata', *names)) def _guess_loader(filename, loader_pem, loader_der): _, ext = os.path.splitext(filename) if ext.lower() == '.pem': return loader_pem elif ext.lower() == '.der': return loader_der else: # pragma: no cover raise ValueError("Loader could not be recognized based on extension") def load_cert(*names): """Load certificate.""" loader = _guess_loader( names[-1], OpenSSL.crypto.FILETYPE_PEM, OpenSSL.crypto.FILETYPE_ASN1) return OpenSSL.crypto.load_certificate(loader, load_vector(*names)) def load_comparable_cert(*names): """Load ComparableX509 cert.""" return ComparableX509(load_cert(*names)) def load_csr(*names): """Load certificate request.""" loader = _guess_loader( names[-1], OpenSSL.crypto.FILETYPE_PEM, OpenSSL.crypto.FILETYPE_ASN1) return OpenSSL.crypto.load_certificate_request(loader, load_vector(*names)) def load_comparable_csr(*names): """Load ComparableX509 certificate request.""" return ComparableX509(load_csr(*names)) def load_rsa_private_key(*names): """Load RSA private key.""" loader = _guess_loader(names[-1], serialization.load_pem_private_key, serialization.load_der_private_key) return ComparableRSAKey(loader( load_vector(*names), password=None, backend=default_backend())) def load_pyopenssl_private_key(*names): """Load pyOpenSSL private key.""" loader = _guess_loader( names[-1], OpenSSL.crypto.FILETYPE_PEM, OpenSSL.crypto.FILETYPE_ASN1) return OpenSSL.crypto.load_privatekey(loader, load_vector(*names)) def skip_unless(condition, reason): # pragma: no cover """Skip tests unless a condition holds. This implements the basic functionality of unittest.skipUnless which is only available on Python 2.7+. :param bool condition: If ``False``, the test will be skipped :param str reason: the reason for skipping the test :rtype: callable :returns: decorator that hides tests unless condition is ``True`` """ if hasattr(unittest, "skipUnless"): return unittest.skipUnless(condition, reason) elif condition: return lambda cls: cls else: return lambda cls: None