[Pkg-privacy-commits] [obfsproxy] 208/353: Only use gmpy if it is installed.

Ximin Luo infinity0 at moszumanska.debian.org
Sat Aug 22 13:02:00 UTC 2015


This is an automated email from the git hooks/post-receive script.

infinity0 pushed a commit to branch master
in repository obfsproxy.

commit aad52ec871af886ac07832cd98db433f460f06b8
Author: Philipp Winter <phw at torproject.org>
Date:   Thu Nov 28 01:38:37 2013 +0100

    Only use gmpy if it is installed.
    
    If the library is not installed, the built-in (and slower) modular
    exponentiation is used.
---
 obfsproxy/common/modexp.py | 24 ++++++++++++++----------
 1 file changed, 14 insertions(+), 10 deletions(-)

diff --git a/obfsproxy/common/modexp.py b/obfsproxy/common/modexp.py
index 7c07f98..410514b 100644
--- a/obfsproxy/common/modexp.py
+++ b/obfsproxy/common/modexp.py
@@ -1,15 +1,19 @@
-import gmpy
-
 def powMod( x, y, mod ):
     """
-    Efficiently calculate and return `x' to the power of `y' mod `mod'.
+    (Efficiently) Calculate and return `x' to the power of `y' mod `mod'.
 
-    Before the modular exponentiation, the three numbers are converted to
-    GMPY's bignum representation which speeds up exponentiation.
+    If possible, the three numbers are converted to GMPY's bignum
+    representation which speeds up exponentiation.  If GMPY is not installed,
+    built-in exponentiation is used.
     """
 
-    x = gmpy.mpz(x)
-    y = gmpy.mpz(y)
-    mod = gmpy.mpz(mod)
-
-    return pow(x, y, mod)
+    try:
+        import gmpy
+        x = gmpy.mpz(x)
+        y = gmpy.mpz(y)
+        mod = gmpy.mpz(mod)
+    except ImportError:
+        # gmpy is not installed but that doesn't matter.
+        pass
+    finally:
+        return pow(x, y, mod)

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-privacy/packages/obfsproxy.git



More information about the Pkg-privacy-commits mailing list