config_file.py 文件源码

python
阅读 28 收藏 0 点赞 0 评论 0

项目:cmdb 作者: jonmsawyer 项目源码 文件源码
def decrypt(self, save_content=False):
        if self.encryption_key is None:
            raise LocalConfigFileError('Cannot decrypt content, missing encryption key.')
        if self.config.get('content') is None:
            raise LocalConfigFileError('Cannot decrypt content, content is empty.')
        if self.is_encryptable == False:
            raise LocalConfigFileError('Cannot decrypt, improper configuration.')
        if self.config.get('is_encrypted') == False:
            return self.config.get('content')

        f = Fernet(self.encryption_key)
        if self.config.get('is_binary') == True:
            decr_content = f.decrypt(self.config.get('content'))
        elif self.config.get('is_binary') == False:
            decr_content = f.decrypt(self.config.get('content').encode('utf-8')).decode('utf-8')
        else:
            raise LocalConfigFileError('Could not tell if file is binary or text. Aborting.')
        if save_content == True:
            try:
                self.config['content'] = decr_content
                self.config['content_length'] = len(decr_content)
                self.config['is_encrypted'] = False
            except:
                raise
        return decr_content
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号