(bytestring)
return bytestring.rstrip(PAD_CHAR)
Unpad will remove padding from the right of a string that has been
    padded by ``simple_pad()`` or by ``crypto_pad()``.

    ``crypto_pad()`` uses `ISO 7816-4 <iso7816>`_, which will result in
    the string ending in a byte with a decimal value of either 0 or 128
    (hex 0x00 or 0x80).

     ``simple_pad()`` pads with PAD_CHAR (an ASCII space character) if
     the original length is not a multiple of AES_BLOCK_SIZE, otherwise
     it does not pad.

     If ``bytestring`` ends in 0x00 or 0x80, it could have been padded
     with ``crypto_pad()``, or it could padded with ``simple_pad()``
     and whose last character is multi-byte non-ASCII UTF-8 character
     whose last byte is 0x00 or 0x80 (e.g. b'0xC3\0x80', "À" (capital
     A-grave)). Because the second possibility is far less likely than
     the first, ``unpad()`` uses ``crypto_unpad()`` in this case.

    .. _iso7816: https://en.wikipedia.org/wiki/Padding_(cryptography)#ISO/IEC_7816-4
Unpad will remove padding from the right of a string that has been
    padded by ``simple_pad()`` or by ``crypto_pad()``.
Unpad will remove padding from the right of a string that has been padded by simple_pad () or by crypto_pad () .
def unpad(bytestring):
    """
    Unpad will remove padding from the right of a string that has been
    padded by ``simple_pad()`` or by ``crypto_pad()``.

    ``crypto_pad()`` uses `ISO 7816-4 <iso7816>`_, which will result in
    the string ending in a byte with a decimal value of either 0 or 128
    (hex 0x00 or 0x80).

     ``simple_pad()`` pads with PAD_CHAR (an ASCII space character) if
     the original length is not a multiple of AES_BLOCK_SIZE, otherwise
     it does not pad.

     If ``bytestring`` ends in 0x00 or 0x80, it could have been padded
     with ``crypto_pad()``, or it could padded with ``simple_pad()``
     and whose last character is multi-byte non-ASCII UTF-8 character
     whose last byte is 0x00 or 0x80 (e.g. b'0xC3\0x80', "À" (capital
     A-grave)). Because the second possibility is far less likely than
     the first, ``unpad()`` uses ``crypto_unpad()`` in this case.

    .. _iso7816: https://en.wikipedia.org/wiki/Padding_(cryptography)#ISO/IEC_7816-4
    """
    if bytestring == b'':
        return bytestring
    if bord(bytestring[-1]) in (0, 128):
        return crypto_unpad(bytestring, AES_BLOCK_SIZE, style='iso7816')
    return bytestring.rstrip(PAD_CHAR)
def unpad ( bytestring ) : if bytestring == b'' : return bytestring if bord ( bytestring [ - 1 ] ) in ( 0 , 128 ) : return crypto_unpad ( bytestring , AES_BLOCK_SIZE , style = 'iso7816' ) return bytestring . rstrip ( PAD_CHAR )