# Path: pysnmp/proto/mpmod/base.py
# class AbstractMessageProcessingModel:
#     def __init__(self):
#         self._snmpMsgSpec = self.snmpMsgSpec()  # local copy
#         self._cache = cache.Cache()
#         
#     def prepareOutgoingMessage(
#         self,
#         snmpEngine,
#         transportDomain,
#         transportAddress,
#         messageProcessingModel,
#         securityModel,
#         securityName,
#         securityLevel,
#         contextEngineId,
#         contextName,
#         pduVersion,
#         pdu,
#         expectResponse,
#         sendPduHandle
#         ):
#         raise error.ProtocolError('method not implemented')
#         
#     def prepareResponseMessage(
#         self,
#         snmpEngine,
#         messageProcessingModel,
#         securityModel,
#         securityName,
#         securityLevel,
#         contextEngineId,
#         contextName,
#         pduVersion,
#         pdu,
#         maxSizeResponseScopedPDU,
#         stateReference,
#         statusInformation
#         ):
#         raise error.ProtocolError('method not implemented')
# 
#     def prepareDataElements(
#         self,
#         snmpEngine,
#         transportDomain,
#         transportAddress,
#         wholeMsg
#         ):
#         raise error.ProtocolError('method not implemented')
# 
#     def releaseStateInformation(self, sendPduHandle):
#         try:
#             self._cache.popBySendPduHandle(sendPduHandle)
#         except error.ProtocolError:
#             pass # XXX maybe these should all follow some scheme?
#     
#     def receiveTimerTick(self, snmpEngine, timeNow):
#         self._cache.expireCaches()
# 
# Path: pysnmp/proto/errind.py
# class ErrorIndication:
# class ParseError(ErrorIndication): pass
# class UnsupportedMsgProcessingModel(ErrorIndication): pass
# class UnknownPDUHandler(ErrorIndication): pass
# class UnsupportedPDUtype(ErrorIndication): pass
# class RequestTimedOut(ErrorIndication): pass
# class EmptyResponse(ErrorIndication): pass
# class NonReportable(ErrorIndication): pass
# class DataMismatch(ErrorIndication): pass
# class EngineIDMismatch(ErrorIndication): pass
# class UnknownEngineID(ErrorIndication): pass
# class TooBig(ErrorIndication): pass
# class LoopTerminated(ErrorIndication):pass
# class InvalidMsg(ErrorIndication):pass
# class UnknownCommunityName(ErrorIndication): pass
# class NoEncryption(ErrorIndication): pass
# class EncryptionError(ErrorIndication): pass
# class DecryptionError(ErrorIndication): pass
# class NoAuthentication(ErrorIndication): pass
# class AuthenticationError(ErrorIndication): pass
# class AuthenticationFailure(ErrorIndication): pass
# class UnsupportedAuthProtocol(ErrorIndication): pass
# class UnsupportedPrivProtocol(ErrorIndication): pass
# class UnknownSecurityName(ErrorIndication): pass
# class UnsupportedSecurityModel(ErrorIndication): pass
# class UnsupportedSecurityLevel(ErrorIndication): pass
# class NotInTimeWindow(ErrorIndication): pass
# class NoSuchView(ErrorIndication): pass
# class NoAccessEntry(ErrorIndication): pass
# class NoGroupName(ErrorIndication): pass
# class NoSuchContext(ErrorIndication): pass
# class NotInView(ErrorIndication): pass
# class AccessAllowed(ErrorIndication): pass
# class OtherError(ErrorIndication): pass
# class OidNotIncreasing(ErrorIndication): pass
#     def __init__(self, descr=None):
#     def __eq__(self, other): return self.__value == other
#     def __ne__(self, other): return self.__value != other
#     def __lt__(self, other): return self.__value < other
#     def __le__(self, other): return self.__value <= other
#     def __gt__(self, other): return self.__value > other
#     def __ge__(self, other): return self.__value >= other
#     def __str__(self): return self.__descr
# 
# Path: pysnmp/debug.py
# class Debug:
#     def __init__(self, *flags):
#     def __str__(self):
#     def __call__(self, msg):
#     def __and__(self, flag):
#     def __rand__(self, flag):
# def setLogger(l):
# def hexdump(octets):


import sys
from pysnmp.proto.mpmod.base import AbstractMessageProcessingModel
from pysnmp.proto.secmod import rfc3414
from pysnmp.proto import rfc1905, rfc3411, api, errind, error
from pyasn1.type import univ, namedtype, constraint
from pyasn1.codec.ber import decoder
from pyasn1.error import PyAsn1Error
from pysnmp import debug
        namedtype.NamedType('plaintext', ScopedPDU()),
        namedtype.NamedType('encryptedPDU', univ.OctetString()),
        )
    
class HeaderData(univ.Sequence):
    componentType = namedtype.NamedTypes(
        namedtype.NamedType('msgID', univ.Integer().subtype(subtypeSpec=constraint.ValueRangeConstraint(0, 2147483647))),
        namedtype.NamedType('msgMaxSize', univ.Integer().subtype(subtypeSpec=constraint.ValueRangeConstraint(484, 2147483647))),
        namedtype.NamedType('msgFlags', univ.OctetString().subtype(subtypeSpec=constraint.ValueSizeConstraint(1, 1))),
        namedtype.NamedType('msgSecurityModel', univ.Integer().subtype(subtypeSpec=constraint.ValueRangeConstraint(1, 2147483647)))
        )

class SNMPv3Message(univ.Sequence):
    componentType = namedtype.NamedTypes(
         namedtype.NamedType('msgVersion', univ.Integer().subtype(subtypeSpec=constraint.ValueRangeConstraint(0, 2147483647))),
         namedtype.NamedType('msgGlobalData', HeaderData()),
         namedtype.NamedType('msgSecurityParameters', univ.OctetString()),
         namedtype.NamedType('msgData', ScopedPduData())
         )

# XXX move somewhere?
_snmpErrors = {
    (1, 3, 6, 1, 6, 3, 15, 1, 1, 1, 0): 'unsupportedSecLevel',
    (1, 3, 6, 1, 6, 3, 15, 1, 1, 2, 0): 'notInTimeWindow', 
    (1, 3, 6, 1, 6, 3, 15, 1, 1, 3, 0): 'unknownUserName',
    (1, 3, 6, 1, 6, 3, 15, 1, 1, 4, 0): 'unknownEngineID',
    (1, 3, 6, 1, 6, 3, 15, 1, 1, 5, 0): 'wrongDigest',
    (1, 3, 6, 1, 6, 3, 15, 1, 1, 6, 0): 'decryptionError',
    }


# Path: pysnmp/proto/mpmod/base.py
# class AbstractMessageProcessingModel:
#     def __init__(self):
#         self._snmpMsgSpec = self.snmpMsgSpec()  # local copy
#         self._cache = cache.Cache()
#         
#     def prepareOutgoingMessage(
#         self,
#         snmpEngine,
#         transportDomain,
#         transportAddress,
#         messageProcessingModel,
#         securityModel,
#         securityName,
#         securityLevel,
#         contextEngineId,
#         contextName,
#         pduVersion,
#         pdu,
#         expectResponse,
#         sendPduHandle
#         ):
#         raise error.ProtocolError('method not implemented')
#         
#     def prepareResponseMessage(
#         self,
#         snmpEngine,
#         messageProcessingModel,
#         securityModel,
#         securityName,
#         securityLevel,
#         contextEngineId,
#         contextName,
#         pduVersion,
#         pdu,
#         maxSizeResponseScopedPDU,
#         stateReference,
#         statusInformation
#         ):
#         raise error.ProtocolError('method not implemented')
# 
#     def prepareDataElements(
#         self,
#         snmpEngine,
#         transportDomain,
#         transportAddress,
#         wholeMsg
#         ):
#         raise error.ProtocolError('method not implemented')
# 
#     def releaseStateInformation(self, sendPduHandle):
#         try:
#             self._cache.popBySendPduHandle(sendPduHandle)
#         except error.ProtocolError:
#             pass # XXX maybe these should all follow some scheme?
#     
#     def receiveTimerTick(self, snmpEngine, timeNow):
#         self._cache.expireCaches()
# 
# Path: pysnmp/proto/errind.py
# class ErrorIndication:
# class ParseError(ErrorIndication): pass
# class UnsupportedMsgProcessingModel(ErrorIndication): pass
# class UnknownPDUHandler(ErrorIndication): pass
# class UnsupportedPDUtype(ErrorIndication): pass
# class RequestTimedOut(ErrorIndication): pass
# class EmptyResponse(ErrorIndication): pass
# class NonReportable(ErrorIndication): pass
# class DataMismatch(ErrorIndication): pass
# class EngineIDMismatch(ErrorIndication): pass
# class UnknownEngineID(ErrorIndication): pass
# class TooBig(ErrorIndication): pass
# class LoopTerminated(ErrorIndication):pass
# class InvalidMsg(ErrorIndication):pass
# class UnknownCommunityName(ErrorIndication): pass
# class NoEncryption(ErrorIndication): pass
# class EncryptionError(ErrorIndication): pass
# class DecryptionError(ErrorIndication): pass
# class NoAuthentication(ErrorIndication): pass
# class AuthenticationError(ErrorIndication): pass
# class AuthenticationFailure(ErrorIndication): pass
# class UnsupportedAuthProtocol(ErrorIndication): pass
# class UnsupportedPrivProtocol(ErrorIndication): pass
# class UnknownSecurityName(ErrorIndication): pass
# class UnsupportedSecurityModel(ErrorIndication): pass
# class UnsupportedSecurityLevel(ErrorIndication): pass
# class NotInTimeWindow(ErrorIndication): pass
# class NoSuchView(ErrorIndication): pass
# class NoAccessEntry(ErrorIndication): pass
# class NoGroupName(ErrorIndication): pass
# class NoSuchContext(ErrorIndication): pass
# class NotInView(ErrorIndication): pass
# class AccessAllowed(ErrorIndication): pass
# class OtherError(ErrorIndication): pass
# class OidNotIncreasing(ErrorIndication): pass
#     def __init__(self, descr=None):
#     def __eq__(self, other): return self.__value == other
#     def __ne__(self, other): return self.__value != other
#     def __lt__(self, other): return self.__value < other
#     def __le__(self, other): return self.__value <= other
#     def __gt__(self, other): return self.__value > other
#     def __ge__(self, other): return self.__value >= other
#     def __str__(self): return self.__descr
# 
# Path: pysnmp/debug.py
# class Debug:
#     def __init__(self, *flags):
#     def __str__(self):
#     def __call__(self, msg):
#     def __and__(self, flag):
#     def __rand__(self, flag):
# def setLogger(l):
# def hexdump(octets):


# Path: pysnmp/proto/mpmod/rfc3412.py
import sys
from pysnmp.proto.mpmod.base import AbstractMessageProcessingModel
from pysnmp.proto.secmod import rfc3414
from pysnmp.proto import rfc1905, rfc3411, api, errind, error
from pyasn1.type import univ, namedtype, constraint
from pyasn1.codec.ber import decoder
from pyasn1.error import PyAsn1Error
from pysnmp import debug

        namedtype.NamedType('plaintext', ScopedPDU()),
        namedtype.NamedType('encryptedPDU', univ.OctetString()),
        )
    
class HeaderData(univ.Sequence):
    componentType = namedtype.NamedTypes(
        namedtype.NamedType('msgID', univ.Integer().subtype(subtypeSpec=constraint.ValueRangeConstraint(0, 2147483647))),
        namedtype.NamedType('msgMaxSize', univ.Integer().subtype(subtypeSpec=constraint.ValueRangeConstraint(484, 2147483647))),
        namedtype.NamedType('msgFlags', univ.OctetString().subtype(subtypeSpec=constraint.ValueSizeConstraint(1, 1))),
        namedtype.NamedType('msgSecurityModel', univ.Integer().subtype(subtypeSpec=constraint.ValueRangeConstraint(1, 2147483647)))
        )

class SNMPv3Message(univ.Sequence):
    componentType = namedtype.NamedTypes(
         namedtype.NamedType('msgVersion', univ.Integer().subtype(subtypeSpec=constraint.ValueRangeConstraint(0, 2147483647))),
         namedtype.NamedType('msgGlobalData', HeaderData()),
         namedtype.NamedType('msgSecurityParameters', univ.OctetString()),
         namedtype.NamedType('msgData', ScopedPduData())
         )

# XXX move somewhere?
_snmpErrors = {
    (1, 3, 6, 1, 6, 3, 15, 1, 1, 1, 0): 'unsupportedSecLevel',
    (1, 3, 6, 1, 6, 3, 15, 1, 1, 2, 0): 'notInTimeWindow', 
    (1, 3, 6, 1, 6, 3, 15, 1, 1, 3, 0): 'unknownUserName',
    (1, 3, 6, 1, 6, 3, 15, 1, 1, 4, 0): 'unknownEngineID',
    (1, 3, 6, 1, 6, 3, 15, 1, 1, 5, 0): 'wrongDigest',
    (1, 3, 6, 1, 6, 3, 15, 1, 1, 6, 0): 'decryptionError',
    }


class SnmpV3MessageProcessingModel(AbstractMessageProcessingModel):