def unpad(data):
    """remove PKCS#7 padding by removing as many digits as
    the padding indicates are padding.

    :data: is a bytestring.
    Returns the unpadded bytestring.
    """
    try:
        return data[:-ord(data[-1])]
    except TypeError:
        return data[:-data[-1]]
