Python cryptography.exceptions.AlreadyFinalized() Examples

The following are 30 code examples of cryptography.exceptions.AlreadyFinalized(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module cryptography.exceptions , or try the search function .
Example #1
Source File: padding.py    From oss-ftp with MIT License 6 votes vote down vote up
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 
Example #2
Source File: padding.py    From oss-ftp with MIT License 6 votes vote down vote up
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 
Example #3
Source File: padding.py    From quickstart-redhat-openshift with Apache License 2.0 5 votes vote down vote up
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) 
Example #4
Source File: padding.py    From learn_python3_spider with MIT License 5 votes vote down vote up
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) 
Example #5
Source File: padding.py    From learn_python3_spider with MIT License 5 votes vote down vote up
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 
Example #6
Source File: padding.py    From learn_python3_spider with MIT License 5 votes vote down vote up
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] 
Example #7
Source File: padding.py    From quickstart-git2s3 with Apache License 2.0 5 votes vote down vote up
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 
Example #8
Source File: padding.py    From quickstart-git2s3 with Apache License 2.0 5 votes vote down vote up
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) 
Example #9
Source File: padding.py    From quickstart-git2s3 with Apache License 2.0 5 votes vote down vote up
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 
Example #10
Source File: padding.py    From quickstart-git2s3 with Apache License 2.0 5 votes vote down vote up
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] 
Example #11
Source File: padding.py    From quickstart-redhat-openshift with Apache License 2.0 5 votes vote down vote up
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 
Example #12
Source File: padding.py    From teleport with Apache License 2.0 5 votes vote down vote up
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 
Example #13
Source File: padding.py    From quickstart-redhat-openshift with Apache License 2.0 5 votes vote down vote up
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 
Example #14
Source File: padding.py    From quickstart-redhat-openshift with Apache License 2.0 5 votes vote down vote up
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] 
Example #15
Source File: padding.py    From Carnets with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
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 
Example #16
Source File: padding.py    From Carnets with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
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) 
Example #17
Source File: padding.py    From Carnets with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
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 
Example #18
Source File: padding.py    From Carnets with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
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] 
Example #19
Source File: padding.py    From learn_python3_spider with MIT License 5 votes vote down vote up
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 
Example #20
Source File: padding.py    From oss-ftp with MIT License 5 votes vote down vote up
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 = len(self._buffer) // (self.block_size // 8)

        result = self._buffer[:finished_blocks * (self.block_size // 8)]
        self._buffer = self._buffer[finished_blocks * (self.block_size // 8):]

        return result 
Example #21
Source File: padding.py    From teleport with Apache License 2.0 5 votes vote down vote up
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) 
Example #22
Source File: padding.py    From teleport with Apache License 2.0 5 votes vote down vote up
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 
Example #23
Source File: padding.py    From teleport with Apache License 2.0 5 votes vote down vote up
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] 
Example #24
Source File: padding.py    From teleport with Apache License 2.0 5 votes vote down vote up
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 
Example #25
Source File: padding.py    From teleport with Apache License 2.0 5 votes vote down vote up
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 
Example #26
Source File: padding.py    From teleport with Apache License 2.0 5 votes vote down vote up
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] 
Example #27
Source File: padding.py    From teleport with Apache License 2.0 5 votes vote down vote up
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 
Example #28
Source File: padding.py    From teleport with Apache License 2.0 5 votes vote down vote up
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) 
Example #29
Source File: padding.py    From teleport with Apache License 2.0 5 votes vote down vote up
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 
Example #30
Source File: padding.py    From Safejumper-for-Desktop with GNU General Public License v2.0 5 votes vote down vote up
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]