sibna 1.5.0__tar.gz → 1.7.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: sibna
3
- Version: 1.5.0
3
+ Version: 1.7.0
4
4
  Summary: Standalone Ultra-Secure Communication Protocol - Python SDK
5
5
  Author-email: Sibna Security Team <security@sibna.dev>
6
6
  License: Apache License
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "sibna"
7
- version = "1.5.0"
7
+ version = "1.7.0"
8
8
  description = "Standalone Ultra-Secure Communication Protocol - Python SDK"
9
9
  readme = "README.md"
10
10
  license = { file = "LICENSE" }
@@ -146,23 +146,26 @@ def pad_payload(data: bytes) -> bytes:
146
146
  """
147
147
  Pad payload to the nearest 1024-byte boundary.
148
148
  Makes all messages appear the same size to a passive observer.
149
+
150
+ Format: [padding_len: 2 bytes LE] + [data] + [random padding]
151
+ Total length is always a multiple of 1024.
149
152
  """
150
- unpadded_len = len(data) + 1
151
- remainder = unpadded_len % _PADDING_BLOCK
152
- padding_needed = (_PADDING_BLOCK - remainder) % _PADDING_BLOCK or _PADDING_BLOCK
153
- indicator = padding_needed % 256
154
- return bytes([indicator]) + data + secrets.token_bytes(padding_needed)
153
+ content_len = 2 + len(data)
154
+ remainder = content_len % _PADDING_BLOCK
155
+ padding_len = (_PADDING_BLOCK - remainder) % _PADDING_BLOCK
156
+ header = padding_len.to_bytes(2, "little")
157
+ return header + data + secrets.token_bytes(padding_len)
155
158
 
156
159
 
157
160
  def unpad_payload(padded: bytes) -> bytes:
158
161
  """Remove padding added by pad_payload()."""
159
- if not padded:
160
- raise ValueError("Empty payload")
161
- indicator = padded[0]
162
- total_len = len(padded)
163
- padding_needed = total_len % _PADDING_BLOCK
164
- actual_padding = indicator if padding_needed == 0 else padding_needed
165
- return padded[1 : total_len - actual_padding]
162
+ if len(padded) < 2:
163
+ raise ValueError("Payload too short")
164
+ padding_len = int.from_bytes(padded[:2], "little")
165
+ data_end = len(padded) - padding_len
166
+ if data_end < 2:
167
+ raise ValueError("Invalid padding length")
168
+ return padded[2:data_end]
166
169
 
167
170
 
168
171
  def make_signed_envelope(
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: sibna
3
- Version: 1.5.0
3
+ Version: 1.7.0
4
4
  Summary: Standalone Ultra-Secure Communication Protocol - Python SDK
5
5
  Author-email: Sibna Security Team <security@sibna.dev>
6
6
  License: Apache License
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes