Example #1
0
    def __init__(self, tag=None, request_id=None, error_status=None, error_index=None, variable_bindings=None):
        if request_id is None:
            # TODO: when Integer() is fixed, use wider range of values
            request_id = Integer.from_int(randint(1 << 24, 1 << 31)).get_object()
        assert isinstance(request_id.value, Integer)
        self.request_id = request_id

        if error_status is None:
            error_status = Integer.from_int(ErrorStatus.no_error).get_object()
        assert isinstance(error_status.value, Integer)
        self.error_status = error_status

        if error_index is None:
            error_index = Integer.from_int(0).get_object()
        assert isinstance(error_index.value, Integer)
        self.error_index = error_index

        assert variable_bindings is not None
        self.variable_bindings = variable_bindings

        Object.__init__(
            self,
            self.get_object_tag() if tag is None else tag,
            [self.request_id, self.error_status, self.error_index, self.variable_bindings],
        )
Example #2
0
    def __init__(self, version=None, community=None, pdu=None):
        if version is None:
            version = Integer.from_int(self.snmp_version).get_object()
        if community is None:
            community = OctetString(b'public').get_object()
        if pdu is None:
            pass

        Object.__init__(self, ObjectTag(TagClassEnum.universal, True, UniversalClassTags.sequence_of),
                        [version, community, pdu])

        self.version = version
        self.community = community
        self.pdu = pdu
Example #3
0
    def __init__(self, version=None, community=None, pdu=None):
        if version is None:
            version = Integer.from_int(self.snmp_version).get_object()
        if community is None:
            community = OctetString(b'public').get_object()
        if pdu is None:
            pass

        Object.__init__(
            self,
            ObjectTag(TagClassEnum.universal, True,
                      UniversalClassTags.sequence_of),
            [version, community, pdu])

        self.version = version
        self.community = community
        self.pdu = pdu
Example #4
0
    def __init__(self, tag=None, request_id=None, error_status=None, error_index=None, variable_bindings=None):
        if request_id is None:
            # TODO: when Integer() is fixed, use wider range of values
            request_id = Integer.from_int(randint(1 << 24, 1 << 31)).get_object()
        assert isinstance(request_id.value, Integer)
        self.request_id = request_id

        if error_status is None:
            error_status = Integer.from_int(ErrorStatus.no_error).get_object()
        assert isinstance(error_status.value, Integer)
        self.error_status = error_status

        if error_index is None:
            error_index = Integer.from_int(0).get_object()
        assert isinstance(error_index.value, Integer)
        self.error_index = error_index

        assert variable_bindings is not None
        self.variable_bindings = variable_bindings

        Object.__init__(self, self.get_object_tag() if tag is None else tag,
                        [self.request_id, self.error_status, self.error_index, self.variable_bindings])
Example #5
0
 def decode(cls, buffer, offset=0):
     """Decodes SNMP packet
     :param buffer:
     :param offset:
     """
     (obj, offset) = Object.decode(buffer, offset)
     assert len(buffer) == offset
     (version, community, pdu) = obj.value
     assert pdu.tag.tag_class == TagClassEnum.context_specific
     assert isinstance(community.value, OctetString)
     if pdu.tag.tag_id in cls.pdus:
         pdu = cls.pdus[pdu.tag.tag_id].from_object(pdu)
     return cls(version, community, pdu)
Example #6
0
 def decode(cls, buffer, offset=0):
     """Decodes SNMP packet
     :param buffer:
     :param offset:
     """
     (obj, offset) = Object.decode(buffer, offset)
     assert len(buffer) == offset
     (version, community, pdu) = obj.value
     assert pdu.tag.tag_class == TagClassEnum.context_specific
     assert isinstance(community.value, OctetString)
     if pdu.tag.tag_id in cls.pdus:
         pdu = cls.pdus[pdu.tag.tag_id].from_object(pdu)
     return cls(version, community, pdu)
Example #7
0
 def get_object(self):
     assert self.tag_id is not None
     return Object(self.get_object_tag(), self)