Merge lp:~stefanor/ibid/crypto-391614 into lp:~ibid-core/ibid/old-trunk-pack-0.92

Proposed by Stefano Rivera
Status: Superseded
Proposed branch: lp:~stefanor/ibid/crypto-391614
Merge into: lp:~ibid-core/ibid/old-trunk-pack-0.92
Diff against target: None lines
To merge this branch: bzr merge lp:~stefanor/ibid/crypto-391614
Reviewer Review Type Date Requested Status
Jonathan Hitchcock Approve
Michael Gorven Approve
Review via email: mp+7845@code.launchpad.net

This proposal has been superseded by a proposal from 2009-06-28.

To post a comment you must log in.
Revision history for this message
Michael Gorven (mgorven) wrote :

 review approve

review: Approve
Revision history for this message
Jonathan Hitchcock (vhata) wrote :

base64 should match 'base10' as well as 'b10' etc, but ja.

review: Approve
lp:~stefanor/ibid/crypto-391614 updated
675. By Stefano Rivera

Friendlier base64 regex. Handle invalid padding

676. By Stefano Rivera

UTF-8 encode input data for crypt and hash

Unmerged revisions

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'ibid/plugins/crypto.py'
2--- ibid/plugins/crypto.py 2009-05-09 16:18:37 +0000
3+++ ibid/plugins/crypto.py 2009-06-24 14:23:42 +0000
4@@ -13,22 +13,32 @@
5 crypt <string> <salt>"""
6 feature = 'hash'
7
8- @match(r'^(md5|sha1|sha224|sha256|sha384|sha512)\s+(.+?)$')
9+ @match(r'^(md5|sha1|sha224|sha256|sha384|sha512)(?:sum)?\s+(.+?)$')
10 def hash(self, event, hash, string):
11- event.addresponse(eval('hashlib.%s' % hash.lower())(string).hexdigest())
12+ func = getattr(hashlib, hash.lower())
13+ event.addresponse(unicode(func(string).hexdigest()))
14
15 @match(r'^crypt\s+(.+)\s+(\S+)$')
16 def handle_crypt(self, event, string, salt):
17- event.addresponse(crypt(string, salt))
18+ event.addresponse(unicode(crypt(string, salt)))
19
20-help['base64'] = u'Encodes and decodes base 16, 32 and 64.'
21+help['base64'] = u'Encodes and decodes base 16, 32 and 64. Assumes UTF-8.'
22 class Base64(Processor):
23 u"""b(16|32|64)(encode|decode) <string>"""
24 feature = 'base64'
25
26 @match(r'^b(16|32|64)(enc|dec)(?:ode)?\s+(.+?)$')
27 def base64(self, event, base, operation, string):
28- event.addresponse(eval('base64.b%s%sode' % (base, operation.lower()))(string))
29+ operation = operation.lower()
30+ func = getattr(base64, 'b%s%sode' % (base, operation))
31+ if operation == 'dec':
32+ bytes = func(string)
33+ try:
34+ event.addresponse(u"Assuming UTF-8: '%s'", unicode(bytes, 'utf-8', 'strict'))
35+ except UnicodeDecodeError:
36+ event.addresponse(u'Not UTF-8: %s', unicode(repr(bytes)))
37+ else:
38+ event.addresponse(unicode(func(string.encode('utf-8'))))
39
40 help['rot13'] = u'Transforms a string with ROT13.'
41 class Rot13(Processor):

Subscribers

People subscribed via source and target branches