'Get a public key from the key agent if possible, otherwise look in
the next configured identity file for one.'

def getPublicKey(self):

    if self.keyAgent:
        key = self.keyAgent.getPublicKey()
        if (key is not None):
            return key
    files = [x for x in self.options.identitys if (x not in self.usedFiles)]
    log.msg(str(self.options.identitys))
    log.msg(str(files))
    if (not files):
        return None
    file = files[0]
    log.msg(file)
    self.usedFiles.append(file)
    file = os.path.expanduser(file)
    file += '.pub'
    if (not os.path.exists(file)):
        return self.getPublicKey()
    try:
        return keys.Key.fromFile(file)
    except keys.BadKeyError:
        return self.getPublicKey()
