diff options
author | Jeff Forcier <jeff@bitprophet.org> | 2017-02-20 21:02:29 -0800 |
---|---|---|
committer | Jeff Forcier <jeff@bitprophet.org> | 2017-02-20 21:02:29 -0800 |
commit | de45684a49d2a94a0bd97385153717acda41ccc5 (patch) | |
tree | 4de354b95534f94648d2b3b17b3e59b722d1b546 | |
parent | e096e2c79e463177aa7622b28c2e6e5f3b8fadcd (diff) | |
parent | 78a5e2bf311f33b1d0a5eea8827f0581d2761ea6 (diff) | |
download | paramiko-de45684a49d2a94a0bd97385153717acda41ccc5.tar.gz |
Merge branch '1.17' into 1.18
-rw-r--r-- | paramiko/rsakey.py | 13 | ||||
-rw-r--r-- | sites/www/changelog.rst | 3 | ||||
-rw-r--r-- | tests/test_pkey.py | 11 |
3 files changed, 24 insertions, 3 deletions
diff --git a/paramiko/rsakey.py b/paramiko/rsakey.py index 4ebd8354..3a7cb960 100644 --- a/paramiko/rsakey.py +++ b/paramiko/rsakey.py @@ -30,7 +30,7 @@ from paramiko.common import max_byte, zero_byte, one_byte from paramiko.message import Message from paramiko.ber import BER, BERException from paramiko.pkey import PKey -from paramiko.py3compat import long +from paramiko.py3compat import long, PY2 from paramiko.ssh_exception import SSHException SHA1_DIGESTINFO = b'\x30\x21\x30\x09\x06\x05\x2b\x0e\x03\x02\x1a\x05\x00\x04\x14' @@ -75,7 +75,16 @@ class RSAKey (PKey): return m.asbytes() def __str__(self): - return self.asbytes() + # NOTE: as per inane commentary in #853, this appears to be the least + # crummy way to get a representation that prints identical to Python + # 2's previous behavior, on both interpreters. + # TODO: replace with a nice clean fingerprint display or something + if PY2: + # Can't just return the .decode below for Py2 because stuff still + # tries stuffing it into ASCII for whatever godforsaken reason + return self.asbytes() + else: + return self.asbytes().decode('utf8', errors='ignore') def __hash__(self): h = hash(self.get_name()) diff --git a/sites/www/changelog.rst b/sites/www/changelog.rst index 02120e31..9745e53f 100644 --- a/sites/www/changelog.rst +++ b/sites/www/changelog.rst @@ -2,6 +2,9 @@ Changelog ========= +* :bug:`853 (1.17+)` Tweak how `RSAKey.__str__ <paramiko.rsakey.RSAKey>` + behaves so it doesn't cause ``TypeError`` under Python 3. Thanks to Francisco + Couzo for the report. * :bug:`862 (1.17+)` (via :issue:`863`) Avoid test suite exceptions on platforms lacking ``errno.ETIME`` (which seems to be some FreeBSD and some Windows environments.) Thanks to Sofian Brabez. diff --git a/tests/test_pkey.py b/tests/test_pkey.py index f673254f..b16f5255 100644 --- a/tests/test_pkey.py +++ b/tests/test_pkey.py @@ -1,3 +1,4 @@ +# -*- coding: utf-8 -*- # Copyright (C) 2003-2009 Robey Pointer <robeypointer@gmail.com> # # This file is part of paramiko. @@ -26,7 +27,7 @@ from binascii import hexlify from hashlib import md5 from paramiko import RSAKey, DSSKey, ECDSAKey, Message, util -from paramiko.py3compat import StringIO, byte_chr, b, bytes +from paramiko.py3compat import StringIO, byte_chr, b, bytes, PY2 from tests.util import test_path @@ -83,6 +84,9 @@ ADRvOqQ5R98Sxst765CAqXmRtz8vwoD96g== x1234 = b'\x01\x02\x03\x04' +TEST_KEY_BYTESTR_2 = '\x00\x00\x00\x07ssh-rsa\x00\x00\x00\x01#\x00\x00\x00\x81\x00\xd3\x8fV\xea\x07\x85\xa6k%\x8d<\x1f\xbc\x8dT\x98\xa5\x96$\xf3E#\xbe>\xbc\xd2\x93\x93\x87f\xceD\x18\xdb \x0c\xb3\xa1a\x96\xf8e#\xcc\xacS\x8a#\xefVlE\x83\x1epv\xc1o\x17M\xef\xdf\x89DUXL\xa6\x8b\xaa<\x06\x10\xd7\x93w\xec\xaf\xe2\xaf\x95\xd8\xfb\xd9\xbfw\xcb\x9f0)#y{\x10\x90\xaa\x85l\tPru\x8c\t\x19\xce\xa0\xf1\xd2\xdc\x8e/\x8b\xa8f\x9c0\xdey\x84\xd2F\xf7\xcbmm\x1f\x87' +TEST_KEY_BYTESTR_3 = '\x00\x00\x00\x07ssh-rsa\x00\x00\x00\x01#\x00\x00\x00\x00ӏV\x07k%<\x1fT$E#>ғfD\x18 \x0cae#̬S#VlE\x1epvo\x17M߉DUXL<\x06\x10דw\u2bd5ٿw˟0)#y{\x10l\tPru\t\x19Π\u070e/f0yFmm\x1f' + class KeyTest (unittest.TestCase): @@ -271,3 +275,8 @@ class KeyTest (unittest.TestCase): self.assertEqual(key, key2) finally: os.remove(newfile) + + def test_stringification(self): + key = RSAKey.from_private_key_file(test_path('test_rsa.key')) + comparable = TEST_KEY_BYTESTR_2 if PY2 else TEST_KEY_BYTESTR_3 + self.assertEqual(str(key), comparable) |