1# 2# This file is part of pyasn1-modules software. 3# 4# Copyright (c) 2005-2017, Ilya Etingof <etingof@gmail.com> 5# License: http://pyasn1.sf.net/license.html 6# 7# SNMPv2c message syntax 8# 9# ASN.1 source from: 10# http://www.ietf.org/rfc/rfc1902.txt 11# 12from pyasn1.type import constraint 13from pyasn1.type import namedtype 14from pyasn1.type import tag 15from pyasn1.type import univ 16 17 18class Integer(univ.Integer): 19 subtypeSpec = univ.Integer.subtypeSpec + constraint.ValueRangeConstraint( 20 -2147483648, 2147483647 21 ) 22 23 24class Integer32(univ.Integer): 25 subtypeSpec = univ.Integer.subtypeSpec + constraint.ValueRangeConstraint( 26 -2147483648, 2147483647 27 ) 28 29 30class OctetString(univ.OctetString): 31 subtypeSpec = univ.Integer.subtypeSpec + constraint.ValueSizeConstraint( 32 0, 65535 33 ) 34 35 36class IpAddress(univ.OctetString): 37 tagSet = univ.OctetString.tagSet.tagImplicitly( 38 tag.Tag(tag.tagClassApplication, tag.tagFormatSimple, 0x00) 39 ) 40 subtypeSpec = univ.OctetString.subtypeSpec + constraint.ValueSizeConstraint( 41 4, 4 42 ) 43 44 45class Counter32(univ.Integer): 46 tagSet = univ.Integer.tagSet.tagImplicitly( 47 tag.Tag(tag.tagClassApplication, tag.tagFormatSimple, 0x01) 48 ) 49 subtypeSpec = univ.Integer.subtypeSpec + constraint.ValueRangeConstraint( 50 0, 4294967295 51 ) 52 53 54class Gauge32(univ.Integer): 55 tagSet = univ.Integer.tagSet.tagImplicitly( 56 tag.Tag(tag.tagClassApplication, tag.tagFormatSimple, 0x02) 57 ) 58 subtypeSpec = univ.Integer.subtypeSpec + constraint.ValueRangeConstraint( 59 0, 4294967295 60 ) 61 62 63class Unsigned32(univ.Integer): 64 tagSet = univ.Integer.tagSet.tagImplicitly( 65 tag.Tag(tag.tagClassApplication, tag.tagFormatSimple, 0x02) 66 ) 67 subtypeSpec = univ.Integer.subtypeSpec + constraint.ValueRangeConstraint( 68 0, 4294967295 69 ) 70 71 72class TimeTicks(univ.Integer): 73 tagSet = univ.Integer.tagSet.tagImplicitly( 74 tag.Tag(tag.tagClassApplication, tag.tagFormatSimple, 0x03) 75 ) 76 subtypeSpec = univ.Integer.subtypeSpec + constraint.ValueRangeConstraint( 77 0, 4294967295 78 ) 79 80 81class Opaque(univ.OctetString): 82 tagSet = univ.OctetString.tagSet.tagImplicitly( 83 tag.Tag(tag.tagClassApplication, tag.tagFormatSimple, 0x04) 84 ) 85 86 87class Counter64(univ.Integer): 88 tagSet = univ.Integer.tagSet.tagImplicitly( 89 tag.Tag(tag.tagClassApplication, tag.tagFormatSimple, 0x06) 90 ) 91 subtypeSpec = univ.Integer.subtypeSpec + constraint.ValueRangeConstraint( 92 0, 18446744073709551615 93 ) 94 95 96class Bits(univ.OctetString): 97 pass 98 99 100class ObjectName(univ.ObjectIdentifier): 101 pass 102 103 104class SimpleSyntax(univ.Choice): 105 componentType = namedtype.NamedTypes( 106 namedtype.NamedType('integer-value', Integer()), 107 namedtype.NamedType('string-value', OctetString()), 108 namedtype.NamedType('objectID-value', univ.ObjectIdentifier()) 109 ) 110 111 112class ApplicationSyntax(univ.Choice): 113 componentType = namedtype.NamedTypes( 114 namedtype.NamedType('ipAddress-value', IpAddress()), 115 namedtype.NamedType('counter-value', Counter32()), 116 namedtype.NamedType('timeticks-value', TimeTicks()), 117 namedtype.NamedType('arbitrary-value', Opaque()), 118 namedtype.NamedType('big-counter-value', Counter64()), 119 # This conflicts with Counter32 120 # namedtype.NamedType('unsigned-integer-value', Unsigned32()), 121 namedtype.NamedType('gauge32-value', Gauge32()) 122 ) # BITS misplaced? 123 124 125class ObjectSyntax(univ.Choice): 126 componentType = namedtype.NamedTypes( 127 namedtype.NamedType('simple', SimpleSyntax()), 128 namedtype.NamedType('application-wide', ApplicationSyntax()) 129 ) 130