Funktionierender Prototyp des Serious Games zur Vermittlung von Wissen zu Software-Engineering-Arbeitsmodellen.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

rfc1902.py 3.6KB

1 year ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. #
  2. # This file is part of pyasn1-modules software.
  3. #
  4. # Copyright (c) 2005-2020, Ilya Etingof <etingof@gmail.com>
  5. # License: http://snmplabs.com/pyasn1/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 constraint
  13. from pyasn1.type import namedtype
  14. from pyasn1.type import tag
  15. from pyasn1.type import univ
  16. class Integer(univ.Integer):
  17. subtypeSpec = univ.Integer.subtypeSpec + constraint.ValueRangeConstraint(
  18. -2147483648, 2147483647
  19. )
  20. class Integer32(univ.Integer):
  21. subtypeSpec = univ.Integer.subtypeSpec + constraint.ValueRangeConstraint(
  22. -2147483648, 2147483647
  23. )
  24. class OctetString(univ.OctetString):
  25. subtypeSpec = univ.Integer.subtypeSpec + constraint.ValueSizeConstraint(
  26. 0, 65535
  27. )
  28. class IpAddress(univ.OctetString):
  29. tagSet = univ.OctetString.tagSet.tagImplicitly(
  30. tag.Tag(tag.tagClassApplication, tag.tagFormatSimple, 0x00)
  31. )
  32. subtypeSpec = univ.OctetString.subtypeSpec + constraint.ValueSizeConstraint(
  33. 4, 4
  34. )
  35. class Counter32(univ.Integer):
  36. tagSet = univ.Integer.tagSet.tagImplicitly(
  37. tag.Tag(tag.tagClassApplication, tag.tagFormatSimple, 0x01)
  38. )
  39. subtypeSpec = univ.Integer.subtypeSpec + constraint.ValueRangeConstraint(
  40. 0, 4294967295
  41. )
  42. class Gauge32(univ.Integer):
  43. tagSet = univ.Integer.tagSet.tagImplicitly(
  44. tag.Tag(tag.tagClassApplication, tag.tagFormatSimple, 0x02)
  45. )
  46. subtypeSpec = univ.Integer.subtypeSpec + constraint.ValueRangeConstraint(
  47. 0, 4294967295
  48. )
  49. class Unsigned32(univ.Integer):
  50. tagSet = univ.Integer.tagSet.tagImplicitly(
  51. tag.Tag(tag.tagClassApplication, tag.tagFormatSimple, 0x02)
  52. )
  53. subtypeSpec = univ.Integer.subtypeSpec + constraint.ValueRangeConstraint(
  54. 0, 4294967295
  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. class Opaque(univ.OctetString):
  64. tagSet = univ.OctetString.tagSet.tagImplicitly(
  65. tag.Tag(tag.tagClassApplication, tag.tagFormatSimple, 0x04)
  66. )
  67. class Counter64(univ.Integer):
  68. tagSet = univ.Integer.tagSet.tagImplicitly(
  69. tag.Tag(tag.tagClassApplication, tag.tagFormatSimple, 0x06)
  70. )
  71. subtypeSpec = univ.Integer.subtypeSpec + constraint.ValueRangeConstraint(
  72. 0, 18446744073709551615
  73. )
  74. class Bits(univ.OctetString):
  75. pass
  76. class ObjectName(univ.ObjectIdentifier):
  77. pass
  78. class SimpleSyntax(univ.Choice):
  79. componentType = namedtype.NamedTypes(
  80. namedtype.NamedType('integer-value', Integer()),
  81. namedtype.NamedType('string-value', OctetString()),
  82. namedtype.NamedType('objectID-value', univ.ObjectIdentifier())
  83. )
  84. class ApplicationSyntax(univ.Choice):
  85. componentType = namedtype.NamedTypes(
  86. namedtype.NamedType('ipAddress-value', IpAddress()),
  87. namedtype.NamedType('counter-value', Counter32()),
  88. namedtype.NamedType('timeticks-value', TimeTicks()),
  89. namedtype.NamedType('arbitrary-value', Opaque()),
  90. namedtype.NamedType('big-counter-value', Counter64()),
  91. # This conflicts with Counter32
  92. # namedtype.NamedType('unsigned-integer-value', Unsigned32()),
  93. namedtype.NamedType('gauge32-value', Gauge32())
  94. ) # BITS misplaced?
  95. class ObjectSyntax(univ.Choice):
  96. componentType = namedtype.NamedTypes(
  97. namedtype.NamedType('simple', SimpleSyntax()),
  98. namedtype.NamedType('application-wide', ApplicationSyntax())
  99. )