Skip to content

Commit 15c90bd

Browse files
committed
ClientEncryption::createDataKey() "keyMaterial" option
1 parent 571b7cb commit 15c90bd

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

src/MongoDB/ClientEncryption.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,17 @@ static mongoc_client_encryption_datakey_opts_t* phongo_clientencryption_datakey_
383383
}
384384
}
385385

386+
if (php_array_existsc(options, "keyMaterial")) {
387+
zval* keyMaterial = php_array_fetchc(options, "keyMaterial");
388+
389+
if (Z_TYPE_P(keyMaterial) != IS_OBJECT || !instanceof_function(Z_OBJCE_P(keyMaterial), php_phongo_binary_ce)) {
390+
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT, "Expected \"keyMaterial\" option to be %s, %s given", ZSTR_VAL(php_phongo_binary_ce->name), PHONGO_ZVAL_CLASS_OR_TYPE_NAME_P(keyMaterial));
391+
return false;
392+
}
393+
394+
mongoc_client_encryption_datakey_opts_set_keymaterial(opts, (uint8_t*) Z_BINARY_OBJ_P(keyMaterial)->data, Z_BINARY_OBJ_P(keyMaterial)->data_len);
395+
}
396+
386397
if (php_array_existsc(options, "masterKey")) {
387398
bson_t masterkey = BSON_INITIALIZER;
388399

tests/clientEncryption/clientEncryption-createDataKey_error-001.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
--TEST--
2-
MongoDB\Driver\ClientEncryption::createDataKey() with invalid keyAltNames
2+
MongoDB\Driver\ClientEncryption::createDataKey() with invalid keyAltNames option
33
--SKIPIF--
44
<?php require __DIR__ . "/../utils/basic-skipif.inc"; ?>
55
<?php skip_if_not_libmongocrypt(); ?>

0 commit comments

Comments
 (0)