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

Proposed by Stefano Rivera
Status: Merged
Approved by: Stefano Rivera
Approved revision: 675
Merged at revision: 676
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
Michael Gorven Approve
Jonathan Hitchcock Approve
Review via email: mp+7987@code.launchpad.net

This proposal supersedes a proposal from 2009-06-24.

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

 review approve

review: Approve
Revision history for this message
Jonathan Hitchcock (vhata) wrote : Posted in a previous version of this proposal

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

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

 review approve

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

UTF-8 encode input data for crypt and hash

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-28 13:26:51 +0000
4@@ -13,22 +13,35 @@
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+ u"""base(16|32|64) (encode|decode) <string>"""
25 feature = 'base64'
26
27- @match(r'^b(16|32|64)(enc|dec)(?:ode)?\s+(.+?)$')
28+ @match(r'^b(?:ase)?(16|32|64)\s*(enc|dec)(?:ode)?\s+(.+?)$')
29 def base64(self, event, base, operation, string):
30- event.addresponse(eval('base64.b%s%sode' % (base, operation.lower()))(string))
31+ operation = operation.lower()
32+ func = getattr(base64, 'b%s%sode' % (base, operation))
33+ if operation == 'dec':
34+ try:
35+ bytes = func(string)
36+ event.addresponse(u"Assuming UTF-8: '%s'", unicode(bytes, 'utf-8', 'strict'))
37+ except TypeError, e:
38+ event.addresponse(u"Invalid base%(base)s: %(error)s",
39+ {'base': base, 'error': unicode(e)})
40+ except UnicodeDecodeError:
41+ event.addresponse(u'Not UTF-8: %s', unicode(repr(bytes)))
42+ else:
43+ event.addresponse(unicode(func(string.encode('utf-8'))))
44
45 help['rot13'] = u'Transforms a string with ROT13.'
46 class Rot13(Processor):

Subscribers

People subscribed via source and target branches