From 27869f1d7ad953d2262b36e2692d784c906a40d2 Mon Sep 17 00:00:00 2001 From: Robey Pointer Date: Tue, 27 Jan 2004 02:00:19 +0000 Subject: [PATCH] [project @ Arch-1:robey@lag.net--2003-public%secsh--dev--1.0--patch-25] pkey no longer raises binascii.Error catch binascii.Error in the private key decoder and convert it into an SSHException. there's no reason people should have to care that it was a decoding error vs. any of the other million things that could be wrong in a corrupt key file. --- paramiko/pkey.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/paramiko/pkey.py b/paramiko/pkey.py index d5e4a0e..ece7023 100644 --- a/paramiko/pkey.py +++ b/paramiko/pkey.py @@ -150,8 +150,7 @@ class PKey (object): @raise IOError: if there was an error reading the file. @raise PasswordRequiredException: if the private key file is encrypted, and C{password} is C{None}. - @raise SSHException: if the key file is invalid - @raise binascii.Error: on base64 decoding error + @raise SSHException: if the key file is invalid. """ pass @@ -177,7 +176,6 @@ class PKey (object): @raise PasswordRequiredException: if the private key file is encrypted, and C{password} is C{None}. @raise SSHException: if the key file is invalid. - @raise binascii.Error: on base64 decoding error. """ f = open(filename, 'r') lines = f.readlines() @@ -201,7 +199,10 @@ class PKey (object): while (lines[end].strip() != '-----END ' + tag + ' PRIVATE KEY-----') and (end < len(lines)): end += 1 # if we trudged to the end of the file, just try to cope. - data = base64.decodestring(''.join(lines[start:end])) + try: + data = base64.decodestring(''.join(lines[start:end])) + except binascii.Error, e: + raise SSHException('base64 decoding error: ' + str(e)) if not headers.has_key('proc-type'): # unencryped: done return data