summaryrefslogtreecommitdiff
path: root/pysnmp/proto/secmod/base.py
blob: 1f6911868c52a7c361b5153415a2c495e2569232 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
from pysnmp.proto import error

class AbstractSecurityModel:
    securityModelID = None
    __stateReference = 0L
    def __init__(self):
        self.__cacheEntries = {}

    def processIncomingMsg(
        self,
        snmpEngine,
        messageProcessingModel,
        maxMessageSize,
        securityParameters,
        securityModel,
        securityLevel,
        wholeMsg,
        msg,
        ):
        raise error.ProtocolError(
            'Security model %s not implemented' % self
            )

    def generateRequestMsg(
        self,
        snmpEngine,
        messageProcessingModel,
        globalData,
        maxMessageSize,
        securityModel,
        securityEngineID,
        securityName,
        securityLevel,
        scopedPDU,
        ):
        raise error.ProtocolError(
            'Security model %s not implemented' % self
            )

    def generateResponseMsg(
        self,
        snmpEngine,
        messageProcessingModel,
        globalData,
        maxMessageSize,
        securityModel,
        securityEngineID,
        securityName,
        securityLevel,
        scopedPDU,
        securityStateReference
        ):
        raise error.ProtocolError(
            'Security model %s not implemented' % self
            )

    # Caching stuff
    
    def _cachePush(self, **securityData):
        stateReference = AbstractSecurityModel.__stateReference
        AbstractSecurityModel.__stateReference = stateReference + 1
        self.__cacheEntries[stateReference] = securityData
        return stateReference
    
    def _cachePop(self, stateReference):
        securityData = self.__cacheEntries.get(stateReference)
        if securityData is None:
            raise error.ProtocolError(
                'Cache miss for stateReference=%s at %s' %
                (stateReference, self)
                )
        del self.__cacheEntries[stateReference]
        return securityData

    def releaseStateInformation(self, stateReference):
        self._cachePop(stateReference)