kmip/core/enums.py
def is_bit_mask(enumeration, potential_mask):
    """
    A utility function that checks if the provided value is a composite bit
    mask of enumeration values in the specified enumeration class.

    Args:
        enumeration (class): One of the mask enumeration classes found in this
            file. These include:
                * Cryptographic Usage Mask
                * Protection Storage Mask
                * Storage Status Mask
        potential_mask (int): A potential bit mask composed of enumeration
            values belonging to the enumeration class.

    Returns:
        True: if the potential mask is a valid bit mask of the mask enumeration
        False: otherwise
    """
    if not isinstance(potential_mask, six.integer_types):
        return False

    mask_enumerations = (
        CryptographicUsageMask,
        ProtectionStorageMask,
        StorageStatusMask
    )
    if enumeration not in mask_enumerations:
        return False

    mask = 0
    for value in [e.value for e in enumeration]:
        if (value & potential_mask) == value:
            mask |= value

    if mask != potential_mask:
        return False

    return True
def is_bit_mask(enumeration, potential_mask):
    """
    A utility function that checks if the provided value is a composite bit
    mask of enumeration values in the specified enumeration class.

    Args:
        enumeration (class): One of the mask enumeration classes found in this
            file. These include:
                * Cryptographic Usage Mask
                * Protection Storage Mask
                * Storage Status Mask
        potential_mask (int): A potential bit mask composed of enumeration
            values belonging to the enumeration class.

    Returns:
        True: if the potential mask is a valid bit mask of the mask enumeration
        False: otherwise
    """
    if not isinstance(potential_mask, six.integer_types):
        return False

    mask_enumerations = (
        CryptographicUsageMask,
        ProtectionStorageMask,
        StorageStatusMask
    )
    if enumeration not in mask_enumerations:
        return False

    mask = 0
    for value in [e.value for e in enumeration]:
        if (value & potential_mask) == value:
            mask |= value

    if mask != potential_mask:
        return False

    return True
A utility function that checks if the provided value is a composite bit
    mask of enumeration values in the specified enumeration class.

    Args:
        enumeration (class): One of the mask enumeration classes found in this
            file. These include:
                * Cryptographic Usage Mask
                * Protection Storage Mask
                * Storage Status Mask
        potential_mask (int): A potential bit mask composed of enumeration
            values belonging to the enumeration class.

    Returns:
        True: if the potential mask is a valid bit mask of the mask enumeration
        False: otherwise