```python
def line_tag(body: str) -> str:
    if not isinstance(body, str):
        raise ValueError("line_tag expects a string")
    return format(sum(ord(ch) for ch in body) % 256, "02x")


def check_line(line: str) -> str:
    if not isinstance(line, str):
        raise ValueError("check_line expects a string")
    if len(line) < 3:
        raise ValueError("line must be at least three characters long")
    if line[-3] != '~':
        raise ValueError("line must have a tilde as the third-from-last character")
    expected_tag = line_tag(line[:-3])
    if line[-2:] != expected_tag:
        raise ValueError("line tag does not match its body")
    return line[:-3]
```