def unpad(buf, byte=None):
    """Truncate the padded bytes.
    None = autodetect
    """
    if not isinstance(buf, bytes):
        raise TypeError('Buffer must be in bytes')
    if byte is None:
        byte = buf[-1:]
    return buf.rstrip(byte)
