def encrypt()

in src/aws_encryption_sdk/internal/crypto/wrapping_keys.py [0:0]


    def encrypt(self, plaintext_data_key, encryption_context):
        """Encrypts a data key using a direct wrapping key.

        :param bytes plaintext_data_key: Data key to encrypt
        :param dict encryption_context: Encryption context to use in encryption
        :returns: Deserialized object containing encrypted key
        :rtype: aws_encryption_sdk.internal.structures.EncryptedData
        """
        if self.wrapping_algorithm.encryption_type is EncryptionType.ASYMMETRIC:
            if self.wrapping_key_type is EncryptionKeyType.PRIVATE:
                encrypted_key = self._wrapping_key.public_key().encrypt(
                    plaintext=plaintext_data_key, padding=self.wrapping_algorithm.padding
                )
            else:
                encrypted_key = self._wrapping_key.encrypt(
                    plaintext=plaintext_data_key, padding=self.wrapping_algorithm.padding
                )
            return EncryptedData(iv=None, ciphertext=encrypted_key, tag=None)
        serialized_encryption_context = serialize_encryption_context(encryption_context=encryption_context)
        iv = os.urandom(self.wrapping_algorithm.algorithm.iv_len)
        return encrypt(
            algorithm=self.wrapping_algorithm.algorithm,
            key=self._derived_wrapping_key,
            plaintext=plaintext_data_key,
            associated_data=serialized_encryption_context,
            iv=iv,
        )