[Nym3-commit] r223 - trunk/nym3/Client

jr at conuropsis.org jr at conuropsis.org
Tue May 3 11:49:55 CEST 2005


Author: jr
Date: 2005-05-03 11:49:55 +0200 (Tue, 03 May 2005)
New Revision: 223

Modified:
   trunk/nym3/Client/Main.py
Log:
Factorize string decypherment with one key from a pool of keys


Modified: trunk/nym3/Client/Main.py
===================================================================
--- trunk/nym3/Client/Main.py	2005-05-03 07:57:34 UTC (rev 222)
+++ trunk/nym3/Client/Main.py	2005-05-03 09:49:55 UTC (rev 223)
@@ -92,6 +92,22 @@
 	ui.display("wrong passphrase")
     return secring
 
+def decypher_string(string, keyring, key_handles):
+    """decypher string with a key contained in keyring with a handle
+    among those provided in key_handles. returns the clear text if
+    it can be found, None otherwise"""
+    #TODO is it correct that any wrong key raises an exception in pk_decrypt?
+    #TODO maybe exiting is too violent, shall we raise an exception?
+    clear = None
+    for k in key_handles:
+	enckey = _cr.pk_decode_private_key(keyring.get_key(k))
+	try:
+	    clear = _cr.pk_decrypt(string, enckey)
+	    break
+	except:
+	    pass
+    return clear
+
 def processMessage(msg, config, ui, nickname):
     """process incoming control message"""
       
@@ -126,13 +142,7 @@
 	    except Keyring.NewKeyring:
 	    # The Keyring is new. That shouldn't happen
 		raise Exception('Bug keyring?')
-	    clear = None
-	    for k in account['encKeys']:
-		enckey = _cr.pk_decode_private_key(secring.get_key(k))
-		try:
-		    clear = _cr.pk_decrypt(com.synSet, enckey)
-		    break
-		except: pass
+	    clear = decypher_string(com.synSet, secring, account['encKeys'])
 	    if not clear:
 		ui.display("Could not decrypt synopsis")
 		sys.exit(1)



More information about the Nym3-commit mailing list