'Whether the padding bits are all zero'

@staticmethod
def has_valid_padding(value, bits=7):

    assert (bits <= 8)
    mask = (((1 << (8 - bits)) - 1) << bits)
    if isinstance(value, integer_types):
        while value:
            if (value & mask):
                return False
            value >>= 8
    elif isinstance(value, bytes):
        for byte in bytearray(value):
            if (byte & mask):
                return False
    else:
        raise TypeError
    return True
