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

[tor-commits] [stem/master] Parse revision counter field



commit e4f364941e89821ab8953698c28c3276d4f76cea
Author: Damian Johnson <atagar@xxxxxxxxxxxxxx>
Date:   Sat Aug 24 15:43:24 2019 -0700

    Parse revision counter field
---
 stem/descriptor/hidden_service.py         |  4 ++++
 test/unit/descriptor/hidden_service_v3.py | 15 +++++++++++++++
 2 files changed, 19 insertions(+)

diff --git a/stem/descriptor/hidden_service.py b/stem/descriptor/hidden_service.py
index 84b8d5e7..5336b1bd 100644
--- a/stem/descriptor/hidden_service.py
+++ b/stem/descriptor/hidden_service.py
@@ -185,6 +185,7 @@ _parse_signature_line = _parse_key_block('signature', 'signature', 'SIGNATURE')
 _parse_v3_version_line = _parse_int_line('hs-descriptor', 'version', allow_negative = False)
 _parse_lifetime_line = _parse_int_line('descriptor-lifetime', 'lifetime', allow_negative = False)
 _parse_signing_key_line = _parse_key_block('descriptor-signing-key-cert', 'signing_cert', 'ED25519 CERT')
+_parse_revision_counter_line = _parse_int_line('revision-counter', 'revision_counter', allow_negative = False)
 
 
 class BaseHiddenServiceDescriptor(Descriptor):
@@ -464,6 +465,7 @@ class HiddenServiceDescriptorV3(BaseHiddenServiceDescriptor):
   :var int version: **\\*** hidden service descriptor version
   :var int lifetime: **\\*** minutes after publication this descriptor is valid
   :var str signing_cert: **\\*** cross-certifier for the short-term descriptor signing key
+  :var int revision_counter: **\\*** descriptor revision number
 
   **\\*** attribute is either required when we're parsed with validation or has
   a default value, others are left as **None** if undefined
@@ -477,12 +479,14 @@ class HiddenServiceDescriptorV3(BaseHiddenServiceDescriptor):
     'version': (None, _parse_v3_version_line),
     'lifetime': (None, _parse_lifetime_line),
     'signing_cert': (None, _parse_signing_key_line),
+    'revision_counter': (None, _parse_revision_counter_line),
   }
 
   PARSER_FOR_LINE = {
     'hs-descriptor': _parse_v3_version_line,
     'descriptor-lifetime': _parse_lifetime_line,
     'descriptor-signing-key-cert': _parse_signing_key_line,
+    'revision-counter': _parse_revision_counter_line,
   }
 
   @classmethod
diff --git a/test/unit/descriptor/hidden_service_v3.py b/test/unit/descriptor/hidden_service_v3.py
index 07a8e32c..5a5f53d4 100644
--- a/test/unit/descriptor/hidden_service_v3.py
+++ b/test/unit/descriptor/hidden_service_v3.py
@@ -39,6 +39,7 @@ class TestHiddenServiceDescriptorV3(unittest.TestCase):
     self.assertEqual(3, desc.version)
     self.assertEqual(180, desc.lifetime)
     self.assertEqual(EXPECTED_SIGNING_CERT, desc.signing_cert)
+    self.assertEqual(15, desc.revision_counter)
 
   def test_invalid_version(self):
     """
@@ -67,3 +68,17 @@ class TestHiddenServiceDescriptorV3(unittest.TestCase):
 
     for test_value in test_values:
       expect_invalid_attr(self, {'descriptor-lifetime': test_value}, 'lifetime')
+
+  def test_invalid_revision_counter(self):
+    """
+    Checks that our revision counter field expects a numeric value.
+    """
+
+    test_values = (
+      '',
+      '-10',
+      'hello',
+    )
+
+    for test_value in test_values:
+      expect_invalid_attr(self, {'revision-counter': test_value}, 'revision_counter')



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