From 8f4f5c915060214efa5385ff5a7c3454e85b4611 Mon Sep 17 00:00:00 2001 From: Jon Wayne Parrott Date: Mon, 12 Feb 2018 10:41:58 -0800 Subject: [PATCH] Add a check for the cryptography version before attempting to use it. --- google/auth/crypt/_cryptography_rsa.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/google/auth/crypt/_cryptography_rsa.py b/google/auth/crypt/_cryptography_rsa.py index 153e68885..87076b0ab 100644 --- a/google/auth/crypt/_cryptography_rsa.py +++ b/google/auth/crypt/_cryptography_rsa.py @@ -25,10 +25,22 @@ from cryptography.hazmat.primitives import serialization from cryptography.hazmat.primitives.asymmetric import padding import cryptography.x509 +import pkg_resources 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()