```python
def mask_from_prefix(prefix: int) -> str:
    if not isinstance(prefix, int):
        raise ValueError("Input must be an integer.")
    if prefix < 0 or prefix > 32:
        raise ValueError("Prefix must be an integer between 0 and 32.")
    
    # Create a list of 32 bits set to 1
    mask_bits = [1] * 32
    
    # Set the first 'prefix' bits to 1
    for i in range(prefix):
        mask_bits[i] = 0
    
    # Convert the bit list back to a dotted-quad string
    return '.'.join(str(sum(mask_bits[:j])) for j in (8, 16, 24, 32))

def prefix_from_mask(mask: str) -> int:
    if not isinstance(mask, str):
        raise ValueError("Input must be a string.")
    
    # Split the mask into four octets
    parts = mask.split('.')
    if len(parts) != 4:
        raise ValueError("Mask must contain exactly four dot-separated fields.")
    
    # Validate each octet
    for part in parts:
        if not part.isdigit():
            raise ValueError("Each octet must be a decimal number.")
        if (part.startswith('0') and part != '0') or int(part) > 255:
            raise ValueError("Octet must be between 0 and 255.")
    
    # Convert the dotted-quad string back to an integer
    return sum(int(bit) * (2 ** i) for i, bit in enumerate(reversed(parts)))
```