def pad_string(text: str, length: int) -> bytes:
    """Pad the string to the specified length and convert."""
    if len(text) > length:
        raise ValueError('{!r} is longer than {}!'.format(text, length))
    return text.encode('ascii') + b'\0' * (length - len(text))