[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [stem/master] Asserting that _decode_fingerprint() output is a fingerprint
commit dd071270d705507f0131bfceac7358f7223ec32d
Author: Damian Johnson <atagar@xxxxxxxxxxxxxx>
Date: Sun Aug 19 21:25:59 2012 -0700
Asserting that _decode_fingerprint() output is a fingerprint
Checking that the _decode_fingerprint() function returns a fingerprint,
throwing a ValueError if it doesn't. Also adding some tests for this.
---
stem/descriptor/networkstatus.py | 6 ++++++
test/unit/descriptor/networkstatus.py | 4 ++++
2 files changed, 10 insertions(+), 0 deletions(-)
diff --git a/stem/descriptor/networkstatus.py b/stem/descriptor/networkstatus.py
index 485234f..d08f316 100644
--- a/stem/descriptor/networkstatus.py
+++ b/stem/descriptor/networkstatus.py
@@ -53,6 +53,7 @@ import stem.descriptor
import stem.version
import stem.exit_policy
import stem.util.enum
+import stem.util.tor_tools
from stem.descriptor import _read_until_keywords, _peek_keyword, _strptime
from stem.descriptor import _read_keyword_line, _read_keyword_line_str, _get_pseudo_pgp_block, _peek_line
@@ -779,6 +780,8 @@ def _decode_fingerprint(identity):
:param str identity: encoded fingerprint from the consensus
:returns: str with the uppercase hex encoding of the relay's fingerprint
+
+ :raises: ValueError if the result isn't a valid fingerprint
"""
# trailing equal signs were stripped from the identity
@@ -799,5 +802,8 @@ def _decode_fingerprint(identity):
fingerprint += hex(ord(char))[2:].zfill(2).upper()
+ if not stem.util.tor_tools.is_valid_fingerprint(fingerprint):
+ raise ValueError("Decoded '%s' to be '%s', which isn't a valid fingerprint" % (identity, fingerprint))
+
return fingerprint
diff --git a/test/unit/descriptor/networkstatus.py b/test/unit/descriptor/networkstatus.py
index ec69367..f14c2be 100644
--- a/test/unit/descriptor/networkstatus.py
+++ b/test/unit/descriptor/networkstatus.py
@@ -24,4 +24,8 @@ class TestNetworkStatus(unittest.TestCase):
for arg, expected in test_values.items():
self.assertEqual(expected, networkstatus._decode_fingerprint(arg))
+
+ self.assertRaises(ValueError, networkstatus._decode_fingerprint, '')
+ self.assertRaises(ValueError, networkstatus._decode_fingerprint, '20wYcb')
+ self.assertRaises(ValueError, networkstatus._decode_fingerprint, '20wYcb' * 30)
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits