```
def mask_from_prefix(prefix):
    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('.')
    
    # Validate each part to ensure it's a non-negative integer and less than 256
    for i, part in enumerate(parts):
        if not part.isdigit() or int(part) < 0 or int(part) > 255:
            raise ValueError("mask must be four dot-separated decimal numbers between 0-255")
    
    # Check if all parts are valid and count the leading ones
    leading_ones_count = 0
    for part in parts:
        value = int(part)
        while value > 0:
            value &= (value - 1)
            leading_ones_count += 1
    
    return leading_ones_count
```