```
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")
    
    # Split the mask into four parts
    parts = mask.split('.')
    if len(parts) != 4:
        raise ValueError("mask must have exactly four dot-separated fields")
    
    total_ones = 0
    for part in parts:
        if not part.isdigit():
            raise ValueError(f"all fields must hold decimal digits, got {part}")
        
        num = int(part)
        if num < 0 or num > 255:
            raise ValueError("octets must be between 0 and 255")
        
        # Count leading ones in the current octet
        count_ones = 8 - bin(num).count('0')
        total_ones += count_ones
        
        # Check that the one bits are unbroken
        if num != 255 - (1 << (8 - count_ones)):
            raise ValueError("mask's ones are broken")
    
    return total_ones
```