From 7fb3b7bf1a1869a52cf59ee3eb607d318e97265c Mon Sep 17 00:00:00 2001 From: "John W. O'Brien" Date: Mon, 27 Jul 2020 14:56:02 -0400 Subject: [PATCH] Support PyCryptodome as alternative to PyCrypto --- rauth/oauth.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/rauth/oauth.py b/rauth/oauth.py index 5dc44b1..edf8e0c 100644 --- a/rauth/oauth.py +++ b/rauth/oauth.py @@ -171,7 +171,8 @@ def __init__(self): from Crypto.Signature import PKCS1_v1_5 as p self.RSA, self.SHA, self.PKCS1_v1_5 = r, s, p except ImportError: # pragma: no cover - raise NotImplementedError('PyCrypto is required for ' + self.NAME) + raise NotImplementedError('PyCrypto(dome) is required for ' + + self.NAME) def sign(self, consumer_secret, @@ -208,7 +209,9 @@ def sign(self, # resolve the key if is_basestring(consumer_secret): consumer_secret = self.RSA.importKey(consumer_secret) - if not isinstance(consumer_secret, self.RSA._RSAobj): + valid_cls = (getattr(self.RSA, '_RSAobj', False) + or getattr(self.RSA, 'RsaKey', False)) + if not (valid_cls and isinstance(consumer_secret, valid_cls)): raise ValueError('invalid consumer_secret') # hash the string with RSA-SHA1