def null_padded(string, length):
    """
    Force a string to a given length by right-padding it with zero-bytes,
    clipping the initial string if neccessary.
    """
    return bytes(string[:length] + '\x00' * (length - len(string)), 'latin1')
