Exemplo n.º 1
0
 def load(self) -> PKey:
     if os.path.isfile(self.path):
         classes = PKey.__subclasses__()
         last = len(classes) + 1
         for i, cls in enumerate(classes):
             try:
                 return cls.from_private_key_file(self.path)
             except SSHException:
                 if i == last:
                     raise
                 continue
     raise EmptyStoreError()
Exemplo n.º 2
0
def read_private_key_file(file_: io.IOBase) -> PKey:
    """Read a private key file.  Similar to :meth:`PKey.from_private_key()
    <paramiko.pkey.PKey.from_private_key>` except it guess the key type.

    :param file_: a stream of the private key to read
    :type file_: :class:`io.IOBase`
    :return: the read private key
    :rtype: :class:`paramiko.pkey.PKery`
    :raise paramiko.ssh_exception.SSHException: when something goes wrong

    """
    classes = PKey.__subclasses__()
    last = len(classes) + 1
    for i, cls in enumerate(classes):
        try:
            return cls.from_private_key(file_)
        except SSHException:
            if i == last:
                raise
            file_.seek(0)
            continue