File: test_backends.py

package info (click to toggle)
python-jose 3.3.0%2Bdfsg-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 528 kB
  • sloc: python: 4,020; makefile: 162; sh: 6
file content (58 lines) | stat: -rw-r--r-- 1,561 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
"""Test the default import handling."""
try:
    from jose.backends.rsa_backend import RSAKey as PurePythonRSAKey
except ImportError:
    PurePythonRSAKey = None
try:
    from jose.backends.cryptography_backend import CryptographyECKey, CryptographyRSAKey
except ImportError:
    CryptographyRSAKey = CryptographyECKey = None
try:
    from jose.backends.ecdsa_backend import ECDSAECKey as PurePythonECDSAKey
except ImportError:
    PurePythonRSAKey = None

try:
    from jose.backends.cryptography_backend import CryptographyAESKey
except ImportError:
    CryptographyAESKey = None
try:
    from jose.backends.cryptography_backend import CryptographyHMACKey
except ImportError:
    CryptographyHMACKey = None

from jose.backends import ECKey, HMACKey, RSAKey
from jose.backends.native import HMACKey as NativeHMACKey

try:
    from jose.backends import AESKey
except ImportError:
    AESKey = None


def test_default_ec_backend():
    if CryptographyECKey is not None:
        assert ECKey is CryptographyECKey
    else:
        assert ECKey is PurePythonECDSAKey


def test_default_rsa_backend():
    if CryptographyRSAKey is not None:
        assert RSAKey is CryptographyRSAKey
    else:
        assert RSAKey is PurePythonRSAKey


def test_default_aes_backend():
    if CryptographyAESKey is not None:
        assert AESKey is CryptographyAESKey
    else:
        assert AESKey is None


def test_default_hmac_backend():
    if CryptographyHMACKey is not None:
        assert HMACKey is CryptographyHMACKey
    else:
        assert HMACKey is NativeHMACKey