Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 1 addition & 7 deletions jose/backends/__init__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
try:
from jose.backends.cryptography_backend import get_random_bytes # noqa: F401
except ImportError:
try:
from jose.backends.pycrypto_backend import get_random_bytes # noqa: F401
except ImportError:
from jose.backends.native import get_random_bytes # noqa: F401
from jose.backends.native import get_random_bytes # noqa: F401

try:
from jose.backends.cryptography_backend import CryptographyRSAKey as RSAKey # noqa: F401
Expand Down
25 changes: 1 addition & 24 deletions jose/backends/cryptography_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

from cryptography.exceptions import InvalidSignature, InvalidTag
from cryptography.hazmat.backends import default_backend
from cryptography.hazmat.bindings.openssl.binding import Binding
from cryptography.hazmat.primitives import hashes, hmac, serialization
from cryptography.hazmat.primitives.asymmetric import ec, padding, rsa
from cryptography.hazmat.primitives.asymmetric.utils import decode_dss_signature, encode_dss_signature
Expand All @@ -25,34 +24,12 @@
is_ssh_key,
long_to_base64,
)
from . import get_random_bytes
from .base import Key

_binding = None


def get_random_bytes(num_bytes):
"""
Get random bytes

Currently, Cryptography returns OS random bytes. If you want OpenSSL
generated random bytes, you'll have to switch the RAND engine after
initializing the OpenSSL backend
Args:
num_bytes (int): Number of random bytes to generate and return
Returns:
bytes: Random bytes
"""
global _binding

if _binding is None:
_binding = Binding()

buf = _binding.ffi.new("char[]", num_bytes)
_binding.lib.RAND_bytes(buf, num_bytes)
rand_bytes = _binding.ffi.buffer(buf, num_bytes)[:]
return rand_bytes


class CryptographyECKey(Key):
SHA256 = hashes.SHA256
SHA384 = hashes.SHA384
Expand Down
Loading