@@ -13,7 +13,7 @@ def format_data(data: str, max_length: Optional[int] = None) -> bytes:
1313
1414 Args:
1515 msg (str): The input string to format.
16- max_length (int, optional): The maximum length of the resulting byte array. Defaults to 800 .
16+ max_length (int, optional): The maximum length of the output byte array.
1717
1818 Returns:
1919 bytes: The formatted byte array, padded with null bytes if necessary.
@@ -26,7 +26,10 @@ def format_data(data: str, max_length: Optional[int] = None) -> bytes:
2626 raise TypeError (f"Expected int, got { type (max_length ).__name__ } " )
2727 if max_length <= 0 :
2828 raise ValueError (f"Invalid maximum length: { max_length } " )
29- return data .encode ("utf-16le" ).ljust (max_length , b"\x00 " )[:max_length ]
29+ padded_bytes = data .encode ("utf-16le" ).ljust (max_length , b"\x00 " )
30+ if len (padded_bytes ) > max_length :
31+ raise ValueError (f"Data exceeds maximum length: { len (padded_bytes )} > { max_length } " )
32+ return padded_bytes
3033
3134
3235def pkg_message (msg : str ) -> bytes :
@@ -38,9 +41,6 @@ def pkg_message(msg: str) -> bytes:
3841
3942 Returns:
4043 bytes: The packaged message as a byte array, including a header and padding.
41-
42- Raises:
43- ValueError: If the message length exceeds 800 bytes or if the header length is incorrect
4444 """
4545 data = format_data (msg , 800 )
4646 head = (
@@ -67,15 +67,6 @@ def pkg_execute(
6767
6868 Returns:
6969 bytes: The packaged command as a byte array, including a header and formatted data.
70-
71- Raises:
72- ValueError: If the executable file or arguments exceed their respective length limits,
73- or if an invalid mode is specified.
74- TypeError: If the executable file or arguments are not strings.
75-
76- Note:
77- The function constructs a specific header and formats the executable file and arguments
78- into byte arrays, ensuring they fit within defined length limits.
7970 """
8071 head = (
8172 b"DMOC\x00 \x00 \x01 \x00 n\x03 \x00 \x00 "
@@ -106,10 +97,6 @@ def pkg_website(url: str) -> bytes:
10697
10798 Returns:
10899 bytes: The packaged URL as a byte array, including a header and padding.
109-
110- Raises:
111- ValueError: If the URL length exceeds 800 bytes.
112- TypeError: If the URL is not a string.
113100 """
114101 data = format_data (url )
115102
0 commit comments