Skip to content

Pymavlink signing: use bytes for secret_key in Python 3 examples - #795

Open
ARYA-mgc wants to merge 1 commit into
mavlink:masterfrom
ARYA-mgc:fix/pymavlink-signing-secret-key-bytes
Open

ARYA-mgc wants to merge 1 commit into
mavlink:masterfrom
ARYA-mgc:fix/pymavlink-signing-secret-key-bytes

Conversation

@ARYA-mgc

@ARYA-mgc ARYA-mgc commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

Description

In en/mavgen_python/message_signing.md, the code snippets for setting up MAVLink 2 message signing initialized secret_key using:

secret_key = chr(42) * 32

In Python 2, chr() returned an 8-bit str (bytes). In Python 3 (supported Python 3.5+), chr(42) * 32 produces a Unicode string (str).

When secret_key is passed to mav.signing.secret_key or the_connection.setup_signing(secret_key), the encoder calls sign_packet() (and validator calls check_signature()), which invokes:

h = hashlib.new("sha256")
h.update(mav.signing.secret_key)

Because hashlib.sha256().update() strictly requires a bytes-like object, passing a str immediately raises:

TypeError: Strings must be encoded before hashing

Changes

  • Updated both code examples in en/mavgen_python/message_signing.md (lines 29 and 88) to initialize secret_key as a bytes object:
    secret_key = b'*' * 32

Verification

  • Tested hashing in Python 3: verified hashlib.new("sha256").update(b'*' * 32) completes without error.
  • Validated formatting and spellcheck with prettier --check, markdownlint-cli2, and cspell (0 issues).

@ARYA-mgc
ARYA-mgc force-pushed the fix/pymavlink-signing-secret-key-bytes branch from a4ebc0a to adb8085 Compare October 23, 2026 10:44
@ARYA-mgc

ARYA-mgc commented Nov 2, 2026

Copy link
Copy Markdown
Contributor Author

Hii! @hamishwillee, could you please review the changes when you get a chance?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant