[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

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



commit 95f0cfecca414ee3fe6c64d121300fe889f13f0f
Author: Isis Lovecruft <isis@xxxxxxxxxxxxxx>
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



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits