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

[tor-commits] [stem/master] Drop sign arg from _descriptor_content() helper



commit a2ff99195fafde3df96c667b12818aa5d9f8baec
Author: Damian Johnson <atagar@xxxxxxxxxxxxxx>
Date:   Sat Jul 1 12:15:42 2017 -0700

    Drop sign arg from _descriptor_content() helper
    
    The _descriptor_content() didn't actually use the sign arg except to do a
    dependency check, which all callers already do.
---
 stem/descriptor/__init__.py                  | 8 +-------
 stem/descriptor/extrainfo_descriptor.py      | 6 +++---
 stem/descriptor/hidden_service_descriptor.py | 2 +-
 stem/descriptor/microdescriptor.py           | 2 +-
 stem/descriptor/networkstatus.py             | 8 ++++----
 stem/descriptor/router_status_entry.py       | 6 +++---
 stem/descriptor/server_descriptor.py         | 6 +++---
 test/unit/tutorial_examples.py               | 3 +--
 8 files changed, 17 insertions(+), 24 deletions(-)

diff --git a/stem/descriptor/__init__.py b/stem/descriptor/__init__.py
index f78de9a..e883c55 100644
--- a/stem/descriptor/__init__.py
+++ b/stem/descriptor/__init__.py
@@ -355,7 +355,7 @@ def _parse_metrics_file(descriptor_type, major_version, minor_version, descripto
     raise TypeError("Unrecognized metrics descriptor format. type: '%s', version: '%i.%i'" % (descriptor_type, major_version, minor_version))
 
 
-def _descriptor_content(attr = None, exclude = (), sign = False, header_template = (), footer_template = ()):
+def _descriptor_content(attr = None, exclude = (), header_template = (), footer_template = ()):
   """
   Constructs a minimal descriptor with the given attributes. The content we
   provide back is of the form...
@@ -386,18 +386,12 @@ def _descriptor_content(attr = None, exclude = (), sign = False, header_template
 
   :param dict attr: keyword/value mappings to be included in the descriptor
   :param list exclude: mandatory keywords to exclude from the descriptor
-  :param bool sign: includes cryptographic signatures and digests if True
   :param tuple header_template: key/value pairs for mandatory fields before unrecognized content
   :param tuple footer_template: key/value pairs for mandatory fields after unrecognized content
 
   :returns: bytes with the requested descriptor content
-
-  :raises: **ImportError** if cryptography is unavailable and sign is True
   """
 
-  if sign and not stem.prereq.is_crypto_available():
-    raise ImportError('Signing descriptors requries the cryptography module')
-
   header_content, footer_content = [], []
   attr = {} if attr is None else dict(attr)  # shallow copy since we're destructive
 
diff --git a/stem/descriptor/extrainfo_descriptor.py b/stem/descriptor/extrainfo_descriptor.py
index 08a07ab..bfea309 100644
--- a/stem/descriptor/extrainfo_descriptor.py
+++ b/stem/descriptor/extrainfo_descriptor.py
@@ -975,10 +975,10 @@ class RelayExtraInfoDescriptor(ExtraInfoDescriptor):
       if signing_key is None:
         signing_key = create_signing_key()
 
-      content = _descriptor_content(attr, exclude, sign, base_header) + b'\nrouter-signature\n'
+      content = _descriptor_content(attr, exclude, base_header) + b'\nrouter-signature\n'
       return _append_router_signature(content, signing_key.private)
     else:
-      return _descriptor_content(attr, exclude, sign, base_header, (
+      return _descriptor_content(attr, exclude, base_header, (
         ('router-signature', _random_crypto_blob('SIGNATURE')),
       ))
 
@@ -1023,7 +1023,7 @@ class BridgeExtraInfoDescriptor(ExtraInfoDescriptor):
     if sign:
       raise NotImplementedError('Signing of %s not implemented' % cls.__name__)
 
-    return _descriptor_content(attr, exclude, sign, (
+    return _descriptor_content(attr, exclude, (
       ('extra-info', 'ec2bridgereaac65a3 %s' % _random_fingerprint()),
       ('published', _random_date()),
     ), (
diff --git a/stem/descriptor/hidden_service_descriptor.py b/stem/descriptor/hidden_service_descriptor.py
index c78c9f0..2e08b78 100644
--- a/stem/descriptor/hidden_service_descriptor.py
+++ b/stem/descriptor/hidden_service_descriptor.py
@@ -242,7 +242,7 @@ class HiddenServiceDescriptor(Descriptor):
     if sign:
       raise NotImplementedError('Signing of %s not implemented' % cls.__name__)
 
-    return _descriptor_content(attr, exclude, sign, (
+    return _descriptor_content(attr, exclude, (
       ('rendezvous-service-descriptor', 'y3olqqblqw2gbh6phimfuiroechjjafa'),
       ('version', '2'),
       ('permanent-key', _random_crypto_blob('RSA PUBLIC KEY')),
diff --git a/stem/descriptor/microdescriptor.py b/stem/descriptor/microdescriptor.py
index 1cd1ce6..c99e371 100644
--- a/stem/descriptor/microdescriptor.py
+++ b/stem/descriptor/microdescriptor.py
@@ -263,7 +263,7 @@ class Microdescriptor(Descriptor):
     if sign:
       raise NotImplementedError('Signing of %s not implemented' % cls.__name__)
 
-    return _descriptor_content(attr, exclude, sign, (
+    return _descriptor_content(attr, exclude, (
       ('onion-key', _random_crypto_blob('RSA PUBLIC KEY')),
     ))
 
diff --git a/stem/descriptor/networkstatus.py b/stem/descriptor/networkstatus.py
index af2e41a..1c0acab 100644
--- a/stem/descriptor/networkstatus.py
+++ b/stem/descriptor/networkstatus.py
@@ -468,7 +468,7 @@ class NetworkStatusDocumentV2(NetworkStatusDocument):
     if sign:
       raise NotImplementedError('Signing of %s not implemented' % cls.__name__)
 
-    return _descriptor_content(attr, exclude, sign, (
+    return _descriptor_content(attr, exclude, (
       ('network-status-version', '2'),
       ('dir-source', '%s %s 80' % (_random_ipv4_address(), _random_ipv4_address())),
       ('fingerprint', _random_fingerprint()),
@@ -945,7 +945,7 @@ class NetworkStatusDocumentV3(NetworkStatusDocument):
       elif k not in attr:
         attr[k] = v
 
-    desc_content = _descriptor_content(attr, exclude, sign, (
+    desc_content = _descriptor_content(attr, exclude, (
       ('network-status-version', '3'),
       ('vote-status', 'consensus'),
       ('consensus-methods', None),
@@ -1424,7 +1424,7 @@ class DirectoryAuthority(Descriptor):
     if not is_vote and not ('vote-digest' in attr or (exclude and 'vote-digest' in exclude)):
       attr['vote-digest'] = _random_fingerprint()
 
-    content = _descriptor_content(attr, exclude, sign, (
+    content = _descriptor_content(attr, exclude, (
       ('dir-source', '%s %s no.place.com %s 9030 9090' % (_random_nickname(), _random_fingerprint(), _random_ipv4_address())),
       ('contact', 'Mike Perry <email>'),
     ))
@@ -1617,7 +1617,7 @@ class KeyCertificate(Descriptor):
     if sign:
       raise NotImplementedError('Signing of %s not implemented' % cls.__name__)
 
-    return _descriptor_content(attr, exclude, sign, (
+    return _descriptor_content(attr, exclude, (
       ('dir-key-certificate-version', '3'),
       ('fingerprint', _random_fingerprint()),
       ('dir-key-published', _random_date()),
diff --git a/stem/descriptor/router_status_entry.py b/stem/descriptor/router_status_entry.py
index 34e9a6a..81bc63d 100644
--- a/stem/descriptor/router_status_entry.py
+++ b/stem/descriptor/router_status_entry.py
@@ -520,7 +520,7 @@ class RouterStatusEntryV2(RouterStatusEntry):
     if sign:
       raise NotImplementedError('Signing of %s not implemented' % cls.__name__)
 
-    return _descriptor_content(attr, exclude, sign, (
+    return _descriptor_content(attr, exclude, (
       ('r', '%s p1aag7VwarGxqctS7/fS0y5FU+s oQZFLYe9e4A7bOkWKR7TaNxb0JE %s %s 9001 0' % (_random_nickname(), _random_date(), _random_ipv4_address())),
     ))
 
@@ -622,7 +622,7 @@ class RouterStatusEntryV3(RouterStatusEntry):
     if sign:
       raise NotImplementedError('Signing of %s not implemented' % cls.__name__)
 
-    return _descriptor_content(attr, exclude, sign, (
+    return _descriptor_content(attr, exclude, (
       ('r', '%s p1aag7VwarGxqctS7/fS0y5FU+s oQZFLYe9e4A7bOkWKR7TaNxb0JE %s %s 9001 0' % (_random_nickname(), _random_date(), _random_ipv4_address())),
       ('s', 'Fast Named Running Stable Valid'),
     ))
@@ -701,7 +701,7 @@ class RouterStatusEntryMicroV3(RouterStatusEntry):
     if sign:
       raise NotImplementedError('Signing of %s not implemented' % cls.__name__)
 
-    return _descriptor_content(attr, exclude, sign, (
+    return _descriptor_content(attr, exclude, (
       ('r', '%s ARIJF2zbqirB9IwsW0mQznccWww %s %s 9001 9030' % (_random_nickname(), _random_date(), _random_ipv4_address())),
       ('m', 'aiUklwBrua82obG5AsTX+iEpkjQA2+AQHxZ7GwMfY70'),
       ('s', 'Fast Guard HSDir Named Running Stable V2Dir Valid'),
diff --git a/stem/descriptor/server_descriptor.py b/stem/descriptor/server_descriptor.py
index 793cb8d..351a7ff 100644
--- a/stem/descriptor/server_descriptor.py
+++ b/stem/descriptor/server_descriptor.py
@@ -834,10 +834,10 @@ class RelayDescriptor(ServerDescriptor):
 
       attr['signing-key'] = signing_key.public_digest
 
-      content = _descriptor_content(attr, exclude, sign, base_header) + b'\nrouter-signature\n'
+      content = _descriptor_content(attr, exclude, base_header) + b'\nrouter-signature\n'
       return _append_router_signature(content, signing_key.private)
     else:
-      return _descriptor_content(attr, exclude, sign, base_header, (
+      return _descriptor_content(attr, exclude, base_header, (
         ('router-signature', _random_crypto_blob('SIGNATURE')),
       ))
 
@@ -961,7 +961,7 @@ class BridgeDescriptor(ServerDescriptor):
     if sign:
       raise NotImplementedError('Signing of %s not implemented' % cls.__name__)
 
-    return _descriptor_content(attr, exclude, sign, (
+    return _descriptor_content(attr, exclude, (
       ('router', '%s %s 9001 0 0' % (_random_nickname(), _random_ipv4_address())),
       ('router-digest', '006FD96BA35E7785A6A3B8B75FE2E2435A13BDB4'),
       ('published', _random_date()),
diff --git a/test/unit/tutorial_examples.py b/test/unit/tutorial_examples.py
index b47de51..ecc9b5c 100644
--- a/test/unit/tutorial_examples.py
+++ b/test/unit/tutorial_examples.py
@@ -315,9 +315,8 @@ class TestTutorialExamples(unittest.TestCase):
 
   @patch('sys.stdout', new_callable = StringIO)
   @patch('stem.descriptor.parse_file')
-  @patch('%s.open' % __name__, create = True)
   @patch('stem.descriptor.remote.Query')
-  def test_persisting_a_consensus(self, query_mock, open_mock, parse_file_mock, stdout_mock):
+  def test_persisting_a_consensus(self, query_mock, parse_file_mock, stdout_mock):
     def tutorial_example_2():
       from stem.descriptor import DocumentHandler, parse_file
 



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