Skip to content

Commit e2b45cd

Browse files
authored
Merge pull request #212 from clintonb/from-file-fix
Updated PrivateKey.from_file to handle encrypted keys
2 parents af750b0 + a5d604d commit e2b45cd

2 files changed

Lines changed: 8 additions & 6 deletions

File tree

Exscript/key.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,13 @@ def from_file(filename, password='', keytype=None):
6868
"""
6969
if keytype is None:
7070
try:
71-
key = RSAKey.from_private_key_file(filename)
71+
RSAKey.from_private_key_file(filename, password=password)
7272
keytype = 'rsa'
73-
except SSHException as e:
73+
except SSHException:
7474
try:
75-
key = DSSKey.from_private_key_file(filename)
75+
DSSKey.from_private_key_file(filename, password=password)
7676
keytype = 'dss'
77-
except SSHException as e:
77+
except SSHException:
7878
msg = 'not a recognized private key: ' + repr(filename)
7979
raise ValueError(msg)
8080
key = PrivateKey(keytype)

tests/Exscript/PrivateKeyTest.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1+
import os.path
12
import sys
23
import unittest
3-
import re
4-
import os.path
4+
55
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..', '..'))
66

77
from Exscript import PrivateKey
@@ -54,5 +54,7 @@ def testSetPassword(self):
5454

5555
def suite():
5656
return unittest.TestLoader().loadTestsFromTestCase(PrivateKeyTest)
57+
58+
5759
if __name__ == '__main__':
5860
unittest.TextTestRunner(verbosity=2).run(suite())

0 commit comments

Comments
 (0)