[tor-commits] [bridgedb/develop] Catch ValueErrors in isValidFingerprint.

isis at torproject.org isis at torproject.org
Thu Feb 19 02:21:13 UTC 2015


commit 95f0cfecca414ee3fe6c64d121300fe889f13f0f
Author: Isis Lovecruft <isis at torproject.org>
Date:   Fri Dec 12 11:23:44 2014 +0000

    Catch ValueErrors in isValidFingerprint.
---
 lib/bridgedb/parse/fingerprint.py |   16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)

diff --git a/lib/bridgedb/parse/fingerprint.py b/lib/bridgedb/parse/fingerprint.py
index 17f15c3..900fc06 100644
--- a/lib/bridgedb/parse/fingerprint.py
+++ b/lib/bridgedb/parse/fingerprint.py
@@ -34,11 +34,13 @@ def isValidFingerprint(fingerprint):
     :rtype: bool
     :returns: ``True`` if the **fingerprint** was valid, ``False`` otherwise.
     """
-    if len(fingerprint) == HEX_FINGERPRINT_LEN:
-        try:
-            fromHex(fingerprint)
-        except TypeError:
-            logging.debug("Invalid hex fingerprint: %r" % repr(fingerprint))
-        else:
-            return True
+    try:
+        if len(fingerprint) != HEX_FINGERPRINT_LEN:
+            raise ValueError("Fingerprint has incorrect length: %r"
+                             % repr(fingerprint))
+        fromHex(fingerprint)
+    except (TypeError, ValueError):
+        logging.debug("Invalid hex fingerprint: %r" % repr(fingerprint))
+    else:
+        return True
     return False





More information about the tor-commits mailing list