meshcoredecoder 0.3.0__py3-none-any.whl → 0.3.1__py3-none-any.whl

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.
cli.py CHANGED
@@ -36,6 +36,9 @@ def print_formatted_packet(packet, keys: Optional[List[str]] = None):
36
36
  print(f'{bold("Payload Type:")} {get_payload_type_name(packet.payload_type)}')
37
37
  print(f'{bold("Total Bytes:")} {packet.total_bytes}')
38
38
 
39
+ # Path comes from the decoder (which applies path-length fallback for repeater-style adverts)
40
+ if packet.path_length and packet.path_length > 0:
41
+ print(f'{bold("Path Length:")} {packet.path_length} byte(s)')
39
42
  if packet.path and len(packet.path) > 0:
40
43
  print(f'{bold("Path:")} {" → ".join(packet.path)}')
41
44
 
index.py CHANGED
@@ -6,7 +6,7 @@ MIT License
6
6
  Main entry point for the MeshCore decoder Python port
7
7
  """
8
8
 
9
- __version__ = "0.3.0"
9
+ __version__ = "0.3.1"
10
10
 
11
11
  # Main decoder
12
12
  from src.decoder.packet_decoder import MeshCorePacketDecoder
@@ -5,4 +5,4 @@ from .decoder.packet_decoder import MeshCorePacketDecoder
5
5
  MeshCoreDecoder = MeshCorePacketDecoder
6
6
 
7
7
  __all__ = ['MeshCoreDecoder', 'MeshCorePacketDecoder']
8
- __version__ = "0.3.0"
8
+ __version__ = "0.3.1"
@@ -1147,20 +1147,30 @@ class ChannelCrypto:
1147
1147
  if not decrypted_bytes or len(decrypted_bytes) < 2:
1148
1148
  return DecryptionResult(success=False, error='Decrypted content too short')
1149
1149
 
1150
- # Parse MeshCore path format: path_len(1) + path(path_len) + extra_type(1) + extra(variable)
1151
- path_len = decrypted_bytes[0]
1152
-
1153
- if len(decrypted_bytes) < 1 + path_len + 1:
1150
+ # Parse MeshCore path format (same encoding as packet header): path_len_byte(1) with
1151
+ # bits 7:6 = hash_size-1 (1/2/3 bytes per hop), bits 5:0 = hop count (0-63).
1152
+ # path_byte_len = hop_count * hash_size; then extra_type(1) + extra(variable).
1153
+ path_len_byte = decrypted_bytes[0]
1154
+ path_hash_size = (path_len_byte >> 6) + 1 # 1, 2, or 3; 4 = reserved
1155
+ path_hash_count = path_len_byte & 63
1156
+ path_byte_len = path_hash_count * path_hash_size
1157
+
1158
+ if path_hash_size == 4:
1159
+ return DecryptionResult(success=False, error='Reserved path hash size in Path payload')
1160
+
1161
+ if len(decrypted_bytes) < 1 + path_byte_len + 1:
1154
1162
  return DecryptionResult(success=False, error='Decrypted content too short for path structure')
1155
1163
 
1156
- path = decrypted_bytes[1:1 + path_len]
1157
- extra_type = decrypted_bytes[1 + path_len]
1158
- extra = decrypted_bytes[2 + path_len:] if len(decrypted_bytes) > 2 + path_len else b''
1164
+ path = decrypted_bytes[1:1 + path_byte_len]
1165
+ extra_type = decrypted_bytes[1 + path_byte_len]
1166
+ extra = decrypted_bytes[2 + path_byte_len:] if len(decrypted_bytes) > 2 + path_byte_len else b''
1159
1167
 
1160
1168
  return DecryptionResult(
1161
1169
  success=True,
1162
1170
  data={
1163
- 'path_len': path_len,
1171
+ 'path_len_byte': path_len_byte,
1172
+ 'path_hash_size': path_hash_size,
1173
+ 'path_hash_count': path_hash_count,
1164
1174
  'path': path,
1165
1175
  'extra_type': extra_type,
1166
1176
  'extra': extra
@@ -34,24 +34,28 @@ class Ed25519SignatureVerifier:
34
34
  app_data_hex: str
35
35
  ) -> bool:
36
36
  """
37
- Verify an Ed25519 signature for MeshCore advertisement packets
37
+ Verify an Ed25519 signature for MeshCore advertisement packets.
38
38
 
39
- According to MeshCore protocol, the signed message for advertisements is:
40
- public_key (32 bytes) + timestamp (4 bytes LE) + app_data (variable)
39
+ Signed message is public_key + timestamp + app_data (docs/payloads.md).
40
+ We also try timestamp + public_key + app_data in case firmware varies.
41
41
  """
42
42
  try:
43
- # Convert hex strings to bytes
44
43
  public_key = hex_to_bytes(public_key_hex)
45
44
  signature = hex_to_bytes(signature_hex)
46
45
  app_data = hex_to_bytes(app_data_hex)
46
+ timestamp_bytes = timestamp.to_bytes(4, byteorder='little')
47
47
 
48
- # Construct the signed message according to MeshCore format
49
- message = Ed25519SignatureVerifier._construct_advert_signed_message(
50
- public_key_hex, timestamp, app_data
51
- )
48
+ # Primary: public_key + timestamp (LE) + app_data (per payloads.md)
49
+ message_pk_first = public_key + timestamp_bytes + app_data
50
+ if Ed25519SignatureVerifier._verify_signature(signature, message_pk_first, public_key):
51
+ return True
52
52
 
53
- # Verify the signature
54
- return Ed25519SignatureVerifier._verify_signature(signature, message, public_key)
53
+ # Alternative: timestamp + public_key + app_data (in case firmware uses this order)
54
+ message_ts_first = timestamp_bytes + public_key + app_data
55
+ if Ed25519SignatureVerifier._verify_signature(signature, message_ts_first, public_key):
56
+ return True
57
+
58
+ return False
55
59
  except Exception as error:
56
60
  print(f'Ed25519 signature verification failed: {error}')
57
61
  return False
@@ -152,40 +152,70 @@ class MeshCorePacketDecoder:
152
152
  ))
153
153
  offset += 4
154
154
 
155
- # Parse path
155
+ # Parse path (multi-byte path encoding per meshcore-decoder PR #8 / Packet.h)
156
+ # Bits 7:6 = hash size selector: (path_len_byte >> 6) + 1 = 1, 2, or 3 bytes per hop
157
+ # Bits 5:0 = hop count (0-63). path_byte_length = hop_count * hash_size
156
158
  if len(bytes_data) < offset + 1:
157
159
  raise ValueError('Packet too short for path length')
158
- path_length = bytes_data[offset]
160
+ path_length_byte = bytes_data[offset]
161
+ path_hash_size, path_hop_count, path_byte_length = MeshCorePacketDecoder._decode_path_len_byte(path_length_byte)
162
+
163
+ payload_start = offset + 1
164
+ remaining_after_path = len(bytes_data) - payload_start
165
+
166
+ # Use legacy (raw path byte count) only when:
167
+ # - Reserved hash size (bits 7:6 = 11), or
168
+ # - Path would extend past packet (path_byte_length > remaining_after_path).
169
+ # Do NOT use min_payload to trigger legacy; valid new-encoding packets can have small payloads.
170
+ use_legacy = False
171
+ if path_hash_size == 4:
172
+ use_legacy = True
173
+ elif path_byte_length > remaining_after_path:
174
+ use_legacy = True
175
+
176
+ if use_legacy:
177
+ # Legacy: path_length byte = raw path byte count (1 byte per hop). Cap at packet and MAX_PATH_SIZE (64).
178
+ path_byte_length = min(path_length_byte, remaining_after_path, 64)
179
+ path_hop_count = path_byte_length
180
+ path_hash_size = 1
159
181
 
160
182
  if include_structure:
161
- if route_type in (RouteType.Direct, RouteType.TransportDirect):
162
- path_length_description = f'For "Direct" packets, this contains routing instructions. {path_length} bytes of routing instructions (decreases as packet travels)'
183
+ hash_desc = f' × {path_hash_size}-byte hashes' if path_hash_size > 1 else ''
184
+ if path_hop_count == 0:
185
+ path_length_description = f'No path data{hash_desc}' if path_hash_size > 1 else 'No path data'
186
+ elif route_type in (RouteType.Direct, RouteType.TransportDirect):
187
+ path_length_description = f'{path_hop_count} hop(s){hash_desc} of routing instructions (decreases as packet travels)'
163
188
  elif route_type in (RouteType.Flood, RouteType.TransportFlood):
164
- path_length_description = f'{path_length} bytes showing route taken (increases as packet floods)'
189
+ path_length_description = f'{path_hop_count} hop(s){hash_desc} showing route taken (increases as packet floods)'
165
190
  else:
166
- path_length_description = f'Path contains {path_length} bytes'
191
+ path_length_description = f'Path: {path_hop_count} hop(s){hash_desc}'
167
192
 
168
193
  segments.append(PacketSegment(
169
194
  name='Path Length',
170
195
  description=path_length_description,
171
196
  start_byte=offset,
172
197
  end_byte=offset,
173
- value=f'0x{path_length:02x}'
198
+ value=f'0x{path_length_byte:02x}'
174
199
  ))
175
200
  offset += 1
176
201
 
177
- if len(bytes_data) < offset + path_length:
202
+ if len(bytes_data) < offset + path_byte_length:
178
203
  raise ValueError('Packet too short for path data')
179
204
 
180
- # Convert path data to hex strings
181
- path_bytes = bytes_data[offset:offset + path_length]
182
- path: Optional[List[str]] = [byte_to_hex(b) for b in path_bytes] if path_length > 0 else None
205
+ # Convert path data to list of hex strings (one per hop, hash_size bytes each)
206
+ path: Optional[List[str]] = None
207
+ if path_hop_count > 0 and path_byte_length > 0:
208
+ path = []
209
+ for i in range(path_hop_count):
210
+ hop_start = offset + i * path_hash_size
211
+ hop_bytes = bytes_data[hop_start:hop_start + path_hash_size]
212
+ path.append(bytes_to_hex(hop_bytes))
183
213
 
184
- if include_structure and path_length > 0:
214
+ if include_structure and path_byte_length > 0:
185
215
  if payload_type == PayloadType.Trace:
186
- # TRACE packets have SNR values in path
216
+ # TRACE packets: path holds SNR values (single-byte entries)
187
217
  snr_values = []
188
- for i in range(path_length):
218
+ for i in range(path_byte_length):
189
219
  snr_raw = bytes_data[offset + i]
190
220
  snr_signed = snr_raw - 256 if snr_raw > 127 else snr_raw
191
221
  snr_db = snr_signed / 4.0
@@ -194,25 +224,24 @@ class MeshCorePacketDecoder:
194
224
  name='Path SNR Data',
195
225
  description=f'SNR values collected during trace: {", ".join(snr_values)}',
196
226
  start_byte=offset,
197
- end_byte=offset + path_length - 1,
198
- value=bytes_to_hex(bytes_data[offset:offset + path_length])
227
+ end_byte=offset + path_byte_length - 1,
228
+ value=bytes_to_hex(bytes_data[offset:offset + path_byte_length])
199
229
  ))
200
230
  else:
231
+ path_description = f'Routing path ({path_hash_size}-byte hash per hop)' if path_hash_size > 1 else 'Routing path information'
201
232
  if route_type in (RouteType.Direct, RouteType.TransportDirect):
202
- path_description = 'Routing instructions (bytes are stripped at each hop as packet travels to destination)'
233
+ path_description = f'Routing instructions ({path_hash_size}-byte hashes stripped at each hop)'
203
234
  elif route_type in (RouteType.Flood, RouteType.TransportFlood):
204
- path_description = 'Historical route taken (bytes are added as packet floods through network)'
205
- else:
206
- path_description = 'Routing path information'
235
+ path_description = f'Historical route taken ({path_hash_size}-byte hashes per hop)'
207
236
 
208
237
  segments.append(PacketSegment(
209
238
  name='Path Data',
210
239
  description=path_description,
211
240
  start_byte=offset,
212
- end_byte=offset + path_length - 1,
213
- value=bytes_to_hex(bytes_data[offset:offset + path_length])
241
+ end_byte=offset + path_byte_length - 1,
242
+ value=bytes_to_hex(bytes_data[offset:offset + path_byte_length])
214
243
  ))
215
- offset += path_length
244
+ offset += path_byte_length
216
245
 
217
246
  # Extract payload
218
247
  payload_bytes = bytes_data[offset:]
@@ -315,8 +344,10 @@ class MeshCorePacketDecoder:
315
344
  value=bytes_to_hex(payload_bytes)
316
345
  ))
317
346
 
318
- # Calculate message hash
319
- message_hash = MeshCorePacketDecoder._calculate_message_hash(bytes_data, route_type, payload_type, payload_version)
347
+ # Calculate message hash (use same path_byte_length we used for decoding)
348
+ message_hash = MeshCorePacketDecoder._calculate_message_hash(
349
+ bytes_data, route_type, payload_type, payload_version, path_byte_length_override=path_byte_length
350
+ )
320
351
 
321
352
  packet = DecodedPacket(
322
353
  message_hash=message_hash,
@@ -324,11 +355,13 @@ class MeshCorePacketDecoder:
324
355
  payload_type=payload_type,
325
356
  payload_version=payload_version,
326
357
  transport_codes=transport_codes,
327
- path_length=path_length,
358
+ path_length=path_hop_count,
328
359
  path=path,
329
360
  payload={'raw': payload_hex, 'decoded': decoded_payload},
330
361
  total_bytes=len(bytes_data),
331
- is_valid=True
362
+ is_valid=True,
363
+ path_byte_length=path_byte_length,
364
+ path_hash_size=path_hash_size if path_hash_size != 1 else None,
332
365
  )
333
366
 
334
367
  structure = PacketStructure(
@@ -387,7 +420,7 @@ class MeshCorePacketDecoder:
387
420
  advert_payload = result['packet'].payload['decoded']
388
421
  bytes_data = hex_to_bytes(hex_data)
389
422
 
390
- # Calculate payload start offset
423
+ # Calculate payload start offset (use same path_length as decoded packet, which may use fallback)
391
424
  offset = 1 # Skip header
392
425
 
393
426
  # Skip transport codes if present
@@ -395,10 +428,9 @@ class MeshCorePacketDecoder:
395
428
  if route_type in (RouteType.TransportFlood, RouteType.TransportDirect):
396
429
  offset += 4
397
430
 
398
- # Skip path data
399
- if len(bytes_data) > offset:
400
- path_length = bytes_data[offset]
401
- offset += 1 + path_length
431
+ # Skip path data: use the packet's path_byte_length (total path bytes after path_len byte)
432
+ path_byte_length = getattr(result['packet'], 'path_byte_length', result['packet'].path_length) or 0
433
+ offset += 1 + path_byte_length
402
434
 
403
435
  # Get the payload bytes
404
436
  payload_bytes = bytes_data[offset:]
@@ -412,11 +444,8 @@ class MeshCorePacketDecoder:
412
444
  if verified_advert:
413
445
  # Update the payload with verification results
414
446
  result['packet'].payload['decoded'] = verified_advert
415
-
416
- # If the advertisement signature is invalid, mark the whole packet as invalid
417
- if not verified_advert.is_valid:
418
- result['packet'].is_valid = False
419
- result['packet'].errors = verified_advert.errors or ['Invalid advertisement signature']
447
+ # Do not mark the whole packet invalid when only the advert signature fails;
448
+ # packet stays valid so decoded advert and signature_valid/errors are visible.
420
449
 
421
450
  # Update structure segments if needed
422
451
  if include_structure and hasattr(verified_advert, 'segments') and verified_advert.segments:
@@ -447,16 +476,18 @@ class MeshCorePacketDecoder:
447
476
  errors.append('Packet too short for transport codes')
448
477
  offset += 4
449
478
 
450
- # Check path length
479
+ # Check path (multi-byte encoding)
451
480
  if len(bytes_data) < offset + 1:
452
481
  errors.append('Packet too short for path length')
453
482
  else:
454
- path_length = bytes_data[offset]
483
+ path_len_byte = bytes_data[offset]
455
484
  offset += 1
456
-
457
- if len(bytes_data) < offset + path_length:
485
+ hash_size, hop_count, byte_length = MeshCorePacketDecoder._decode_path_len_byte(path_len_byte)
486
+ if hash_size == 4:
487
+ errors.append('Invalid path length byte: reserved hash size (bits 7:6 = 11)')
488
+ if len(bytes_data) < offset + byte_length:
458
489
  errors.append('Packet too short for path data')
459
- offset += path_length
490
+ offset += byte_length
460
491
 
461
492
  # Check if we have payload data
462
493
  if offset >= len(bytes_data):
@@ -468,20 +499,59 @@ class MeshCorePacketDecoder:
468
499
  return ValidationResult(is_valid=len(errors) == 0, errors=errors if errors else None)
469
500
 
470
501
  @staticmethod
471
- def _calculate_message_hash(bytes_data: bytes, route_type: RouteType, payload_type: PayloadType, payload_version: PayloadVersion) -> str:
502
+ def _decode_path_len_byte(path_len_byte: int) -> tuple:
503
+ """
504
+ Decode path length byte per meshcore-decoder PR #8 / Packet.h.
505
+ Bits 7:6 = hash size selector: (path_len_byte >> 6) + 1 = 1, 2, or 3 bytes per hop.
506
+ Bits 5:0 = hop count (0-63).
507
+ Returns (hash_size, hop_count, byte_length). hash_size 4 = reserved.
508
+ """
509
+ hash_size = (path_len_byte >> 6) + 1 # 1, 2, or 3; 4 if bits 7:6 = 11 (reserved)
510
+ hop_count = path_len_byte & 63
511
+ byte_length = hop_count * hash_size
512
+ return (hash_size, hop_count, byte_length)
513
+
514
+ @staticmethod
515
+ def _min_payload_for_type(payload_type: PayloadType) -> int:
516
+ """Minimum payload size in bytes for the payload type (for path-length fallback)."""
517
+ mins = {
518
+ PayloadType.Advert: 101, # public_key(32) + timestamp(4) + signature(64) + flags(1)
519
+ PayloadType.AnonRequest: 35, # dest(1) + pubkey(32) + MAC(2)
520
+ PayloadType.Trace: 9,
521
+ PayloadType.Ack: 4,
522
+ PayloadType.Control: 1,
523
+ PayloadType.Request: 4,
524
+ PayloadType.Response: 4,
525
+ PayloadType.TextMessage: 4,
526
+ PayloadType.Path: 4,
527
+ PayloadType.GroupText: 3,
528
+ PayloadType.GroupData: 3,
529
+ }
530
+ return mins.get(payload_type, 0)
531
+
532
+ @staticmethod
533
+ def _calculate_message_hash(
534
+ bytes_data: bytes,
535
+ route_type: RouteType,
536
+ payload_type: PayloadType,
537
+ payload_version: PayloadVersion,
538
+ path_byte_length_override: Optional[int] = None,
539
+ ) -> str:
472
540
  """Calculate message hash for a packet"""
541
+ def skip_path(off: int) -> int:
542
+ if path_byte_length_override is not None:
543
+ return off + 1 + path_byte_length_override
544
+ if len(bytes_data) <= off:
545
+ return off
546
+ _, _, path_byte_len = MeshCorePacketDecoder._decode_path_len_byte(bytes_data[off])
547
+ return off + 1 + path_byte_len
548
+
473
549
  # For TRACE packets, use the trace tag as hash
474
550
  if payload_type == PayloadType.Trace and len(bytes_data) >= 13:
475
551
  offset = 1
476
-
477
- # Skip transport codes if present
478
552
  if route_type in (RouteType.TransportFlood, RouteType.TransportDirect):
479
553
  offset += 4
480
-
481
- # Skip path data
482
- if len(bytes_data) > offset:
483
- path_len = bytes_data[offset]
484
- offset += 1 + path_len
554
+ offset = skip_path(offset)
485
555
 
486
556
  # Extract trace tag
487
557
  if len(bytes_data) >= offset + 4:
@@ -494,15 +564,9 @@ class MeshCorePacketDecoder:
494
564
  # For other packets, create hash from constant parts
495
565
  constant_header = (payload_type.value << 2) | (payload_version.value << 6)
496
566
  offset = 1
497
-
498
- # Skip transport codes if present
499
567
  if route_type in (RouteType.TransportFlood, RouteType.TransportDirect):
500
568
  offset += 4
501
-
502
- # Skip path data
503
- if len(bytes_data) > offset:
504
- path_len = bytes_data[offset]
505
- offset += 1 + path_len
569
+ offset = skip_path(offset)
506
570
 
507
571
  payload_data = bytes_data[offset:]
508
572
  hash_input = [constant_header] + list(payload_data)
@@ -149,22 +149,29 @@ class PathPayloadDecoder:
149
149
  )
150
150
 
151
151
  if decryption_result.success and decryption_result.data:
152
- # Parse decrypted path structure
153
- path_len = decryption_result.data['path_len']
152
+ # Parse decrypted path structure (multi-byte path encoding)
153
+ path_hash_size = decryption_result.data['path_hash_size']
154
+ path_hash_count = decryption_result.data['path_hash_count']
154
155
  path_bytes = decryption_result.data['path']
155
156
  extra_type = decryption_result.data['extra_type']
156
157
  extra_bytes = decryption_result.data['extra']
157
158
 
158
- # Convert path bytes to hex strings
159
- path_hashes = [byte_to_hex(b) for b in path_bytes]
159
+ # One hex string per hop (each hop is path_hash_size bytes)
160
+ path_hashes = []
161
+ for i in range(path_hash_count):
162
+ hop_start = i * path_hash_size
163
+ hop_bytes = path_bytes[hop_start:hop_start + path_hash_size]
164
+ path_hashes.append(bytes_to_hex(hop_bytes))
160
165
  extra_data = bytes_to_hex(extra_bytes)
161
166
 
162
- result.path_length = path_len
167
+ result.path_length = path_hash_count
163
168
  result.path_hashes = path_hashes
164
169
  result.extra_type = extra_type
165
170
  result.extra_data = extra_data
166
171
  result.decrypted = {
167
- 'path_len': path_len,
172
+ 'path_len_byte': decryption_result.data['path_len_byte'],
173
+ 'path_hash_size': path_hash_size,
174
+ 'path_hash_count': path_hash_count,
168
175
  'path_hashes': path_hashes,
169
176
  'extra_type': extra_type,
170
177
  'extra_data': extra_data
@@ -204,22 +211,28 @@ class PathPayloadDecoder:
204
211
  )
205
212
 
206
213
  if decryption_result.success and decryption_result.data:
207
- # Parse decrypted path structure
208
- path_len = decryption_result.data['path_len']
214
+ # Parse decrypted path structure (multi-byte path encoding)
215
+ path_hash_size = decryption_result.data['path_hash_size']
216
+ path_hash_count = decryption_result.data['path_hash_count']
209
217
  path_bytes = decryption_result.data['path']
210
218
  extra_type = decryption_result.data['extra_type']
211
219
  extra_bytes = decryption_result.data['extra']
212
220
 
213
- # Convert path bytes to hex strings
214
- path_hashes = [byte_to_hex(b) for b in path_bytes]
221
+ path_hashes = []
222
+ for i in range(path_hash_count):
223
+ hop_start = i * path_hash_size
224
+ hop_bytes = path_bytes[hop_start:hop_start + path_hash_size]
225
+ path_hashes.append(bytes_to_hex(hop_bytes))
215
226
  extra_data = bytes_to_hex(extra_bytes)
216
227
 
217
- result.path_length = path_len
228
+ result.path_length = path_hash_count
218
229
  result.path_hashes = path_hashes
219
230
  result.extra_type = extra_type
220
231
  result.extra_data = extra_data
221
232
  result.decrypted = {
222
- 'path_len': path_len,
233
+ 'path_len_byte': decryption_result.data['path_len_byte'],
234
+ 'path_hash_size': path_hash_size,
235
+ 'path_hash_count': path_hash_count,
223
236
  'path_hashes': path_hashes,
224
237
  'extra_type': extra_type,
225
238
  'extra_data': extra_data
@@ -240,22 +253,28 @@ class PathPayloadDecoder:
240
253
  shared_secret
241
254
  )
242
255
  if decryption_result.success and decryption_result.data:
243
- # Parse decrypted path structure
244
- path_len = decryption_result.data['path_len']
256
+ # Parse decrypted path structure (multi-byte path encoding)
257
+ path_hash_size = decryption_result.data['path_hash_size']
258
+ path_hash_count = decryption_result.data['path_hash_count']
245
259
  path_bytes = decryption_result.data['path']
246
260
  extra_type = decryption_result.data['extra_type']
247
261
  extra_bytes = decryption_result.data['extra']
248
262
 
249
- # Convert path bytes to hex strings
250
- path_hashes = [byte_to_hex(b) for b in path_bytes]
263
+ path_hashes = []
264
+ for i in range(path_hash_count):
265
+ hop_start = i * path_hash_size
266
+ hop_bytes = path_bytes[hop_start:hop_start + path_hash_size]
267
+ path_hashes.append(bytes_to_hex(hop_bytes))
251
268
  extra_data = bytes_to_hex(extra_bytes)
252
269
 
253
- result.path_length = path_len
270
+ result.path_length = path_hash_count
254
271
  result.path_hashes = path_hashes
255
272
  result.extra_type = extra_type
256
273
  result.extra_data = extra_data
257
274
  result.decrypted = {
258
- 'path_len': path_len,
275
+ 'path_len_byte': decryption_result.data['path_len_byte'],
276
+ 'path_hash_size': path_hash_size,
277
+ 'path_hash_count': path_hash_count,
259
278
  'path_hashes': path_hashes,
260
279
  'extra_type': extra_type,
261
280
  'extra_data': extra_data
@@ -20,7 +20,9 @@ class DecodedPacket:
20
20
  is_valid: bool,
21
21
  transport_codes: Optional[List[int]] = None,
22
22
  path: Optional[List[str]] = None,
23
- errors: Optional[List[str]] = None
23
+ errors: Optional[List[str]] = None,
24
+ path_byte_length: Optional[int] = None,
25
+ path_hash_size: Optional[int] = None,
24
26
  ):
25
27
  # Packet metadata
26
28
  self.message_hash = message_hash
@@ -30,10 +32,12 @@ class DecodedPacket:
30
32
  self.payload_type = payload_type
31
33
  self.payload_version = payload_version
32
34
 
33
- # Transport and routing
35
+ # Transport and routing (path_length = hop count; path_byte_length = total path bytes)
34
36
  self.transport_codes = transport_codes
35
37
  self.path_length = path_length
36
38
  self.path = path
39
+ self.path_byte_length = path_byte_length if path_byte_length is not None else path_length
40
+ self.path_hash_size = path_hash_size # 1, 2, or 3 bytes per hop
37
41
 
38
42
  # Payload data
39
43
  self.payload = payload
@@ -62,6 +66,10 @@ class DecodedPacket:
62
66
 
63
67
  if self.transport_codes:
64
68
  result['transportCodes'] = list(self.transport_codes)
69
+ if getattr(self, 'path_byte_length', None) is not None and self.path_byte_length != self.path_length:
70
+ result['pathByteLength'] = self.path_byte_length
71
+ if getattr(self, 'path_hash_size', None) is not None:
72
+ result['pathHashSize'] = self.path_hash_size
65
73
 
66
74
  if self.errors:
67
75
  result['errors'] = self.errors
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: meshcoredecoder
3
- Version: 0.3.0
3
+ Version: 0.3.1
4
4
  Summary: Complete Python implementation of the MeshCore Packet Decoder
5
5
  Home-page: https://github.com/chrisdavis2110/meshcore-decoder-py
6
6
  Author: Chris Davis
@@ -1,12 +1,12 @@
1
- cli.py,sha256=oMW7wy8UoVFiS6fcp5jZ8ZojbVm7ZrbLJcX0_CmVljo,51434
2
- index.py,sha256=dPlGhLOsOIhFtz5pCKOMJzBDD1lAEjI8NkZH5j-GeRw,2448
3
- meshcoredecoder/__init__.py,sha256=OqlWqWYHDEvulEe-sCfkgQB7Vyi3eT4niUFIbly74Zo,275
1
+ cli.py,sha256=9PGvHEnelR5kYiWBnB74sQNXkMAAd2WNsyeIsTasG68,51656
2
+ index.py,sha256=l0g0BBClksKbPCQmIVfPAkV_4Mo1M-mxJPRXueALQhM,2448
3
+ meshcoredecoder/__init__.py,sha256=3a9jhv9Infplw8D7Mp2uFKqFmZoo2N_WzBv-paIWMJc,275
4
4
  meshcoredecoder/crypto/__init__.py,sha256=00r884_WImNp5YOYfSKYtUaIj6gZdyJV0--xC_Y71Ok,236
5
- meshcoredecoder/crypto/channel_crypto.py,sha256=YKcFcD14ToqDhGfNUZwHEEW-kXKB8UP0VRuQWW75h7M,55512
6
- meshcoredecoder/crypto/ed25519_verifier.py,sha256=9DAx0gqnf9I7fPxfKU4G1y0GbJK1stCtTKpCX4foL5k,5057
5
+ meshcoredecoder/crypto/channel_crypto.py,sha256=qUQ4cM1JDFUPWENMgEdX5Ru4fUsoJc-HudkkRui5Qdo,56167
6
+ meshcoredecoder/crypto/ed25519_verifier.py,sha256=l6VXrkQo_NcrPZhpIORtIRH7eTyqgwuIAaW16BOcDmw,5339
7
7
  meshcoredecoder/crypto/key_manager.py,sha256=FXABZBd1B0kQwpyg7EX-pZDqxh5KVKnlB7A1FE3NQeU,5034
8
8
  meshcoredecoder/decoder/__init__.py,sha256=P_E5CQS1eXoVy59A1mAV9TD5XCS6FpQpc4RizhOZVrw,654
9
- meshcoredecoder/decoder/packet_decoder.py,sha256=qQA0wPI63fIjT8z95rrjkMBYfM6GmIuiAZaMRmvfGfM,25055
9
+ meshcoredecoder/decoder/packet_decoder.py,sha256=zgIjrwy7NI1WmOrJlhynMgmC9dCgBwd-zXM4-sO_TO0,28971
10
10
  meshcoredecoder/decoder/payload_decoders/__init__.py,sha256=Q3khEbL1w84VhfczwcMm8KVT9HCjBPb8RzmcoU-NtB8,885
11
11
  meshcoredecoder/decoder/payload_decoders/ack.py,sha256=Ao9M4b5e-aoNoq6pVAHkmcx1wJFrzsHLnSSjK84jcM8,3332
12
12
  meshcoredecoder/decoder/payload_decoders/advert.py,sha256=iWJLyiU1mZ_wbfLaS51KFPdDeLJ0iTwM3Nn-LrIpu8Q,12710
@@ -14,7 +14,7 @@ meshcoredecoder/decoder/payload_decoders/anon_request.py,sha256=MwCaHNcNZAMmc4C9
14
14
  meshcoredecoder/decoder/payload_decoders/control.py,sha256=wWWOGLzuyTMpIbBtpI3k4lL88Us-3Ca7byK76d1ifw8,8836
15
15
  meshcoredecoder/decoder/payload_decoders/group_data.py,sha256=llDm6lXDYqM_3udSz7lOtKCfHR39hUa5zivyfs21B_U,5435
16
16
  meshcoredecoder/decoder/payload_decoders/group_text.py,sha256=BhdF1ZYrMS_UH7-xRxeNHU1WvgNf2Buk9SxpDN0YYcQ,5526
17
- meshcoredecoder/decoder/payload_decoders/path.py,sha256=nsY4XzSPYBtMhMWDqLf2aDx0n3mg19qH8fo_sb04Nc4,13899
17
+ meshcoredecoder/decoder/payload_decoders/path.py,sha256=vgDDYkjUqSS94QqnAB7HYVlxJvtFUiM5moFA3diX7JQ,15576
18
18
  meshcoredecoder/decoder/payload_decoders/request.py,sha256=M4YMuVPNvSyyZjvIIpy1KaO5lFO9JyviKMRU9-52oag,19055
19
19
  meshcoredecoder/decoder/payload_decoders/response.py,sha256=jab9mYYNYJH4xSCn2Fo9eOECvnMiplUxgW7MKvcC8_M,61439
20
20
  meshcoredecoder/decoder/payload_decoders/text_message.py,sha256=JBwizJ58xRWB_JehPwLcatAP-K3WGag25zBaVrdZLu0,10622
@@ -22,15 +22,15 @@ meshcoredecoder/decoder/payload_decoders/trace.py,sha256=eN3E_5oidZzGdNsr--Phxtw
22
22
  meshcoredecoder/types/__init__.py,sha256=XReL92twDsQQf8GUxYbPEdZGlV8XweQCPT-43jn8IfA,640
23
23
  meshcoredecoder/types/crypto.py,sha256=o7C7IsiwMtJjzIUYRw548-AJmm898ucLDy1xYVukreE,1842
24
24
  meshcoredecoder/types/enums.py,sha256=nBnpiQ1iFxeMaQBpQKrz2UrJqgH3Pw_LXrzK-aUlPc0,2019
25
- meshcoredecoder/types/packet.py,sha256=LAMTHsFX3pWxP5M4gVsMRHEct2C2p36gpij_BuJofMw,3874
25
+ meshcoredecoder/types/packet.py,sha256=sQ6N1qPPlqveJK_gZ8elcSHNgTp9gSvcL55LfDjadho,4493
26
26
  meshcoredecoder/types/payloads.py,sha256=Vbhx0ayfZ8Xg3UaCv29Ysb6zHSEP6_rWn8oDCUKe1Ks,12778
27
27
  meshcoredecoder/utils/__init__.py,sha256=0_EpRPd97R2Cead_BTG9SDS6vVZV268u3XBkA-syOHk,739
28
28
  meshcoredecoder/utils/auth_token.py,sha256=gVVgHH_Am1k-cZxPbrTHCafvqdWSqlg9Dw-RRYaRI8Y,6973
29
29
  meshcoredecoder/utils/enum_names.py,sha256=Rb64MIF0ygzCkLMWCsMbSV3wAbExMVpoCWS3jdYR8Ms,2040
30
30
  meshcoredecoder/utils/hex.py,sha256=IjDuoeIAr7swv9Fa1NKstZTotTwmtufdi_psCjqVU5k,1136
31
- meshcoredecoder-0.3.0.dist-info/licenses/LICENSE,sha256=W4bNA8wxOTF7Wmcmi5UwjrrKnjT_Qua52Z5wQLPLfKM,1130
32
- meshcoredecoder-0.3.0.dist-info/METADATA,sha256=RSx1Bwxi2wxPwu7zYPgP-GGCec2WMrASxZKzRB6G6P8,34093
33
- meshcoredecoder-0.3.0.dist-info/WHEEL,sha256=YCfwYGOYMi5Jhw2fU4yNgwErybb2IX5PEwBKV4ZbdBo,91
34
- meshcoredecoder-0.3.0.dist-info/entry_points.txt,sha256=P8cgSHWETiDCc2jRCB95PuVyJDDeSq0gH-ufYVlqWDY,45
35
- meshcoredecoder-0.3.0.dist-info/top_level.txt,sha256=Rj9ZjVG2I6CEgpgF8I_QqUDp-vTQEdYm2KD93mIGkJM,26
36
- meshcoredecoder-0.3.0.dist-info/RECORD,,
31
+ meshcoredecoder-0.3.1.dist-info/licenses/LICENSE,sha256=W4bNA8wxOTF7Wmcmi5UwjrrKnjT_Qua52Z5wQLPLfKM,1130
32
+ meshcoredecoder-0.3.1.dist-info/METADATA,sha256=sM70INuRw1I5ZD53GX8ozArIf7V82mBW45AoX35pdFY,34093
33
+ meshcoredecoder-0.3.1.dist-info/WHEEL,sha256=YCfwYGOYMi5Jhw2fU4yNgwErybb2IX5PEwBKV4ZbdBo,91
34
+ meshcoredecoder-0.3.1.dist-info/entry_points.txt,sha256=P8cgSHWETiDCc2jRCB95PuVyJDDeSq0gH-ufYVlqWDY,45
35
+ meshcoredecoder-0.3.1.dist-info/top_level.txt,sha256=Rj9ZjVG2I6CEgpgF8I_QqUDp-vTQEdYm2KD93mIGkJM,26
36
+ meshcoredecoder-0.3.1.dist-info/RECORD,,