Updated CryptographyClientImpl to return a versioned keyId where applicable#47822
Updated CryptographyClientImpl to return a versioned keyId where applicable#47822
CryptographyClientImpl to return a versioned keyId where applicable#47822Conversation
There was a problem hiding this comment.
Pull request overview
This PR fixes Key Vault cryptography operation results to return the service-returned (versioned) key identifier (kid) instead of the client’s (potentially unversioned) keyId, enabling correct roundtrip scenarios when key rotation is used (e.g., sign→verify, wrap→unwrap).
Changes:
- Updated
EncryptResultto useKeyOperationResult.getKid()forkeyId. - Updated
DecryptResultto useKeyOperationResult.getKid()forkeyId. - Updated
SignResult,WrapResult, andUnwrapResultto useKeyOperationResult.getKid()forkeyId.
...ava/com/azure/security/keyvault/keys/cryptography/implementation/CryptographyClientImpl.java
Show resolved
Hide resolved
...ava/com/azure/security/keyvault/keys/cryptography/implementation/CryptographyClientImpl.java
Show resolved
Hide resolved
heaths
left a comment
There was a problem hiding this comment.
Given your changelog entry, this would seem right but without seeing any tests or knowing your code from memory, does getKid() return the full URI including version? Might be good to add a test or even an assertion to existing tests to make sure you do indeed have a version.
|
@heaths Added a few more check to our unit tests, including one for kid version |
| // Ensure the keyId includes the key version | ||
| String[] keyIdParts = keyId.split("/"); | ||
|
|
||
| assertTrue(keyIdParts.length >= 5 && !keyIdParts[4].isEmpty(), "keyId does not contain key version."); |
There was a problem hiding this comment.
Nit: this works, but don't you have an ID parser like we added to all other languages? Might be nice to use that for maintainability so it's obvious that the version is being checked: parse it into its components, and check a version local. Just a suggestion. Non-blocking.
There was a problem hiding this comment.
Oh, you're right! I forgot we had that. Thanks for reminding me :)
Description
Fixes: #43451
Fixed an issue where cryptographic operation results (
SignResult,EncryptResult,DecryptResult,WrapResult,UnwrapResult) returned a versionless key ID instead of the full versioned key ID returned by the service. This caused issues when attempting roundtrip scenarios, as callers couldn't determine which key version was used for the original operation (e.g. Sign -> Verify).All SDK Contribution checklist:
General Guidelines and Best Practices
Testing Guidelines