[gnome-keysign: 1/2] avahi: unify API with the the other offer classes



commit 6fed6c3e7c3d197248111870d3acf3ea10160bc9
Author: Tobias Mueller <muelli cryptobitch de>
Date:   Wed May 8 09:23:49 2019 +0200

    avahi: unify API with the the other offer classes
    
    We now offer a allocate_code as well as a start function.
    The former still being a bit of a misnomer. It should probably be named
    something like "get_discovery_information". And we might enjoy a
    "_and_run()" version for not having to do two calls to the class.

 keysign/avahioffer.py | 11 +++++++----
 keysign/offer.py      |  8 +++-----
 2 files changed, 10 insertions(+), 9 deletions(-)
---
diff --git a/keysign/avahioffer.py b/keysign/avahioffer.py
index 6c9434e..5b865d9 100755
--- a/keysign/avahioffer.py
+++ b/keysign/avahioffer.py
@@ -53,17 +53,19 @@ class AvahiHTTPOffer:
         self.keyserver = Keyserver.ServeKeyThread(keydata, fingerprint)
         self.mac = mac_generate(fingerprint.encode('ascii'), keydata)
 
-    def start(self):
-        """Starts offering the key"""
+    def allocate_code(self):
+        """Returns the information necessary to discover the key through Avahi"""
         fingerprint = self.fingerprint.upper()
         mac = self.mac.upper()
         discovery_info = 'OPENPGP4FPR:{0}#MAC={1}'.format(
                                 fingerprint, mac)
+        return format_fingerprint(self.key.fingerprint), discovery_info
 
+    def start(self):
+        """Starts offering the key"""
         log.info("Requesting to start")
         self.keyserver.start()
 
-        return format_fingerprint(self.key.fingerprint), discovery_info
 
     def stop(self):
         "Stops offering the key"
@@ -77,9 +79,10 @@ def main(args):
 
     key = get_usable_keys(pattern=args[0])[0]
     offer = AvahiHTTPOffer(key)
-    discovery_info = offer.start()
+    discovery_info = offer.allocate_code()
     print (_("Offering key: {}").format(key))
     print (_("Discovery info: {}").format(discovery_info))
+    offer.start()
     print (_("Press Enter to stop"))
     try: input_ = raw_input
     except NameError: input_ = input
diff --git a/keysign/offer.py b/keysign/offer.py
index 4328417..d6adabb 100644
--- a/keysign/offer.py
+++ b/keysign/offer.py
@@ -24,8 +24,7 @@ class Offer:
     @inlineCallbacks
     def allocate_code(self, worm=True):
         self.a_offer = AvahiHTTPOffer(self.key)
-        a_info = self.a_offer.start()
-        code, a_data = a_info
+        code, a_data = self.a_offer.allocate_code()
         discovery_data = [a_data]
         if worm:
             self.w_offer = WormholeOffer(self.key)
@@ -44,9 +43,8 @@ class Offer:
         returnValue((code, discovery_data))
 
     def start(self):
-        # With the current workflow avahi needs to be started
-        # for allocate the code
-        d = []
+        avahi_defers = self.a_offer.start()
+        d = [avahi_defers] if avahi_defers else []
         if self.w_offer:
             w_d = self.w_offer.start()
             d.append(w_d)


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