rfc1902.py 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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. #
  12. from pyasn1.type import univ, namedtype, tag, constraint
  13. class Integer(univ.Integer):
  14. subtypeSpec = univ.Integer.subtypeSpec + constraint.ValueRangeConstraint(
  15. -2147483648, 2147483647
  16. )
  17. class Integer32(univ.Integer):
  18. subtypeSpec = univ.Integer.subtypeSpec + constraint.ValueRangeConstraint(
  19. -2147483648, 2147483647
  20. )
  21. class OctetString(univ.OctetString):
  22. subtypeSpec = univ.Integer.subtypeSpec + constraint.ValueSizeConstraint(
  23. 0, 65535
  24. )
  25. class IpAddress(univ.OctetString):
  26. tagSet = univ.OctetString.tagSet.tagImplicitly(
  27. tag.Tag(tag.tagClassApplication, tag.tagFormatSimple, 0x00)
  28. )
  29. subtypeSpec = univ.OctetString.subtypeSpec + constraint.ValueSizeConstraint(
  30. 4, 4
  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. class Gauge32(univ.Integer):
  40. tagSet = univ.Integer.tagSet.tagImplicitly(
  41. tag.Tag(tag.tagClassApplication, tag.tagFormatSimple, 0x02)
  42. )
  43. subtypeSpec = univ.Integer.subtypeSpec + constraint.ValueRangeConstraint(
  44. 0, 4294967295
  45. )
  46. class Unsigned32(univ.Integer):
  47. tagSet = univ.Integer.tagSet.tagImplicitly(
  48. tag.Tag(tag.tagClassApplication, tag.tagFormatSimple, 0x02)
  49. )
  50. subtypeSpec = univ.Integer.subtypeSpec + constraint.ValueRangeConstraint(
  51. 0, 4294967295
  52. )
  53. class TimeTicks(univ.Integer):
  54. tagSet = univ.Integer.tagSet.tagImplicitly(
  55. tag.Tag(tag.tagClassApplication, tag.tagFormatSimple, 0x03)
  56. )
  57. subtypeSpec = univ.Integer.subtypeSpec + constraint.ValueRangeConstraint(
  58. 0, 4294967295
  59. )
  60. class Opaque(univ.OctetString):
  61. tagSet = univ.OctetString.tagSet.tagImplicitly(
  62. tag.Tag(tag.tagClassApplication, tag.tagFormatSimple, 0x04)
  63. )
  64. class Counter64(univ.Integer):
  65. tagSet = univ.Integer.tagSet.tagImplicitly(
  66. tag.Tag(tag.tagClassApplication, tag.tagFormatSimple, 0x06)
  67. )
  68. subtypeSpec = univ.Integer.subtypeSpec + constraint.ValueRangeConstraint(
  69. 0, 18446744073709551615
  70. )
  71. class Bits(univ.OctetString):
  72. pass
  73. class ObjectName(univ.ObjectIdentifier):
  74. pass
  75. class SimpleSyntax(univ.Choice):
  76. componentType = namedtype.NamedTypes(
  77. namedtype.NamedType('integer-value', Integer()),
  78. namedtype.NamedType('string-value', OctetString()),
  79. namedtype.NamedType('objectID-value', univ.ObjectIdentifier())
  80. )
  81. class ApplicationSyntax(univ.Choice):
  82. componentType = namedtype.NamedTypes(
  83. namedtype.NamedType('ipAddress-value', IpAddress()),
  84. namedtype.NamedType('counter-value', Counter32()),
  85. namedtype.NamedType('timeticks-value', TimeTicks()),
  86. namedtype.NamedType('arbitrary-value', Opaque()),
  87. namedtype.NamedType('big-counter-value', Counter64()),
  88. # This conflicts with Counter32
  89. # namedtype.NamedType('unsigned-integer-value', Unsigned32()),
  90. namedtype.NamedType('gauge32-value', Gauge32())
  91. ) # BITS misplaced?
  92. class ObjectSyntax(univ.Choice):
  93. componentType = namedtype.NamedTypes(
  94. namedtype.NamedType('simple', SimpleSyntax()),
  95. namedtype.NamedType('application-wide', ApplicationSyntax())
  96. )