OLD | NEW |
(Empty) | |
| 1 # |
| 2 # SNMPv2c message syntax |
| 3 # |
| 4 # ASN.1 source from: |
| 5 # http://www.ietf.org/rfc/rfc1902.txt |
| 6 # |
| 7 from pyasn1.type import univ, namedtype, namedval, tag, constraint |
| 8 |
| 9 class Integer(univ.Integer): |
| 10 subtypeSpec = univ.Integer.subtypeSpec+constraint.ValueRangeConstraint( |
| 11 -2147483648, 2147483647 |
| 12 ) |
| 13 |
| 14 class Integer32(univ.Integer): |
| 15 subtypeSpec = univ.Integer.subtypeSpec+constraint.ValueRangeConstraint( |
| 16 -2147483648, 2147483647 |
| 17 ) |
| 18 |
| 19 class OctetString(univ.OctetString): |
| 20 subtypeSpec = univ.Integer.subtypeSpec+constraint.ValueSizeConstraint( |
| 21 0, 65535 |
| 22 ) |
| 23 |
| 24 class IpAddress(univ.OctetString): |
| 25 tagSet = univ.OctetString.tagSet.tagImplicitly( |
| 26 tag.Tag(tag.tagClassApplication, tag.tagFormatSimple, 0x00) |
| 27 ) |
| 28 subtypeSpec = univ.OctetString.subtypeSpec+constraint.ValueSizeConstraint( |
| 29 4, 4 |
| 30 ) |
| 31 |
| 32 class Counter32(univ.Integer): |
| 33 tagSet = univ.Integer.tagSet.tagImplicitly( |
| 34 tag.Tag(tag.tagClassApplication, tag.tagFormatSimple, 0x01) |
| 35 ) |
| 36 subtypeSpec = univ.Integer.subtypeSpec+constraint.ValueRangeConstraint( |
| 37 0, 4294967295 |
| 38 ) |
| 39 |
| 40 class Gauge32(univ.Integer): |
| 41 tagSet = univ.Integer.tagSet.tagImplicitly( |
| 42 tag.Tag(tag.tagClassApplication, tag.tagFormatSimple, 0x02) |
| 43 ) |
| 44 subtypeSpec = univ.Integer.subtypeSpec+constraint.ValueRangeConstraint( |
| 45 0, 4294967295 |
| 46 ) |
| 47 |
| 48 class Unsigned32(univ.Integer): |
| 49 tagSet = univ.Integer.tagSet.tagImplicitly( |
| 50 tag.Tag(tag.tagClassApplication, tag.tagFormatSimple, 0x02) |
| 51 ) |
| 52 subtypeSpec = univ.Integer.subtypeSpec+constraint.ValueRangeConstraint( |
| 53 0, 4294967295 |
| 54 ) |
| 55 |
| 56 class TimeTicks(univ.Integer): |
| 57 tagSet = univ.Integer.tagSet.tagImplicitly( |
| 58 tag.Tag(tag.tagClassApplication, tag.tagFormatSimple, 0x03) |
| 59 ) |
| 60 subtypeSpec = univ.Integer.subtypeSpec+constraint.ValueRangeConstraint( |
| 61 0, 4294967295 |
| 62 ) |
| 63 |
| 64 class Opaque(univ.OctetString): |
| 65 tagSet = univ.OctetString.tagSet.tagImplicitly( |
| 66 tag.Tag(tag.tagClassApplication, tag.tagFormatSimple, 0x04) |
| 67 ) |
| 68 |
| 69 class Counter64(univ.Integer): |
| 70 tagSet = univ.Integer.tagSet.tagImplicitly( |
| 71 tag.Tag(tag.tagClassApplication, tag.tagFormatSimple, 0x06) |
| 72 ) |
| 73 subtypeSpec = univ.Integer.subtypeSpec+constraint.ValueRangeConstraint( |
| 74 0, 18446744073709551615 |
| 75 ) |
| 76 |
| 77 class Bits(univ.OctetString): pass |
| 78 |
| 79 class ObjectName(univ.ObjectIdentifier): pass |
| 80 |
| 81 class SimpleSyntax(univ.Choice): |
| 82 componentType = namedtype.NamedTypes( |
| 83 namedtype.NamedType('integer-value', Integer()), |
| 84 namedtype.NamedType('string-value', OctetString()), |
| 85 namedtype.NamedType('objectID-value', univ.ObjectIdentifier()) |
| 86 ) |
| 87 |
| 88 class ApplicationSyntax(univ.Choice): |
| 89 componentType = namedtype.NamedTypes( |
| 90 namedtype.NamedType('ipAddress-value', IpAddress()), |
| 91 namedtype.NamedType('counter-value', Counter32()), |
| 92 namedtype.NamedType('timeticks-value', TimeTicks()), |
| 93 namedtype.NamedType('arbitrary-value', Opaque()), |
| 94 namedtype.NamedType('big-counter-value', Counter64()), |
| 95 # This conflicts with Counter32 |
| 96 # namedtype.NamedType('unsigned-integer-value', Unsigned32()), |
| 97 namedtype.NamedType('gauge32-value', Gauge32()) |
| 98 ) # BITS misplaced? |
| 99 |
| 100 class ObjectSyntax(univ.Choice): |
| 101 componentType = namedtype.NamedTypes( |
| 102 namedtype.NamedType('simple', SimpleSyntax()), |
| 103 namedtype.NamedType('application-wide', ApplicationSyntax()) |
| 104 ) |
| 105 |
OLD | NEW |