File: base.py

package info (click to toggle)
python-pysnmp4 7.1.22-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,504 kB
  • sloc: python: 33,673; makefile: 169; javascript: 4
file content (90 lines) | stat: -rw-r--r-- 2,439 bytes parent folder | download | duplicates (2)
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#
# This file is part of pysnmp software.
#
# Copyright (c) 2005-2020, Ilya Etingof <etingof@gmail.com>
# License: https://www.pysnmp.com/pysnmp/license.html
#

from typing import TYPE_CHECKING


from pysnmp.proto import error
from pysnmp.proto.errind import ErrorIndication
from pysnmp.proto.secmod import cache

if TYPE_CHECKING:
    from pysnmp.entity.engine import SnmpEngine


class AbstractSecurityModel:
    """Abstract security model class."""

    SECURITY_MODEL_ID = None
    _cache: cache.Cache

    def __init__(self):
        """Create a security model object."""
        self._cache = cache.Cache()

    def process_incoming_message(
        self,
        snmpEngine: "SnmpEngine",
        messageProcessingModel,
        maxMessageSize,
        securityParameters,
        securityModel,
        securityLevel,
        wholeMsg,
        msg,
    ):
        """Process an incoming message."""
        raise error.ProtocolError("Security model %s not implemented" % self)

    def generate_request_message(
        self,
        snmpEngine: "SnmpEngine",
        messageProcessingModel,
        globalData,
        maxMessageSize,
        securityModel,
        securityEngineID,
        securityName,
        securityLevel,
        scopedPDU,
    ):
        """Generate a request message."""
        raise error.ProtocolError("Security model %s not implemented" % self)

    def generate_response_message(
        self,
        snmpEngine: "SnmpEngine",
        messageProcessingModel,
        globalData,
        maxMessageSize,
        securityModel,
        securityEngineID,
        securityName,
        securityLevel,
        scopedPDU,
        securityStateReference,
        ctx: ErrorIndication,
    ):
        """Generate a response message."""
        raise error.ProtocolError("Security model %s not implemented" % self)

    def release_state_information(self, stateReference):
        """Release state information."""
        self._cache.pop(stateReference)

    def receive_timer_tick(self, snmpEngine: "SnmpEngine", timeNow):
        """Process a timer tick."""
        pass

    def _close(self):
        """
        Close the security model to test memory leak.

        This method is intended for unit testing purposes only.
        It closes the security model and checks if all associated resources are released.
        """
        raise error.ProtocolError("Security model %s not implemented" % self)