|
28 | 28 | KeyUsage,
|
29 | 29 | ListKeysResponse,
|
30 | 30 | PublicKey,
|
| 31 | + SignRequest, |
| 32 | + SignResponse, |
31 | 33 | UpdateKeyRequest,
|
| 34 | + VerifyRequest, |
| 35 | + VerifyResponse, |
32 | 36 | )
|
33 | 37 | from .marshalling import (
|
34 | 38 | unmarshal_Key,
|
|
37 | 41 | unmarshal_EncryptResponse,
|
38 | 42 | unmarshal_ListKeysResponse,
|
39 | 43 | unmarshal_PublicKey,
|
| 44 | + unmarshal_SignResponse, |
| 45 | + unmarshal_VerifyResponse, |
40 | 46 | marshal_CreateKeyRequest,
|
41 | 47 | marshal_DecryptRequest,
|
42 | 48 | marshal_EncryptRequest,
|
43 | 49 | marshal_GenerateDataKeyRequest,
|
44 | 50 | marshal_ImportKeyMaterialRequest,
|
| 51 | + marshal_SignRequest, |
45 | 52 | marshal_UpdateKeyRequest,
|
| 53 | + marshal_VerifyRequest, |
46 | 54 | )
|
47 | 55 |
|
48 | 56 |
|
@@ -602,10 +610,10 @@ async def encrypt(
|
602 | 610 | """
|
603 | 611 | Encrypt a payload.
|
604 | 612 | Encrypt a payload using an existing key, specified by the `key_id` parameter. Only keys with a usage set to `symmetric_encryption` are supported by this method. The maximum payload size that can be encrypted is 64 KB of plaintext.
|
605 |
| - :param key_id: ID of the key to encrypt. |
| 613 | + :param key_id: The key must have an usage set to `symmetric_encryption` or `asymmetric_encryption`. |
606 | 614 | :param plaintext: Data size must be between 1 and 65535 bytes.
|
607 | 615 | :param region: Region to target. If none is passed will use default region from the config.
|
608 |
| - :param associated_data: Additional data which will not be encrypted, but authenticated and appended to the encrypted payload. |
| 616 | + :param associated_data: Additional data which will not be encrypted, but authenticated and appended to the encrypted payload. Only supported by keys with a usage set to `symmetric_encryption`. |
609 | 617 | :return: :class:`EncryptResponse <EncryptResponse>`
|
610 | 618 |
|
611 | 619 | Usage:
|
@@ -650,10 +658,10 @@ async def decrypt(
|
650 | 658 | """
|
651 | 659 | Decrypt an encrypted payload.
|
652 | 660 | Decrypt an encrypted payload using an existing key, specified by the `key_id` parameter. The maximum payload size that can be decrypted is equivalent to the encrypted output of 64 KB of data (around 131 KB).
|
653 |
| - :param key_id: ID of the key to decrypt. |
| 661 | + :param key_id: The key must have an usage set to `symmetric_encryption` or `asymmetric_encryption`. |
654 | 662 | :param ciphertext: Data size must be between 1 and 131071 bytes.
|
655 | 663 | :param region: Region to target. If none is passed will use default region from the config.
|
656 |
| - :param associated_data: The additional data must match the value passed in the encryption request. |
| 664 | + :param associated_data: The additional data must match the value passed in the encryption request. Only supported by keys with a usage set to `symmetric_encryption`. |
657 | 665 | :return: :class:`DecryptResponse <DecryptResponse>`
|
658 | 666 |
|
659 | 667 | Usage:
|
@@ -687,6 +695,100 @@ async def decrypt(
|
687 | 695 | self._throw_on_error(res)
|
688 | 696 | return unmarshal_DecryptResponse(res.json())
|
689 | 697 |
|
| 698 | + async def sign( |
| 699 | + self, |
| 700 | + *, |
| 701 | + key_id: str, |
| 702 | + digest: str, |
| 703 | + region: Optional[ScwRegion] = None, |
| 704 | + ) -> SignResponse: |
| 705 | + """ |
| 706 | + Sign a message digest. |
| 707 | + Use a given key to sign a message digest. The key must have its usage set to `asymmetric_signing`. The digest must be created using the same digest algorithm that is defined in the key's algorithm configuration. |
| 708 | + :param key_id: ID of the key to use for signing. |
| 709 | + :param digest: The digest must be generated using the same algorithm defined in the key’s algorithm settings. |
| 710 | + :param region: Region to target. If none is passed will use default region from the config. |
| 711 | + :return: :class:`SignResponse <SignResponse>` |
| 712 | +
|
| 713 | + Usage: |
| 714 | + :: |
| 715 | +
|
| 716 | + result = await api.sign( |
| 717 | + key_id="example", |
| 718 | + digest="example", |
| 719 | + ) |
| 720 | + """ |
| 721 | + |
| 722 | + param_region = validate_path_param( |
| 723 | + "region", region or self.client.default_region |
| 724 | + ) |
| 725 | + param_key_id = validate_path_param("key_id", key_id) |
| 726 | + |
| 727 | + res = self._request( |
| 728 | + "POST", |
| 729 | + f"/key-manager/v1alpha1/regions/{param_region}/keys/{param_key_id}/sign", |
| 730 | + body=marshal_SignRequest( |
| 731 | + SignRequest( |
| 732 | + key_id=key_id, |
| 733 | + digest=digest, |
| 734 | + region=region, |
| 735 | + ), |
| 736 | + self.client, |
| 737 | + ), |
| 738 | + ) |
| 739 | + |
| 740 | + self._throw_on_error(res) |
| 741 | + return unmarshal_SignResponse(res.json()) |
| 742 | + |
| 743 | + async def verify( |
| 744 | + self, |
| 745 | + *, |
| 746 | + key_id: str, |
| 747 | + digest: str, |
| 748 | + signature: str, |
| 749 | + region: Optional[ScwRegion] = None, |
| 750 | + ) -> VerifyResponse: |
| 751 | + """ |
| 752 | + Verify a message signature. |
| 753 | + Use a given key to verify a message signature against a message digest. The key must have its usage set to `asymmetric_signing`. The message digest must be generated using the same digest algorithm that is defined in the key's algorithm configuration. |
| 754 | + :param key_id: ID of the key to use for signature verification. |
| 755 | + :param digest: Must be generated using the same algorithm specified in the key’s configuration. |
| 756 | + :param signature: The message signature to verify. |
| 757 | + :param region: Region to target. If none is passed will use default region from the config. |
| 758 | + :return: :class:`VerifyResponse <VerifyResponse>` |
| 759 | +
|
| 760 | + Usage: |
| 761 | + :: |
| 762 | +
|
| 763 | + result = await api.verify( |
| 764 | + key_id="example", |
| 765 | + digest="example", |
| 766 | + signature="example", |
| 767 | + ) |
| 768 | + """ |
| 769 | + |
| 770 | + param_region = validate_path_param( |
| 771 | + "region", region or self.client.default_region |
| 772 | + ) |
| 773 | + param_key_id = validate_path_param("key_id", key_id) |
| 774 | + |
| 775 | + res = self._request( |
| 776 | + "POST", |
| 777 | + f"/key-manager/v1alpha1/regions/{param_region}/keys/{param_key_id}/verify", |
| 778 | + body=marshal_VerifyRequest( |
| 779 | + VerifyRequest( |
| 780 | + key_id=key_id, |
| 781 | + digest=digest, |
| 782 | + signature=signature, |
| 783 | + region=region, |
| 784 | + ), |
| 785 | + self.client, |
| 786 | + ), |
| 787 | + ) |
| 788 | + |
| 789 | + self._throw_on_error(res) |
| 790 | + return unmarshal_VerifyResponse(res.json()) |
| 791 | + |
690 | 792 | async def import_key_material(
|
691 | 793 | self,
|
692 | 794 | *,
|
|
0 commit comments