def _msg_type_component(tag_value, values): c = constraint.ConstraintsUnion(*(constraint.SingleValueConstraint(int(v)) for v in values)) return _sequence_component('msg-type', tag_value, univ.Integer(), subtypeSpec=c)
def setUp(self): BaseTestCase.setUp(self) self.c1 = constraint.SingleValueConstraint(5) self.c2 = constraint.ConstraintsUnion( self.c1, constraint.ValueRangeConstraint(1, 3))
class SemanticsInformation(univ.Sequence): componentType = namedtype.NamedTypes( namedtype.OptionalNamedType('semanticsIndentifier', univ.ObjectIdentifier()), namedtype.OptionalNamedType('nameRegistrationAuthorities', NameRegistrationAuthorities())) subtypeSpec = constraint.ConstraintsUnion( constraint.WithComponentsConstraint( ('semanticsIndentifier', constraint.ComponentPresentConstraint())), constraint.WithComponentsConstraint( ('nameRegistrationAuthorities', constraint.ComponentPresentConstraint())))
def testSubtypeSpec(self): s = self.s1.clone(subtypeSpec=constraint.ConstraintsUnion( constraint.SingleValueConstraint(str2octs('abc')))) try: s.setComponentByPosition(0, univ.OctetString('abc')) except: assert 0, 'constraint fails' try: s.setComponentByPosition(1, univ.OctetString('Abc')) except: pass else: assert 0, 'constraint fails'
def testSizeSpec(self): s = self.s1.clone(sizeSpec=constraint.ConstraintsUnion( constraint.ValueSizeConstraint(1, 1))) s.setComponentByPosition(0, univ.OctetString('abc')) try: s.verifySizeSpec() except PyAsn1Error: assert 0, 'size spec fails' s.setComponentByPosition(1, univ.OctetString('abc')) try: s.verifySizeSpec() except PyAsn1Error: pass else: assert 0, 'size spec fails'
def testComponentConstraintsMatching(self): s = self.s1.clone() o = univ.OctetString().subtype(subtypeSpec=constraint.ConstraintsUnion( constraint.SingleValueConstraint(str2octs('cba')))) s.strictConstraints = True # This requires types equality try: s.setComponentByPosition(0, o.clone('cba')) except PyAsn1Error: pass else: assert 0, 'inner supertype constraint allowed' s.strictConstraints = False # This requires subtype relationships try: s.setComponentByPosition(0, o.clone('cba')) except PyAsn1Error: assert 0, 'inner supertype constraint disallowed' else: pass
def testSubtypeSpec(self): s = self.s1.clone(subtypeSpec=constraint.ConstraintsUnion( constraint.SingleValueConstraint(str2octs('abc')))) try: s.setComponentByPosition(0, univ.OctetString('abc')) except PyAsn1Error: assert 0, 'constraint fails' try: s.setComponentByPosition(1, univ.OctetString('Abc')) except PyAsn1Error: try: s.setComponentByPosition(1, univ.OctetString('Abc'), verifyConstraints=False) except PyAsn1Error: assert 0, 'constraint failes with verifyConstraints=True' else: assert 0, 'constraint fails'
def testComponentConstraintsMatching(self): s = self.s1.clone() o = univ.OctetString().subtype(subtypeSpec=constraint.ConstraintsUnion( constraint.SingleValueConstraint(str2octs('cba')))) s.strictConstraints = True try: s.setComponentByName('name', o.clone('cba')) except PyAsn1Error: pass else: assert 0, 'inner supertype constraint allowed' s.strictConstraints = False try: s.setComponentByName('name', o.clone('cba')) except PyAsn1Error: assert 0, 'inner supertype constraint disallowed' else: pass
class EnhancedJWTClaimConstraints(univ.Sequence): componentType = namedtype.NamedTypes( namedtype.OptionalNamedType( 'mustInclude', JWTClaimNames().subtype(explicitTag=tag.Tag( tag.tagClassContext, tag.tagFormatSimple, 0))), namedtype.OptionalNamedType( 'permittedValues', JWTClaimValuesList().subtype(explicitTag=tag.Tag( tag.tagClassContext, tag.tagFormatSimple, 1))), namedtype.OptionalNamedType( 'mustExclude', JWTClaimNames().subtype(explicitTag=tag.Tag( tag.tagClassContext, tag.tagFormatSimple, 2)))) subtypeSpec = constraint.ConstraintsUnion( constraint.WithComponentsConstraint( ('mustInclude', constraint.ComponentPresentConstraint())), constraint.WithComponentsConstraint( ('permittedValues', constraint.ComponentPresentConstraint())), constraint.WithComponentsConstraint( ('mustExclude', constraint.ComponentPresentConstraint())))
def setUp(self): self.c1 = constraint.ConstraintsUnion( constraint.SingleValueConstraint(5), constraint.ValueRangeConstraint(1, 3))
def testCmp4(self): c = constraint.ConstraintsUnion( constraint.ConstraintsIntersection( constraint.SingleValueConstraint(5))) assert self.c1 not in c, '__cmp__() fails'
def testCmp3(self): c = constraint.ConstraintsUnion( constraint.ConstraintsIntersection( constraint.SingleValueConstraint(4), constraint.ValueRangeConstraint(2, 4))) assert self.c1 in c, '__cmp__() fails'
class TimeOfDay(univ.OctetString): subtypeSpec = constraint.ConstraintsUnion( constraint.ValueSizeConstraint(4, 4), constraint.ValueSizeConstraint(6, 6))
class LogotypeData(univ.Sequence): pass LogotypeData.componentType = namedtype.NamedTypes( namedtype.OptionalNamedType( 'image', univ.SequenceOf(componentType=LogotypeImage())), namedtype.OptionalNamedType( 'audio', univ.SequenceOf(componentType=LogotypeAudio()).subtype( implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 1)))) LogotypeData.subtypeSpec = constraint.ConstraintsUnion( constraint.WithComponentsConstraint( ('image', constraint.ComponentPresentConstraint())), constraint.WithComponentsConstraint( ('audio', constraint.ComponentPresentConstraint()))) class LogotypeReference(univ.Sequence): pass LogotypeReference.componentType = namedtype.NamedTypes( namedtype.NamedType( 'refStructHash', univ.SequenceOf(componentType=HashAlgAndValue()).subtype( sizeSpec=constraint.ValueSizeConstraint(1, MAX))), namedtype.NamedType( 'refStructURI',
snmpTargetAddrExtEntry = MibTableRow((1, 3, 6, 1, 6, 3, 18, 1, 2, 1)) if mibBuilder.loadTexts: snmpTargetAddrExtEntry.setDescription( "Information about a particular mask and mms value.") snmpTargetAddrTMask = MibTableColumn( (1, 3, 6, 1, 6, 3, 18, 1, 2, 1, 1), OctetString().subtype(subtypeSpec=constraint.ValueSizeConstraint( 0, 255)).clone('')).setMaxAccess("readcreate") if mibBuilder.loadTexts: snmpTargetAddrTMask.setDescription( "The mask value associated with an entry in the\nsnmpTargetAddrTable. The value of this object must\nhave the same length as the corresponding instance of\nsnmpTargetAddrTAddress, or must have length 0. An\nattempt to set it to any other value will result in\nan inconsistentValue error.\n\nThe value of this object allows an entry in the\nsnmpTargetAddrTable to specify multiple addresses.\nThe mask value is used to select which bits of\na transport address must match bits of the corresponding\ninstance of snmpTargetAddrTAddress, in order for the\ntransport address to match a particular entry in the\nsnmpTargetAddrTable. Bits which are 1 in the mask\nvalue indicate bits in the transport address which\nmust match bits in the snmpTargetAddrTAddress value.\n\n\nBits which are 0 in the mask indicate bits in the\ntransport address which need not match. If the\nlength of the mask is 0, the mask should be treated\nas if all its bits were 1 and its length were equal\nto the length of the corresponding value of\nsnmpTargetAddrTable.\n\nThis object may not be modified while the value of the\ncorresponding instance of snmpTargetAddrRowStatus is\nactive(1). An attempt to set this object in this case\nwill result in an inconsistentValue error." ) snmpTargetAddrMMS = MibTableColumn( (1, 3, 6, 1, 6, 3, 18, 1, 2, 1, 2), Integer32().subtype(subtypeSpec=constraint.ConstraintsUnion( constraint.ValueRangeConstraint(0, 0), constraint.ValueRangeConstraint(484, 2147483647), )).clone(484)).setMaxAccess("readcreate") if mibBuilder.loadTexts: snmpTargetAddrMMS.setDescription( "The maximum message size value associated with an entry\nin the snmpTargetAddrTable." ) snmpTrapAddress = MibScalar((1, 3, 6, 1, 6, 3, 18, 1, 3), IpAddress()).setMaxAccess("notifyonly") if mibBuilder.loadTexts: snmpTrapAddress.setDescription( "The value of the agent-addr field of a Trap PDU which\nis forwarded by a proxy forwarder application using\nan SNMP version other than SNMPv1. The value of this\nobject SHOULD contain the value of the agent-addr field\nfrom the original Trap PDU as generated by an SNMPv1\nagent." ) snmpTrapCommunity = MibScalar((1, 3, 6, 1, 6, 3, 18, 1, 4), OctetString()).setMaxAccess("notifyonly") if mibBuilder.loadTexts: snmpTrapCommunity.setDescription(
pass CMSAlgorithmProtection.componentType = namedtype.NamedTypes( namedtype.NamedType('digestAlgorithm', DigestAlgorithmIdentifier()), namedtype.OptionalNamedType('signatureAlgorithm', SignatureAlgorithmIdentifier().subtype( implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 1))), namedtype.OptionalNamedType('macAlgorithm', MessageAuthenticationCodeAlgorithm().subtype( implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 2))) ) CMSAlgorithmProtection.subtypeSpec = constraint.ConstraintsUnion( constraint.WithComponentsConstraint( ('signatureAlgorithm', constraint.ComponentPresentConstraint()), ('macAlgorithm', constraint.ComponentAbsentConstraint())), constraint.WithComponentsConstraint( ('signatureAlgorithm', constraint.ComponentAbsentConstraint()), ('macAlgorithm', constraint.ComponentPresentConstraint())) ) aa_cmsAlgorithmProtection = rfc5652.Attribute() aa_cmsAlgorithmProtection['attrType'] = id_aa_cmsAlgorithmProtect aa_cmsAlgorithmProtection['attrValues'][0] = CMSAlgorithmProtection() # Map of Attribute Type OIDs to Attributes are # added to the ones that are in rfc5652.py _cmsAttributesMapUpdate = { id_aa_cmsAlgorithmProtect: CMSAlgorithmProtection(),
class JWTClaimConstraints(univ.Sequence): pass JWTClaimConstraints.componentType = namedtype.NamedTypes( namedtype.OptionalNamedType('mustInclude', JWTClaimNames().subtype(explicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 0))), namedtype.OptionalNamedType('permittedValues', JWTClaimPermittedValuesList().subtype(explicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 1))) ) JWTClaimConstraints.subtypeSpec = constraint.ConstraintsUnion( constraint.WithComponentsConstraint( ('mustInclude', constraint.ComponentPresentConstraint())), constraint.WithComponentsConstraint( ('permittedValues', constraint.ComponentPresentConstraint())) ) id_pe_JWTClaimConstraints = _OID(1, 3, 6, 1, 5, 5, 7, 1, 27) class ServiceProviderCode(char.IA5String): pass class TelephoneNumber(char.IA5String): pass TelephoneNumber.subtypeSpec = constraint.ConstraintsIntersection(
GostR3410_94_ParamSetParameters.componentType = namedtype.NamedTypes( namedtype.NamedType('t', GostR3410_94_ParamSetParameters_t()), namedtype.NamedType('p', univ.Integer()), namedtype.NamedType('q', univ.Integer()), namedtype.NamedType('a', univ.Integer()), namedtype.OptionalNamedType('validationAlgorithm', AlgorithmIdentifier())) class GostR3410_94_PublicKey(univ.OctetString): pass GostR3410_94_PublicKey.subtypeSpec = constraint.ConstraintsUnion( constraint.ValueSizeConstraint(64, 64), constraint.ValueSizeConstraint(128, 128)) class GostR3410_94_PublicKeyParameters(univ.Sequence): pass GostR3410_94_PublicKeyParameters.componentType = namedtype.NamedTypes( namedtype.NamedType( 'publicKeyParamSet', univ.ObjectIdentifier(). subtype(subtypeSpec=constraint.SingleValueConstraint( id_GostR3410_94_TestParamSet, id_GostR3410_94_CryptoPro_A_ParamSet, id_GostR3410_94_CryptoPro_B_ParamSet, id_GostR3410_94_CryptoPro_C_ParamSet,
class ExtUTCTime(OctetString): subtypeSpec = OctetString.subtypeSpec + constraint.ConstraintsUnion( constraint.ValueSizeConstraint(11, 11), constraint.ValueSizeConstraint(13, 13))