aboutsummaryrefslogtreecommitdiffstats
path: root/cryptography
diff options
context:
space:
mode:
authorAlex Gaynor <alex.gaynor@gmail.com>2014-03-05 12:51:20 -0800
committerAlex Gaynor <alex.gaynor@gmail.com>2014-03-05 12:51:20 -0800
commit138c12ca2fb7be92f8e2ab4594201f31a51b99a6 (patch)
treed54914ef0fa6178c49200748ceb586ae093810c7 /cryptography
parente889cc2161d044303ae7ba682fa9c341aa1c99f5 (diff)
parentb1ab2229f6a7db4301f5fd80ef1715d02276ce81 (diff)
downloadcryptography-138c12ca2fb7be92f8e2ab4594201f31a51b99a6.tar.gz
cryptography-138c12ca2fb7be92f8e2ab4594201f31a51b99a6.tar.bz2
cryptography-138c12ca2fb7be92f8e2ab4594201f31a51b99a6.zip
Merge pull request #736 from skeuomorf/bitlength
Move bit_length function from rsa to utils
Diffstat (limited to 'cryptography')
-rw-r--r--cryptography/hazmat/primitives/asymmetric/rsa.py13
-rw-r--r--cryptography/utils.py9
2 files changed, 11 insertions, 11 deletions
diff --git a/cryptography/hazmat/primitives/asymmetric/rsa.py b/cryptography/hazmat/primitives/asymmetric/rsa.py
index d8254046..dfb43340 100644
--- a/cryptography/hazmat/primitives/asymmetric/rsa.py
+++ b/cryptography/hazmat/primitives/asymmetric/rsa.py
@@ -13,21 +13,12 @@
from __future__ import absolute_import, division, print_function
-import sys
-
import six
from cryptography import utils
from cryptography.hazmat.primitives import interfaces
-def _bit_length(x):
- if sys.version_info >= (2, 7):
- return x.bit_length()
- else:
- return len(bin(x)) - (2 + (x <= 0))
-
-
@utils.register_interface(interfaces.RSAPublicKey)
class RSAPublicKey(object):
def __init__(self, public_exponent, modulus):
@@ -55,7 +46,7 @@ class RSAPublicKey(object):
@property
def key_size(self):
- return _bit_length(self.modulus)
+ return utils.bit_length(self.modulus)
@property
def public_exponent(self):
@@ -144,7 +135,7 @@ class RSAPrivateKey(object):
@property
def key_size(self):
- return _bit_length(self.modulus)
+ return utils.bit_length(self.modulus)
def public_key(self):
return RSAPublicKey(self.public_exponent, self.modulus)
diff --git a/cryptography/utils.py b/cryptography/utils.py
index e697d515..eac833b6 100644
--- a/cryptography/utils.py
+++ b/cryptography/utils.py
@@ -13,9 +13,18 @@
from __future__ import absolute_import, division, print_function
+import sys
+
def register_interface(iface):
def register_decorator(klass):
iface.register(klass)
return klass
return register_decorator
+
+
+def bit_length(x):
+ if sys.version_info >= (2, 7):
+ return x.bit_length()
+ else:
+ return len(bin(x)) - (2 + (x <= 0))