[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [stem/master] Use integer hidden service versions
commit 746b6eb4b750561b7f4baa3f9d670ca47f0f3b29
Author: Damian Johnson <atagar@xxxxxxxxxxxxxx>
Date: Tue Feb 24 09:28:45 2015 -0800
Use integer hidden service versions
Clarification courtesy of #15010.
---
stem/descriptor/hidden_service_descriptor.py | 28 +++++++++++++++------
test/unit/descriptor/hidden_service_descriptor.py | 8 +++---
2 files changed, 25 insertions(+), 11 deletions(-)
diff --git a/stem/descriptor/hidden_service_descriptor.py b/stem/descriptor/hidden_service_descriptor.py
index 8e0ba67..68997ab 100644
--- a/stem/descriptor/hidden_service_descriptor.py
+++ b/stem/descriptor/hidden_service_descriptor.py
@@ -109,13 +109,28 @@ def _parse_file(descriptor_file, validate = False, **kwargs):
break # done parsing file
-# TODO: For the 'version' and 'protocol-versions' lines should they be ints
-# instead? Presently the spec says it's a 'version-number' which is an
-# undefined type.
+def _parse_version_line(descriptor, entries):
+ value = _value('version', entries)
+
+ if value.isdigit():
+ descriptor.version = int(value)
+ else:
+ raise ValueError('version line must have a positive integer value: %s' % value)
+
def _parse_protocol_versions_line(descriptor, entries):
value = _value('protocol-versions', entries)
- descriptor.protocol_versions = value.split(',')
+
+ try:
+ versions = [int(entry) for entry in value.split(',')]
+ except ValueError:
+ raise ValueError('protocol-versions line has non-numeric versoins: protocol-versions %s' % value)
+
+ for v in versions:
+ if v <= 0:
+ raise ValueError('protocol-versions must be positive integers: %s' % value)
+
+ descriptor.protocol_versions = versions
def _parse_introduction_points_line(descriptor, entries):
@@ -144,7 +159,6 @@ def _parse_introduction_points_line(descriptor, entries):
descriptor.introduction_points_content = decoded_field
_parse_rendezvous_service_descriptor_line = _parse_simple_line('rendezvous-service-descriptor', 'descriptor_id')
-_parse_version_line = _parse_simple_line('version', 'version')
_parse_permanent_key_line = _parse_key_block('permanent-key', 'permanent_key', 'RSA PUBLIC KEY')
_parse_secret_id_part_line = _parse_simple_line('secret-id-part', 'secret_id_part')
_parse_publication_time_line = _parse_timestamp_line('publication-time', 'published')
@@ -156,12 +170,12 @@ class HiddenServiceDescriptor(Descriptor):
Hidden service descriptor.
:var str descriptor_id: **\*** identifier for this descriptor, this is a base32 hash of several fields
- :var str version: **\*** hidden service descriptor version
+ :var int version: **\*** hidden service descriptor version
:var str permanent_key: **\*** long term key of the hidden service
:var str secret_id_part: **\*** hash of the time period, cookie, and replica
values so our descriptor_id can be validated
:var datetime published: **\*** time in UTC when this descriptor was made
- :var list protocol_versions: **\*** versions that are supported when establishing a connection
+ :var list protocol_versions: **\*** list of **int** versions that are supported when establishing a connection
:var str introduction_points_encoded: **\*** raw introduction points blob
:var list introduction_points_auth: **\*** tuples of the form
(auth_method, auth_data) for our introduction_points_content
diff --git a/test/unit/descriptor/hidden_service_descriptor.py b/test/unit/descriptor/hidden_service_descriptor.py
index 4853a28..a430b06 100644
--- a/test/unit/descriptor/hidden_service_descriptor.py
+++ b/test/unit/descriptor/hidden_service_descriptor.py
@@ -195,18 +195,18 @@ class TestHiddenServiceDescriptor(unittest.TestCase):
desc = next(stem.descriptor.parse_file(descriptor_file, 'hidden-service-descriptor 1.0', validate = True))
self.assertEqual('utjk4arxqg6s6zzo7n6cjnq6ot34udhr', desc.descriptor_id)
- self.assertEqual('2', desc.version)
+ self.assertEqual(2, desc.version)
self.assertEqual('6355jaerje3bqozopwq2qmpf4iviizdn', desc.secret_id_part)
self.assertEqual(datetime.datetime(2014, 10, 31, 23, 0, 0), desc.published)
- self.assertEqual(['2', '3'], desc.protocol_versions)
+ self.assertEqual([2, 3], desc.protocol_versions)
def _assert_matches_duckduckgo(self, desc):
self.assertEqual('y3olqqblqw2gbh6phimfuiroechjjafa', desc.descriptor_id)
- self.assertEqual('2', desc.version)
+ self.assertEqual(2, desc.version)
self.assertEqual(EXPECTED_DDG_PERMANENT_KEY, desc.permanent_key)
self.assertEqual('e24kgecavwsznj7gpbktqsiwgvngsf4e', desc.secret_id_part)
self.assertEqual(datetime.datetime(2015, 2, 23, 20, 0, 0), desc.published)
- self.assertEqual(['2', '3'], desc.protocol_versions)
+ self.assertEqual([2, 3], desc.protocol_versions)
self.assertEqual(EXPECTED_DDG_INTRODUCTION_POINTS_ENCODED, desc.introduction_points_encoded)
self.assertEqual([], desc.introduction_points_auth)
self.assertEqual(EXPECTED_DDG_INTRODUCTION_POINTS_CONTENT, desc.introduction_points_content)
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits