本文整理匯總了Python中cryptography.exceptions.AlreadyFinalized方法的典型用法代碼示例。如果您正苦於以下問題:Python exceptions.AlreadyFinalized方法的具體用法?Python exceptions.AlreadyFinalized怎麽用?Python exceptions.AlreadyFinalized使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類cryptography.exceptions
的用法示例。
在下文中一共展示了exceptions.AlreadyFinalized方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: update
# 需要導入模塊: from cryptography import exceptions [as 別名]
# 或者: from cryptography.exceptions import AlreadyFinalized [as 別名]
def update(self, data):
if self._buffer is None:
raise AlreadyFinalized("Context was already finalized.")
if not isinstance(data, bytes):
raise TypeError("data must be bytes.")
self._buffer += data
finished_blocks = max(
len(self._buffer) // (self.block_size // 8) - 1,
0
)
result = self._buffer[:finished_blocks * (self.block_size // 8)]
self._buffer = self._buffer[finished_blocks * (self.block_size // 8):]
return result
示例2: finalize
# 需要導入模塊: from cryptography import exceptions [as 別名]
# 或者: from cryptography.exceptions import AlreadyFinalized [as 別名]
def finalize(self):
if self._buffer is None:
raise AlreadyFinalized("Context was already finalized.")
if len(self._buffer) != self.block_size // 8:
raise ValueError("Invalid padding bytes.")
valid = lib.Cryptography_check_pkcs7_padding(
self._buffer, self.block_size // 8
)
if not valid:
raise ValueError("Invalid padding bytes.")
pad_size = six.indexbytes(self._buffer, -1)
res = self._buffer[:-pad_size]
self._buffer = None
return res
示例3: _byte_unpadding_update
# 需要導入模塊: from cryptography import exceptions [as 別名]
# 或者: from cryptography.exceptions import AlreadyFinalized [as 別名]
def _byte_unpadding_update(buffer_, data, block_size):
if buffer_ is None:
raise AlreadyFinalized("Context was already finalized.")
if not isinstance(data, bytes):
raise TypeError("data must be bytes.")
buffer_ += data
finished_blocks = max(len(buffer_) // (block_size // 8) - 1, 0)
result = buffer_[:finished_blocks * (block_size // 8)]
buffer_ = buffer_[finished_blocks * (block_size // 8):]
return buffer_, result
示例4: _byte_padding_update
# 需要導入模塊: from cryptography import exceptions [as 別名]
# 或者: from cryptography.exceptions import AlreadyFinalized [as 別名]
def _byte_padding_update(buffer_, data, block_size):
if buffer_ is None:
raise AlreadyFinalized("Context was already finalized.")
if not isinstance(data, bytes):
raise TypeError("data must be bytes.")
buffer_ += data
finished_blocks = len(buffer_) // (block_size // 8)
result = buffer_[:finished_blocks * (block_size // 8)]
buffer_ = buffer_[finished_blocks * (block_size // 8):]
return buffer_, result
示例5: _byte_padding_pad
# 需要導入模塊: from cryptography import exceptions [as 別名]
# 或者: from cryptography.exceptions import AlreadyFinalized [as 別名]
def _byte_padding_pad(buffer_, block_size, paddingfn):
if buffer_ is None:
raise AlreadyFinalized("Context was already finalized.")
pad_size = block_size // 8 - len(buffer_)
return buffer_ + paddingfn(pad_size)
示例6: _byte_unpadding_check
# 需要導入模塊: from cryptography import exceptions [as 別名]
# 或者: from cryptography.exceptions import AlreadyFinalized [as 別名]
def _byte_unpadding_check(buffer_, block_size, checkfn):
if buffer_ is None:
raise AlreadyFinalized("Context was already finalized.")
if len(buffer_) != block_size // 8:
raise ValueError("Invalid padding bytes.")
valid = checkfn(buffer_, block_size // 8)
if not valid:
raise ValueError("Invalid padding bytes.")
pad_size = six.indexbytes(buffer_, -1)
return buffer_[:-pad_size]
示例7: _byte_padding_update
# 需要導入模塊: from cryptography import exceptions [as 別名]
# 或者: from cryptography.exceptions import AlreadyFinalized [as 別名]
def _byte_padding_update(buffer_, data, block_size):
if buffer_ is None:
raise AlreadyFinalized("Context was already finalized.")
utils._check_bytes("data", data)
buffer_ += data
finished_blocks = len(buffer_) // (block_size // 8)
result = buffer_[:finished_blocks * (block_size // 8)]
buffer_ = buffer_[finished_blocks * (block_size // 8):]
return buffer_, result
示例8: _byte_unpadding_update
# 需要導入模塊: from cryptography import exceptions [as 別名]
# 或者: from cryptography.exceptions import AlreadyFinalized [as 別名]
def _byte_unpadding_update(buffer_, data, block_size):
if buffer_ is None:
raise AlreadyFinalized("Context was already finalized.")
utils._check_bytes("data", data)
buffer_ += data
finished_blocks = max(len(buffer_) // (block_size // 8) - 1, 0)
result = buffer_[:finished_blocks * (block_size // 8)]
buffer_ = buffer_[finished_blocks * (block_size // 8):]
return buffer_, result