```python
def mask_from_prefix(prefix: int) -> str:
    if isinstance(prefix, bool) or not isinstance(prefix, int) or not 0 <= prefix <= 32:
        raise ValueError("prefix must be an integer from 0 to 32")
    octets = []
    for slot in range(4):
        ones = min(8, max(0, prefix - slot * 8))
        octets.append(str(256 - 2 ** (8 - ones)))
    return ".".join(octets)


def prefix_from_mask(mask: str) -> int:
    if not isinstance(mask, str):
        raise ValueError("mask must be a string")
    
    octets = mask.split(".")
    if len(octets) != 4:
        raise ValueError("mask must have exactly four dot-separated fields")
    
    leading_ones_count = 0
    for i, octet in enumerate(octets):
        if not octet.isdigit():
            raise ValueError("each field must hold decimal digits")
        
        octet_value = int(octet)
        if octet_value > 255:
            raise ValueError("each octet must be between 0 and 255")
        
        if i == 0:
            leading_ones_count = 8 - (octet_value ^ 255).bit_length()
        elif leading_ones_count == 0:
            continue
        elif (leading_ones_count + (octet_value ^ 255).bit_length()) % 8 != 0:
            raise ValueError("mask's ones are broken by a zero")
        else:
            leading_ones_count += 8 - (octet_value ^ 255).bit_length()
    
    return leading_ones_count
```