-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Python: Fix type annotations in KMS client methods #7520
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
`kms_client.encrypt` returns type `bytes`. Updated method signatures for encrypt and decrypt. The "Plaintext" returned from `kms_client.decrypt` is also `bytes`, but it should be decoded to `str` to match the parameter type of the encrypt method.
@@ -75,7 +75,7 @@ def decrypt(self, key_id: str, cipher_text: str) -> bytes: | |||
try: | |||
return self.kms_client.decrypt(KeyId=key_id, CiphertextBlob=cipher_text)[ | |||
"Plaintext" | |||
] | |||
].decode() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi, we don't need use the decode() method here as that is being taken care of on line 201. Having the method returns an error. The other changes look good to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I removed the redundant call to decode() on line 201. The call to decode() should be inside the decrypt() function, making its signature the inverse of encrypt(). Since encode() is called from encrypt(), it makes sense that decode() would be called in decrypt().
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi, we don't need use the decode() method here as that is being taken care of on line 201. Having the method returns an error. The other changes look good to me.
I removed the redundant call to decode() on line 201. The call to decode() should be inside the decrypt() function, making its signature the inverse of encrypt(). Since encode() is called from encrypt(), it makes sense that decode() would be called in decrypt().
Updated encrypt/decrypt method signatures to properly handle bytes return types from KMS client operations.
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.