@@ -71,6 +71,27 @@ static PHP_METHOD(ClientEncryption, encrypt)
7171 phongo_clientencryption_encrypt (intern , value , return_value , options TSRMLS_CC );
7272} /* }}} */
7373
74+ /* {{{ proto mixed MongoDB\Driver\ClientEncryption::decrypt(MongoDB\BSON\BinaryInterface $value)
75+ Decrypts an encrypted value (BSON binary of subtype 6). Returns the original BSON value */
76+ static PHP_METHOD (ClientEncryption , decrypt )
77+ {
78+ zval * ciphertext ;
79+ zend_error_handling error_handling ;
80+ php_phongo_clientencryption_t * intern ;
81+
82+ intern = Z_CLIENTENCRYPTION_OBJ_P (getThis ());
83+ zend_replace_error_handling (EH_THROW , phongo_exception_from_phongo_domain (PHONGO_ERROR_INVALID_ARGUMENT ), & error_handling TSRMLS_CC );
84+
85+ if (zend_parse_parameters (ZEND_NUM_ARGS () TSRMLS_CC , "O" , & ciphertext , php_phongo_binary_interface_ce ) == FAILURE ) {
86+ zend_restore_error_handling (& error_handling TSRMLS_CC );
87+ return ;
88+ }
89+
90+ zend_restore_error_handling (& error_handling TSRMLS_CC );
91+
92+ phongo_clientencryption_decrypt (intern , ciphertext , return_value TSRMLS_CC );
93+ } /* }}} */
94+
7495ZEND_BEGIN_ARG_INFO_EX (ai_ClientEncryption_createDataKey , 0 , 0 , 1 )
7596 ZEND_ARG_INFO (0 , kmsProvider )
7697 ZEND_ARG_ARRAY_INFO (0 , options , 1 )
@@ -81,13 +102,18 @@ ZEND_BEGIN_ARG_INFO_EX(ai_ClientEncryption_encrypt, 0, 0, 1)
81102 ZEND_ARG_ARRAY_INFO (0 , options , 1 )
82103ZEND_END_ARG_INFO ()
83104
105+ ZEND_BEGIN_ARG_INFO_EX (ai_ClientEncryption_decrypt , 0 , 0 , 1 )
106+ ZEND_ARG_OBJ_INFO (0 , keyVaultClient , MongoDB \\BSON \\BinaryInterface , 0 )
107+ ZEND_END_ARG_INFO ()
108+
84109ZEND_BEGIN_ARG_INFO_EX (ai_ClientEncryption_void , 0 , 0 , 0 )
85110ZEND_END_ARG_INFO ()
86111
87112static zend_function_entry php_phongo_clientencryption_me [] = {
88113 /* clang-format off */
89114 PHP_ME (ClientEncryption , createDataKey , ai_ClientEncryption_createDataKey , ZEND_ACC_PUBLIC | ZEND_ACC_FINAL )
90115 PHP_ME (ClientEncryption , encrypt , ai_ClientEncryption_encrypt , ZEND_ACC_PUBLIC | ZEND_ACC_FINAL )
116+ PHP_ME (ClientEncryption , decrypt , ai_ClientEncryption_decrypt , ZEND_ACC_PUBLIC | ZEND_ACC_FINAL )
91117 ZEND_NAMED_ME (__construct , PHP_FN (MongoDB_disabled___construct ), ai_ClientEncryption_void , ZEND_ACC_PRIVATE | ZEND_ACC_FINAL )
92118 ZEND_NAMED_ME (__wakeup , PHP_FN (MongoDB_disabled___wakeup ), ai_ClientEncryption_void , ZEND_ACC_PUBLIC | ZEND_ACC_FINAL )
93119 PHP_FE_END
0 commit comments