Honor get_encoding in salt.utils.x509.load_pubkey - #70125
Open
Georgefifth wants to merge 1 commit into
Open
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
Makes
salt.utils.x509.load_pubkeyhonor itsget_encodingparameter, which it accepts but never used. Withget_encoding=Trueit now returns a(public_key, encoding, None)tuple — the same contract as its siblingload_privkeyin the same module — whereencodingisNone(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 passesget_encoding=Truetoload_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
3008.x: all three code paths (key object / PEM / DER) returned the bare key withget_encoding=True.test_load_pubkey_returns_key_by_defaultandtest_load_pubkey_get_encoding(instance/PEM/DER) totests/pytests/unit/utils/test_x509.py. The new tests fail on the pre-fix code (3 failed) and pass with the fix.tests/pytests/unit/utils/test_x509.pysuite: 180 passed.black --checkandisort --check-onlypass on the changed files.