Contained subtype constraint

class pyasn1.type.constraint.ContainedSubtypeConstraint(*values: Any)

Create a ContainedSubtypeConstraint object.

The ContainedSubtypeConstraint satisfies any value that either equals one of the permitted values or satisfies one of the included constraints.

The ContainedSubtypeConstraint object can be applied to any ASN.1 type.

Parameters:

*values – Full set of values and constraint objects permitted by this constraint object.

Examples

class DivisorOfEighteen(Integer):
    '''
    ASN.1 specification:

    Divisors-of-18 ::= INTEGER (INCLUDES Divisors-of-6 | 9 | 18)
    '''
    subtypeSpec = ContainedSubtypeConstraint(
        SingleValueConstraint(1, 2, 3, 6), 9, 18
    )

# this will succeed
divisor_of_eighteen = DivisorOfEighteen(9)

# this will raise ValueConstraintError
divisor_of_eighteen = DivisorOfEighteen(10)