Skip to content

Commit

Permalink
Add a check for the cryptography version before attempting to use it.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jon Wayne Parrott committed Feb 12, 2018
1 parent 20ba485 commit 31dac96
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions google/auth/crypt/_cryptography_rsa.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
``rsa`` library.
"""

import pkg_resources

import cryptography.exceptions
from cryptography.hazmat import backends
from cryptography.hazmat.primitives import hashes
Expand All @@ -29,6 +31,17 @@
from google.auth import _helpers
from google.auth.crypt import base

_IMPORT_ERROR_MSG = (
'cryptography>=1.4.0 is required to use cryptography-based RSA '
'implementation.')

try: # pragma: NO COVER
release = pkg_resources.get_distribution('cryptography').parsed_version
if release < pkg_resources.parse_version('1.4.0'):
raise ImportError(_IMPORT_ERROR_MSG)
except pkg_resources.DistributionNotFound: # pragma: NO COVER
raise ImportError(_IMPORT_ERROR_MSG)


_CERTIFICATE_MARKER = b'-----BEGIN CERTIFICATE-----'
_BACKEND = backends.default_backend()
Expand Down

0 comments on commit 31dac96

Please sign in to comment.