rfc1155.py 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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. # SNMPv1 message syntax
  8. #
  9. # ASN.1 source from:
  10. # http://www.ietf.org/rfc/rfc1155.txt
  11. #
  12. # Sample captures from:
  13. # http://wiki.wireshark.org/SampleCaptures/
  14. #
  15. from pyasn1.type import univ, namedtype, tag, constraint
  16. class ObjectName(univ.ObjectIdentifier):
  17. pass
  18. class SimpleSyntax(univ.Choice):
  19. componentType = namedtype.NamedTypes(
  20. namedtype.NamedType('number', univ.Integer()),
  21. namedtype.NamedType('string', univ.OctetString()),
  22. namedtype.NamedType('object', univ.ObjectIdentifier()),
  23. namedtype.NamedType('empty', univ.Null())
  24. )
  25. class IpAddress(univ.OctetString):
  26. tagSet = univ.OctetString.tagSet.tagImplicitly(
  27. tag.Tag(tag.tagClassApplication, tag.tagFormatSimple, 0)
  28. )
  29. subtypeSpec = univ.Integer.subtypeSpec + constraint.ValueSizeConstraint(
  30. 4, 4
  31. )
  32. class NetworkAddress(univ.Choice):
  33. componentType = namedtype.NamedTypes(
  34. namedtype.NamedType('internet', IpAddress())
  35. )
  36. class Counter(univ.Integer):
  37. tagSet = univ.Integer.tagSet.tagImplicitly(
  38. tag.Tag(tag.tagClassApplication, tag.tagFormatSimple, 1)
  39. )
  40. subtypeSpec = univ.Integer.subtypeSpec + constraint.ValueRangeConstraint(
  41. 0, 4294967295
  42. )
  43. class Gauge(univ.Integer):
  44. tagSet = univ.Integer.tagSet.tagImplicitly(
  45. tag.Tag(tag.tagClassApplication, tag.tagFormatSimple, 2)
  46. )
  47. subtypeSpec = univ.Integer.subtypeSpec + constraint.ValueRangeConstraint(
  48. 0, 4294967295
  49. )
  50. class TimeTicks(univ.Integer):
  51. tagSet = univ.Integer.tagSet.tagImplicitly(
  52. tag.Tag(tag.tagClassApplication, tag.tagFormatSimple, 3)
  53. )
  54. subtypeSpec = univ.Integer.subtypeSpec + constraint.ValueRangeConstraint(
  55. 0, 4294967295
  56. )
  57. class Opaque(univ.OctetString):
  58. tagSet = univ.OctetString.tagSet.tagImplicitly(
  59. tag.Tag(tag.tagClassApplication, tag.tagFormatSimple, 4)
  60. )
  61. class ApplicationSyntax(univ.Choice):
  62. componentType = namedtype.NamedTypes(
  63. namedtype.NamedType('address', NetworkAddress()),
  64. namedtype.NamedType('counter', Counter()),
  65. namedtype.NamedType('gauge', Gauge()),
  66. namedtype.NamedType('ticks', TimeTicks()),
  67. namedtype.NamedType('arbitrary', Opaque())
  68. )
  69. class ObjectSyntax(univ.Choice):
  70. componentType = namedtype.NamedTypes(
  71. namedtype.NamedType('simple', SimpleSyntax()),
  72. namedtype.NamedType('application-wide', ApplicationSyntax())
  73. )