engine.py 文件源码

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

项目:deb-python-kmip 作者: openstack 项目源码 文件源码
def _handle_symmetric_padding(self,
                                  algorithm,
                                  plain_text,
                                  padding_method,
                                  undo_padding=False):
        # KMIP 1.3 test TC-STREAM-ENC-2-13.xml demonstrates a case
        # where an encrypt call for 3DES-ECB does not use padding if
        # the plaintext fits the blocksize of the algorithm. This does
        # not appear to be documented explicitly in the KMIP spec. It
        # also makes failures during unpadding after decryption
        # impossible to differentiate from cipher text/key mismatches.
        # For now, ALWAYS apply padding regardless of plain text length.
        if padding_method in self._symmetric_padding_methods.keys():
            padding_method = self._symmetric_padding_methods.get(
                padding_method
            )
            if undo_padding:
                padder = padding_method(algorithm.block_size).unpadder()
            else:
                padder = padding_method(algorithm.block_size).padder()
            plain_text = padder.update(plain_text)
            plain_text += padder.finalize()
        else:
            if padding_method is None:
                raise exceptions.InvalidField(
                    "Padding method is required."
                )
            else:
                raise exceptions.InvalidField(
                    "Padding method '{0}' is not supported.".format(
                        padding_method
                    )
                )
        return plain_text
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号