Skip to content

Commit

Permalink
Add crypto support to t_show and t_describe. Fix some bugs on t_edit …
Browse files Browse the repository at this point in the history
…and passphrase validity check
  • Loading branch information
digitalfox committed Jul 6, 2010
1 parent ab49fa8 commit d5b717d
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 4 deletions.
3 changes: 3 additions & 0 deletions src/yokadi/cryptutils.py
Expand Up @@ -112,6 +112,9 @@ def isEncrypted(self, data):
def isPassphraseValid(self):
"""Check if user passphrase is valid.
ie. : if it can decrypt the check crypto word"""
if not self.passphrase:
# If no passphrase has been defined, it is definitively not valid !
return False
if self.crypto_check:
try:
int(self._decrypt(self.crypto_check))
Expand Down
33 changes: 29 additions & 4 deletions src/yokadi/taskcmd.py
Expand Up @@ -166,10 +166,18 @@ def do_t_describe(self, line):
t_describe <id>"""
task = self.getTaskFromId(line)
try:
description = tui.editText(task.description)
if self.cryptoMgr.isEncrypted(task.title):
# As title is encrypted, we assume description will be encrypted as well
description = self.cryptoMgr.decrypt(task.description)
else:
description = task.description
description = tui.editText(description)
except Exception, e:
raise YokadiException(e)
task.description = description
if self.cryptoMgr.isEncrypted(task.title):
task.description = self.cryptoMgr.encrypt(description)
else:
task.description = description

complete_t_describe = taskIdCompleter

Expand Down Expand Up @@ -604,6 +612,9 @@ def parser_t_show(self):
default="all",
help="<output> can be one of %s. If not set, it defaults to all." % ", ".join(choices),
metavar="<output>")
parser.add_option("-d", dest="decrypt", default=False, action="store_true",
help="Decrypt task description")

return parser

def do_t_show(self, line):
Expand All @@ -612,6 +623,17 @@ def do_t_show(self, line):

task = self.getTaskFromId(' '.join(args))

if self.cryptoMgr.isEncrypted(task.title):
if self.cryptoMgr.isPassphraseValid() or options.decrypt:
title = self.cryptoMgr.decrypt(task.title)
description = self.cryptoMgr.decrypt(task.description)
else:
title = "<... encrypted data...>"
description = "<... encrypted data...>"
else:
title = task.title
description = task.description

if options.output in ("all", "summary"):
keywordDict = task.getKeywordDict()
keywordArray = []
Expand All @@ -624,7 +646,7 @@ def do_t_show(self, line):
keywords = ", ".join(keywordArray)
fields = [
("Project", task.project.name),
("Title", task.title),
("Title", title),
("Created", task.creationDate),
("Due", task.dueDate),
("Status", task.status),
Expand All @@ -641,7 +663,7 @@ def do_t_show(self, line):
if options.output in ("all", "description") and task.description:
if options.output == "all":
print
print task.description
print description

complete_t_show = taskIdCompleter

Expand Down Expand Up @@ -669,6 +691,9 @@ def editComplete(text, state):

if self.cryptoMgr.isEncrypted(task.title):
title = self.cryptoMgr.decrypt(task.title)
else:
title = task.title

# Create task line
taskLine = parseutils.createLine("", title, task.getKeywordDict())

Expand Down

0 comments on commit d5b717d

Please sign in to comment.