Skip to content

Honor get_encoding in salt.utils.x509.load_pubkey - #70125

Open
Georgefifth wants to merge 1 commit into
saltstack:3008.xfrom
Georgefifth:fix-load-pubkey-get-encoding
Open

Honor get_encoding in salt.utils.x509.load_pubkey#70125
Georgefifth wants to merge 1 commit into
saltstack:3008.xfrom
Georgefifth:fix-load-pubkey-get-encoding

Conversation

@Georgefifth

Copy link
Copy Markdown

What does this PR do?

Makes salt.utils.x509.load_pubkey honor its get_encoding parameter, which it accepts but never used. With get_encoding=True it now returns a (public_key, encoding, None) tuple — the same contract as its sibling load_privkey in the same module — where encoding is None (already-loaded key object), "pem", or "der".

What issues does this PR fix or reference?

Fixes #70046

Previous Behavior

load_pubkey(pk, get_encoding=True) ignored the argument and returned the bare public key object.

New Behavior

load_pubkey(pk, get_encoding=True) returns (public_key, encoding, None). Default behavior (no argument) is unchanged. No in-tree caller passes get_encoding=True to load_pubkey, so nothing existing changes shape.

Merge requirements satisfied?

[NOTICE] Bug fixes or features added to Salt require tests.

Commits signed with GPG?

No

Verification

  • Reproduced on 3008.x: all three code paths (key object / PEM / DER) returned the bare key with get_encoding=True.
  • Added test_load_pubkey_returns_key_by_default and test_load_pubkey_get_encoding (instance/PEM/DER) to tests/pytests/unit/utils/test_x509.py. The new tests fail on the pre-fix code (3 failed) and pass with the fix.
  • Full tests/pytests/unit/utils/test_x509.py suite: 180 passed.
  • black --check and isort --check-only pass on the changed files.

load_pubkey accepted a get_encoding parameter but never used it,
always returning the bare public key object. Honor the argument the
same way its sibling load_privkey does: return a
(public_key, encoding, None) tuple when get_encoding=True.

Default behavior is unchanged, and no in-tree caller passes
get_encoding=True, so this cannot break existing users of the
function.

Fixes saltstack#70046
@Georgefifth
Georgefifth requested a review from a team as a code owner August 23, 2026 09:41
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