# Path: pycoind/util/pyaes/util.py
# def append_PKCS7_padding(data):
#     pad = 16 - (len(data) % 16)
#     return data + pad * chr(pad)
# 
# def strip_PKCS7_padding(data):
#     if len(data) % 16 != 0:
#         raise ValueError("invalid length")
# 
#     pad = ord(data[-1])
# 
#     if pad > 16:
#         raise ValueError("invalid padding byte")
# 
#     return data[:-pad]


from .aes import AESBlockModeOfOperation, AESSegmentModeOfOperation, AESStreamModeOfOperation
from .util import append_PKCS7_padding, strip_PKCS7_padding

        # Finalize; process the spare bytes we were keeping
        if not data:
            result = self._final(self._buffer)
            self._buffer = None
            return result

        self._buffer += data

        # We keep 16 bytes around so we can determine padding
        result = ''
        while len(self._buffer) > 16:
            can_consume = self._mode._can_consume(len(self._buffer) - 16)
            if can_consume == 0: break
            result += self._feed(self._buffer[:can_consume])
            self._buffer = self._buffer[can_consume:]

        return result


class Encrypter(BlockFeeder):
    'Accepts bytes of plaintext and returns encrypted ciphertext.'

    def __init__(self, mode):
        BlockFeeder.__init__(self, mode, mode.encrypt, mode._final_encrypt)


class Decrypter(BlockFeeder):
    'Accepts bytes of ciphertext and returns decrypted plaintext.'


# Path: pycoind/util/pyaes/util.py
# def append_PKCS7_padding(data):
#     pad = 16 - (len(data) % 16)
#     return data + pad * chr(pad)
# 
# def strip_PKCS7_padding(data):
#     if len(data) % 16 != 0:
#         raise ValueError("invalid length")
# 
#     pad = ord(data[-1])
# 
#     if pad > 16:
#         raise ValueError("invalid padding byte")
# 
#     return data[:-pad]


# Path: pycoind/util/pyaes/blockfeeder.py
from .aes import AESBlockModeOfOperation, AESSegmentModeOfOperation, AESStreamModeOfOperation
from .util import append_PKCS7_padding, strip_PKCS7_padding


        # Finalize; process the spare bytes we were keeping
        if not data:
            result = self._final(self._buffer)
            self._buffer = None
            return result

        self._buffer += data

        # We keep 16 bytes around so we can determine padding
        result = ''
        while len(self._buffer) > 16:
            can_consume = self._mode._can_consume(len(self._buffer) - 16)
            if can_consume == 0: break
            result += self._feed(self._buffer[:can_consume])
            self._buffer = self._buffer[can_consume:]

        return result


class Encrypter(BlockFeeder):
    'Accepts bytes of plaintext and returns encrypted ciphertext.'

    def __init__(self, mode):
        BlockFeeder.__init__(self, mode, mode.encrypt, mode._final_encrypt)


class Decrypter(BlockFeeder):
    'Accepts bytes of ciphertext and returns decrypted plaintext.'


    def __init__(self, mode):