```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")
    
    prefix = 0
    for octet in octets:
        if not octet.isdigit():
            raise ValueError("all fields must hold decimal digits")
        
        value = int(octet)
        if value > 255 or (value and value < 10 and octet[0] == '0'):
            raise ValueError("octet values must be between 0 and 255, with no leading zero except for 0 itself")
        
        if prefix != 0 and value != 0:
            raise ValueError("mask ones must not be broken by a zero")
        
        prefix += bin(value).count('1')
    
    return prefix
```