Skip to content

Commit 4dd6f79

Browse files
authored
Python: Fix type annotations in KMS client methods (#7520)
* Update key_encryption.py
1 parent f084f15 commit 4dd6f79

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

python/example_code/kms/key_encryption.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def from_client(cls) -> "KeyEncrypt":
3535
# snippet-end:[python.example_code.kms.KeyEncrypt.decl]
3636

3737
# snippet-start:[python.example_code.kms.Encrypt]
38-
def encrypt(self, key_id: str, text: str) -> str:
38+
def encrypt(self, key_id: str, text: str) -> bytes:
3939
"""
4040
Encrypts text by using the specified key.
4141
@@ -64,7 +64,7 @@ def encrypt(self, key_id: str, text: str) -> str:
6464
# snippet-end:[python.example_code.kms.Encrypt]
6565

6666
# snippet-start:[python.example_code.kms.Decrypt]
67-
def decrypt(self, key_id: str, cipher_text: str) -> bytes:
67+
def decrypt(self, key_id: str, cipher_text: bytes) -> str:
6868
"""
6969
Decrypts text previously encrypted with a key.
7070
@@ -75,7 +75,7 @@ def decrypt(self, key_id: str, cipher_text: str) -> bytes:
7575
try:
7676
return self.kms_client.decrypt(KeyId=key_id, CiphertextBlob=cipher_text)[
7777
"Plaintext"
78-
]
78+
].decode()
7979
except ClientError as err:
8080
logger.error(
8181
"Couldn't decrypt your ciphertext. Here's why: %s",
@@ -198,7 +198,7 @@ def key_encryption(kms_client):
198198
answer = input("Ready to decrypt your ciphertext (y/n)? ")
199199
if answer.lower() == "y":
200200
decrypted_text = key_encrypt.decrypt(key_id, cipher_text)
201-
print(f"Your plaintext is {decrypted_text.decode()}")
201+
print(f"Your plaintext is {decrypted_text}")
202202
print("-" * 88)
203203
key_encrypt.re_encrypt(key_id, cipher_text)
204204
else:

0 commit comments

Comments
 (0)