```python
def mask_from_prefix(prefix: int) -> str:
    """Render a network mask with the given count of leading ones."""
    if not isinstance(prefix, int) or prefix < 0 or prefix > 32:
        raise ValueError("Prefix must be an integer from 0 to 32")
    
    return ".".join(f"{(1 << (8 - i)) - 1}" for i in range(4))

def prefix_from_mask(mask: str) -> int:
    """Convert a network mask back to its count of leading ones."""
    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 be decimal digits")
        
        octet_int = int(octet)
        if octet_int < 0 or octet_int > 255:
            raise ValueError("Octets must be between 0 and 255")
        
        if prefix != 0 and octet_int != 0:
            raise ValueError("Mask ones must not be broken by a zero")
        
        prefix += (8 - octet_int.bit_length())
    
    return prefix
```