```python
def mask_from_prefix(prefix: int) -> str:
    if not isinstance(prefix, int) or not 0 <= prefix <= 32:
        raise ValueError("Prefix must be an integer from 0 to 32")
    return ".".join([f"{0xFF << (32 - i - 8):03d}" for i in range(4)])

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")
    
    total_bits = 0
    for octet in octets:
        if not octet.isdigit():
            raise ValueError("All fields must contain only decimal digits")
        if octet[0] == '0' and len(octet) > 1:
            raise ValueError("Octets cannot have leading zeros except 0 itself")
        value = int(octet)
        if value > 255:
            raise ValueError("All octets must be between 0 and 255")
        
        if total_bits % 8 == 0 and value != 0xFF:
            raise ValueError("Mask cannot have broken runs of leading one bits")
        total_bits += (8 - value.bit_length())
    
    return total_bits
```