def __init__(self, keys_path=settings.KEY_PAIR_DIR): if os.path.exists(keys_path) and os.path.getsize(keys_path) > 0: self.bio = openfile(keys_path, 'rb') self.rsa = load_key_bio(self.bio, callback=do_nothing) else: self.bio = openfile(keys_path, 'ab+') self.rsa = self.generate() self.rsa.save_key_bio(self.bio, callback=do_nothing) self.rsa.save_pub_key_bio(self.bio) self.bio.reset()
def load(self): """ Load keys from file """ load_key_bio(self.bio, callback=do_nothing) self.bio.reset()