```python
def mask_from_prefix(prefix: int) -> str:
    """Render a network mask with the given number 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(str((1 << (32 - i)) - 1).zfill(3) 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")
    
    for octet in octets:
        if not octet.isdigit() or (octet[0] == '0' and len(octet) > 1):
            raise ValueError("Each field must be a decimal number without leading zeros other than '0'")
        
        if int(octet) > 255:
            raise ValueError("Each field must contain a number from 0 to 255")
    
    prefix = 0
    for octet in octets:
        if int(octet) != (1 << 8) - 1:
            break
        prefix += 8
    
    return prefix
```