mirror of
https://github.com/certbot/certbot.git
synced 2026-07-27 08:09:10 +02:00
Allow unicode input for JOSE Base64
This commit is contained in:
@@ -97,7 +97,7 @@ def jose_b64decode(arg, decoding='utf-8'):
|
||||
"""JOSE Base64 decode.
|
||||
|
||||
:param arg: Base64 string to be decoded.
|
||||
:type arg: str
|
||||
:type arg: str or unicode
|
||||
|
||||
:param decoding: Name of the encoding to be performed after
|
||||
Base64 decoding.
|
||||
@@ -107,5 +107,6 @@ def jose_b64decode(arg, decoding='utf-8'):
|
||||
:rtype: str or unicode
|
||||
|
||||
"""
|
||||
decoded = base64.urlsafe_b64decode(arg + '=' * (4 - (len(arg) % 4)))
|
||||
ascii = arg.encode('ascii') # equivalent to str(arg), for unicode input
|
||||
decoded = base64.urlsafe_b64decode(ascii + '=' * (4 - (len(ascii) % 4)))
|
||||
return decoded if decoding is None else decoded.decode(decoding)
|
||||
|
||||
@@ -126,6 +126,9 @@ class JOSEB64DecodeTest(unittest.TestCase):
|
||||
def test_with_encoding(self):
|
||||
self.assertEqual(self._call('xIU=', 'utf-8'), u'\u0105')
|
||||
|
||||
def test_unicode(self):
|
||||
self.assertEqual(self._call(u'YQ', None), 'a')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
||||
Reference in New Issue
Block a user