# Path: conpot/utils/networking.py
# def str_to_bytes(x):
#     return x if isinstance(x, bytes) else str(x).encode("ascii")


from struct import pack, unpack
from conpot.protocols.s7comm.exceptions import AssembleException, ParseException
from conpot.utils.networking import str_to_bytes
import struct
import conpot.core as conpot_core
import logging
            return 12 + int(self.param_length) + int(self.data_length)
        else:
            return 10 + int(self.param_length) + int(self.data_length)

    def handle(self, current_client=None):
        if self.param in self.param_mapping:
            if self.param == 0x29:
                return self.param_mapping[self.param][1](current_client)
            # direct execution to the correct method based on the param
            return self.param_mapping[self.param][1]()

    def request_not_implemented(self):
        raise ParseException("s7comm", "request not implemented in honeypot yet.")

    def pack(self):
        if self.pdu_type not in self.pdu_mapping:
            raise AssembleException("s7comm", "invalid or unsupported pdu type")
        elif self.pdu_type in (2, 3):
            # type 2 and 3 feature an additional RESULT INFORMATION header
            return (
                pack(
                    "!BBHHHHH",
                    self.magic,
                    self.pdu_type,
                    self.reserved,
                    self.request_id,
                    self.param_length,
                    self.data_length,
                    self.result_info,
                )

# Path: conpot/utils/networking.py
# def str_to_bytes(x):
#     return x if isinstance(x, bytes) else str(x).encode("ascii")


# Path: conpot/protocols/s7comm/s7.py
from struct import pack, unpack
from conpot.protocols.s7comm.exceptions import AssembleException, ParseException
from conpot.utils.networking import str_to_bytes
import struct
import conpot.core as conpot_core
import logging

            return 12 + int(self.param_length) + int(self.data_length)
        else:
            return 10 + int(self.param_length) + int(self.data_length)

    def handle(self, current_client=None):
        if self.param in self.param_mapping:
            if self.param == 0x29:
                return self.param_mapping[self.param][1](current_client)
            # direct execution to the correct method based on the param
            return self.param_mapping[self.param][1]()

    def request_not_implemented(self):
        raise ParseException("s7comm", "request not implemented in honeypot yet.")

    def pack(self):
        if self.pdu_type not in self.pdu_mapping:
            raise AssembleException("s7comm", "invalid or unsupported pdu type")
        elif self.pdu_type in (2, 3):
            # type 2 and 3 feature an additional RESULT INFORMATION header
            return (
                pack(
                    "!BBHHHHH",
                    self.magic,
                    self.pdu_type,
                    self.reserved,
                    self.request_id,
                    self.param_length,
                    self.data_length,
                    self.result_info,
                )

                + str_to_bytes(self.parameters)