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

[tor-commits] [stem/master] Shorter attribute name for cert and extension types



commit 2a656032d0f755191b1da3272e8dd2bf7ed7414b
Author: Damian Johnson <atagar@xxxxxxxxxxxxxx>
Date:   Sun Mar 26 17:08:45 2017 +0200

    Shorter attribute name for cert and extension types
    
    I was avoiding calling them 'type' because it's a builtin function, but meh.
    Calling it 'cert_type' and 'extension_type' is clearly redundant.
---
 stem/descriptor/certificate.py      | 14 +++++++-------
 test/unit/descriptor/certificate.py | 12 ++++++------
 2 files changed, 13 insertions(+), 13 deletions(-)

diff --git a/stem/descriptor/certificate.py b/stem/descriptor/certificate.py
index e513dac..094667d 100644
--- a/stem/descriptor/certificate.py
+++ b/stem/descriptor/certificate.py
@@ -110,7 +110,7 @@ class Ed25519CertificateV1(Ed25519Certificate):
   Version 1 Ed25519 certificate, which are used for signing tor server
   descriptors.
 
-  :var CertType cert_type: certificate purpose
+  :var CertType type: certificate purpose
   :var datetime expiration: expiration of the certificate
   :var int key_type: format of the key
   :var bytes key: key content
@@ -129,18 +129,18 @@ class Ed25519CertificateV1(Ed25519Certificate):
     if cert_type in (0, 1, 2, 3):
       raise ValueError('Ed25519 certificate cannot have a type of %i. This is reserved to avoid conflicts with tor CERTS cells.' % cert_type)
     elif cert_type == 4:
-      self.cert_type = CertType.SIGNING
+      self.type = CertType.SIGNING
     elif cert_type == 5:
-      self.cert_type = CertType.LINK_CERT
+      self.type = CertType.LINK_CERT
     elif cert_type == 6:
-      self.cert_type = CertType.AUTH
+      self.type = CertType.AUTH
     elif cert_type == 7:
       raise ValueError('Ed25519 certificate cannot have a type of 7. This is reserved for RSA identity cross-certification.')
     else:
       raise ValueError("BUG: Ed25519 certificate type is decoded from one byte. It shouldn't be possible to have a value of %i." % cert_type)
 
     # expiration time is in hours since epoch
-    self.expiration = datetime.datetime.fromtimestamp(stem.util.str_tools._to_int(decoded[2:6]) * 60 * 60)
+    self.expiration = datetime.datetime.fromtimestamp(stem.util.str_tools._to_int(decoded[2:6]) * 3600)
 
     self.key_type = stem.util.str_tools._to_int(decoded[6])
     self.key = decoded[7:39]
@@ -178,11 +178,11 @@ class Ed25519CertificateV1(Ed25519Certificate):
       raise ValueError('Ed25519 certificate had %i bytes of unused extension data' % len(remaining_data))
 
 
-class Ed25519Extension(collections.namedtuple('Ed25519Extension', ['extension_type', 'flags', 'flag_int', 'data'])):
+class Ed25519Extension(collections.namedtuple('Ed25519Extension', ['type', 'flags', 'flag_int', 'data'])):
   """
   Extension within an Ed25519 certificate.
 
-  :var int extension_type: extension type
+  :var int type: extension type
   :var list flags: extension attribute flags
   :var int flag_int: integer encoding of the extension attribute flags
   :var bytes data: data the extension concerns
diff --git a/test/unit/descriptor/certificate.py b/test/unit/descriptor/certificate.py
index 9c1ef10..1444a10 100644
--- a/test/unit/descriptor/certificate.py
+++ b/test/unit/descriptor/certificate.py
@@ -47,18 +47,18 @@ class TestEd25519Certificate(unittest.TestCase):
     self.assertEqual(Ed25519CertificateV1, type(cert))
     self.assertEqual(1, cert.version)
     self.assertEqual(cert_bytes, cert.encoded)
-    self.assertEqual(CertType.SIGNING, cert.cert_type)
+    self.assertEqual(CertType.SIGNING, cert.type)
     self.assertEqual(datetime.datetime(1970, 1, 1, 1, 0), cert.expiration)
     self.assertEqual(1, cert.key_type)
     self.assertEqual(b'\x03' * 32, cert.key)
     self.assertEqual(b'\x01' * ED25519_SIGNATURE_LENGTH, cert.signature)
 
     self.assertEqual([
-      Ed25519Extension(extension_type = 4, flags = [ExtensionFlag.AFFECTS_VALIDATION, ExtensionFlag.UNKNOWN], flag_int = 7, data = b'\x15\x12'),
-      Ed25519Extension(extension_type = 5, flags = [ExtensionFlag.UNKNOWN], flag_int = 4, data = b''),
+      Ed25519Extension(type = 4, flags = [ExtensionFlag.AFFECTS_VALIDATION, ExtensionFlag.UNKNOWN], flag_int = 7, data = b'\x15\x12'),
+      Ed25519Extension(type = 5, flags = [ExtensionFlag.UNKNOWN], flag_int = 4, data = b''),
     ], cert.extensions)
 
-    self.assertEqual(ExtensionType.HAS_SIGNING_KEY, cert.extensions[0].extension_type)
+    self.assertEqual(ExtensionType.HAS_SIGNING_KEY, cert.extensions[0].type)
 
   def test_with_real_cert(self):
     cert = Ed25519Certificate.parse(ED25519_CERT)
@@ -66,11 +66,11 @@ class TestEd25519Certificate(unittest.TestCase):
     self.assertEqual(Ed25519CertificateV1, type(cert))
     self.assertEqual(1, cert.version)
     self.assertEqual(ED25519_CERT, cert.encoded)
-    self.assertEqual(CertType.SIGNING, cert.cert_type)
+    self.assertEqual(CertType.SIGNING, cert.type)
     self.assertEqual(datetime.datetime(2015, 8, 28, 19, 0), cert.expiration)
     self.assertEqual(1, cert.key_type)
     self.assertEqual(EXPECTED_CERT_KEY, cert.key)
-    self.assertEqual([Ed25519Extension(extension_type = 4, flags = [], flag_int = 0, data = EXPECTED_EXTENSION_DATA)], cert.extensions)
+    self.assertEqual([Ed25519Extension(type = 4, flags = [], flag_int = 0, data = EXPECTED_EXTENSION_DATA)], cert.extensions)
     self.assertEqual(EXPECTED_SIGNATURE, cert.signature)
 
   def test_non_base64(self):



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