Serialize header extensions according to RFC 5285.

def pack_header_extensions(extensions: List[Tuple[int, bytes]]) -> Tuple[int, bytes]:
    """
    Serialize header extensions according to RFC 5285.
    """
    extension_profile = 0
    extension_value = b''

    if not extensions:
        return extension_profile, extension_value

    one_byte = True
    for x_id, x_value in extensions:
        x_length = len(x_value)
        assert x_id > 0 and x_id < 256
        assert x_length >= 0 and x_length < 256
        if x_id > 14 or x_length == 0 or x_length > 16:
            one_byte = False

    if one_byte:
        # One-Byte Header
        extension_profile = 0xBEDE
        extension_value = b''
        for x_id, x_value in extensions:
            x_length = len(x_value)
            extension_value += pack('!B', (x_id << 4) | (x_length - 1))
            extension_value += x_value
    else:
        # Two-Byte Header
        extension_profile = 0x1000
        extension_value = b''
        for x_id, x_value in extensions:
            x_length = len(x_value)
            extension_value += pack('!BB', x_id, x_length)
            extension_value += x_value

    extension_value += b'\x00' * padl(len(extension_value))
    return extension_profile, extension_value