[Nym3-commit] r341 - trunk/nymbaron/Client

jr at conuropsis.org jr at conuropsis.org
Wed Oct 12 20:24:02 CEST 2005


Author: jr
Date: 2005-10-12 20:24:02 +0200 (Wed, 12 Oct 2005)
New Revision: 341

Modified:
   trunk/nymbaron/Client/Main.py
Log:
- check for the existence of the keyring in decode secring
- replace ui, config in the signature of build_syn_index by secring
- remove unused arguments of build_journal_index
- Get ask only once for the passphrase


Modified: trunk/nymbaron/Client/Main.py
===================================================================
--- trunk/nymbaron/Client/Main.py	2005-10-12 18:20:11 UTC (rev 340)
+++ trunk/nymbaron/Client/Main.py	2005-10-12 18:24:02 UTC (rev 341)
@@ -116,7 +116,11 @@
 	return sys.stdin.read()
 
 def decode_secring(config, ui):
-    secring = Keyring.Keyring(config.secring_path)
+    try:
+	secring = Keyring.Keyring(config.secring_path)
+    except Keyring.NewKeyring:
+	# The Keyring is new. That shouldn't happen
+	raise Exception('Bug keyring?')
     ui.display("You need to provide your passphrase to unlock your keyring")
     while True:
 	passphrase1 = ui.prompthidden("Passphrase")
@@ -150,11 +154,11 @@
 	ui.display("No account relative to the provided nickname, abort")
 	sys.exit(1)
 
-def build_syn_index(ui, config, account):
-    """Builds the index of synopses of the given account, using ui to get
-    the password to decrypt the keyring. Returns a hash containing the
-    correspondance index -> mid, where index is a XNymSeq as a str"""
-    secring = decode_secring(config, ui)
+def build_syn_index(secring, account):
+    """Builds the index of synopses of the given account. secring must be
+    decrypted and contain the private admin key of account. Returns a hash
+    containing the correspondance index -> mid, where index is a XNymSeq as a
+    str"""
     synbox = account.get_synbox(secring)
     index = {}
     for xnymseq, (mid, flag, syn) in synbox.iteritems():
@@ -167,7 +171,7 @@
     mbox, index = account.get_mbox()
     return dict([(str(i), j) for (i, j) in enumerate(index)])
 
-def build_journal_index(ui, config, secring, account):
+def build_journal_index(secring, account):
     """Builds the index of the journal of the given account. Returns a hash
     containing the correspondance index -> seqno, index as a str. secring must
     be decrypted"""
@@ -435,8 +439,9 @@
 	    older = binascii.unhexlify(older)
 	else:
 	    try:
+		secring = decode_secring(config, ui)
 		l = decode_message_references([older], ['syn'],
-		    {'syn': (build_syn_index, (ui, config, account))})
+		    {'syn': (build_syn_index, (secring, account))})
 	    except DecodeException, inst:
 		ui.display(str(inst))
 		sys.exit(1)
@@ -465,8 +470,9 @@
 	    "No nickname given, abort\nUse -n <nickname>")   
     delmsg = Message.Delete()
     try:
+	secring = decode_secring(config, ui)
 	midlist = decode_message_references(midlist, ['syn'],
-	        {'syn': (build_syn_index, (ui, config, account))})
+	        {'syn': (build_syn_index, (secring, account))})
     except DecodeException, inst:
 	ui.display(str(inst))
 	sys.exit(1)
@@ -490,25 +496,16 @@
     account = get_account_from_nickname(ui, config, nickname,
 	    "No nickname given, abort\nUse -n <nickname>")
     getmsg = Message.Get()
+    secring = decode_secring(config, ui)
     try:
 	midlist = decode_message_references(midlist, ['syn'],
-	        {'syn': (build_syn_index, (ui, config, account))})
+	        {'syn': (build_syn_index, (secring, account))})
     except DecodeException, inst:
 	ui.display(str(inst))
 	sys.exit(1)
     #if the midlist is empty, do nothing
     if not midlist: return
     getmsg.fromData(midlist)
-    try:
-	secring = Keyring.Keyring(config.secring_path)
-	ui.display("You need to provide your passphrase to unlock your keyring")
-	while True:
-		passphrase1 = ui.prompthidden("Passphrase")
-		if secring.decrypt(passphrase1): break
-		ui.display("wrong passphrase")
-    except Keyring.NewKeyring:
-	# The Keyring is new. That shouldn't happen
-	raise Exception('Bug keyring?')
     idKey = _cr.pk_decode_private_key(secring.get_key(account['idKey']))
     account.sendControl([getmsg], idKey, "get messages")
 
@@ -522,7 +519,7 @@
 	#the items to decode as an argument?
 	seqnolist = decode_message_references(seqnolist, ['journal'],
 	        {'journal': (build_journal_index, 
-		    (ui, config, secring, account))})
+		    (secring, account))})
     except DecodeException, inst:
 	ui.display(str(inst))
 	sys.exit(1)
@@ -672,8 +669,9 @@
 def ldelete_syn(ui, config, nickname, args = []):
     account = get_account_from_nickname(ui, config, nickname,
 	    "No nickname given, abort\nUse -n <nickname>")
+    secring = decode_secring(config, ui)
     mids = decode_message_references(args, ['syn'],
-	        {'syn': (build_syn_index, (ui, config, account))})
+	        {'syn': (build_syn_index, (secring, account))})
     #if mids is empty, do nothing
     if not mids: return
     secring = decode_secring(config, ui)



More information about the Nym3-commit mailing list