rfc3412.py 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. # SNMPv3 message syntax
  8. #
  9. # ASN.1 source from:
  10. # http://www.ietf.org/rfc/rfc3412.txt
  11. #
  12. from pyasn1.type import constraint
  13. from pyasn1.type import namedtype
  14. from pyasn1.type import univ
  15. from pyasn1_modules import rfc1905
  16. class ScopedPDU(univ.Sequence):
  17. componentType = namedtype.NamedTypes(
  18. namedtype.NamedType('contextEngineId', univ.OctetString()),
  19. namedtype.NamedType('contextName', univ.OctetString()),
  20. namedtype.NamedType('data', rfc1905.PDUs())
  21. )
  22. class ScopedPduData(univ.Choice):
  23. componentType = namedtype.NamedTypes(
  24. namedtype.NamedType('plaintext', ScopedPDU()),
  25. namedtype.NamedType('encryptedPDU', univ.OctetString()),
  26. )
  27. class HeaderData(univ.Sequence):
  28. componentType = namedtype.NamedTypes(
  29. namedtype.NamedType('msgID',
  30. univ.Integer().subtype(subtypeSpec=constraint.ValueRangeConstraint(0, 2147483647))),
  31. namedtype.NamedType('msgMaxSize',
  32. univ.Integer().subtype(subtypeSpec=constraint.ValueRangeConstraint(484, 2147483647))),
  33. namedtype.NamedType('msgFlags', univ.OctetString().subtype(subtypeSpec=constraint.ValueSizeConstraint(1, 1))),
  34. namedtype.NamedType('msgSecurityModel',
  35. univ.Integer().subtype(subtypeSpec=constraint.ValueRangeConstraint(1, 2147483647)))
  36. )
  37. class SNMPv3Message(univ.Sequence):
  38. componentType = namedtype.NamedTypes(
  39. namedtype.NamedType('msgVersion',
  40. univ.Integer().subtype(subtypeSpec=constraint.ValueRangeConstraint(0, 2147483647))),
  41. namedtype.NamedType('msgGlobalData', HeaderData()),
  42. namedtype.NamedType('msgSecurityParameters', univ.OctetString()),
  43. namedtype.NamedType('msgData', ScopedPduData())
  44. )