aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--cryptography/utils.py9
1 files changed, 9 insertions, 0 deletions
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))