diff --git a/docs/tutorial/client-side-encryption.txt b/docs/tutorial/client-side-encryption.txt index efff2e7d4..a8c02699a 100644 --- a/docs/tutorial/client-side-encryption.txt +++ b/docs/tutorial/client-side-encryption.txt @@ -39,7 +39,7 @@ more than one encryption key or create them dynamically. use MongoDB\Client; use MongoDB\Driver\ClientEncryption; - $localKey = new Binary('', Binary::TYPE_GENERIC); + $localKey = new Binary(''); $clientEncryptionOpts = [ 'keyVaultNamespace' => 'encryption.__keyVault', @@ -78,7 +78,7 @@ side. use MongoDB\Client; use MongoDB\Driver\ClientEncryption; - $localKey = new Binary('', Binary::TYPE_GENERIC); + $localKey = new Binary(''); $encryptionOpts = [ 'keyVaultNamespace' => 'encryption.__keyVault', 'kmsProviders' => [ @@ -142,7 +142,7 @@ encrypted fields. use MongoDB\Client; use MongoDB\Driver\ClientEncryption; - $localKey = new Binary('', Binary::TYPE_GENERIC); + $localKey = new Binary(''); $client = new Client(); @@ -197,7 +197,7 @@ encrypts and decrypts values in the document. use MongoDB\Client; use MongoDB\Driver\ClientEncryption; - $localKey = new Binary('', Binary::TYPE_GENERIC); + $localKey = new Binary(''); $clientEncryptionOpts = [ 'keyVaultNamespace' => 'encryption.__keyVault', @@ -250,7 +250,7 @@ To use an alternate name when referencing an encryption key, use the use MongoDB\Client; use MongoDB\Driver\ClientEncryption; - $localKey = new Binary('', Binary::TYPE_GENERIC); + $localKey = new Binary(''); $clientEncryptionOpts = [ 'keyVaultNamespace' => 'encryption.__keyVault', @@ -300,7 +300,7 @@ query on the ``encryptedIndexed`` field. use MongoDB\BSON\Binary; use MongoDB\Client; - $localKey = new Binary('', Binary::TYPE_GENERIC); + $localKey = new Binary(''); $encryptionOpts = [ 'keyVaultNamespace' => 'encryption.__keyVault', diff --git a/psalm-baseline.xml b/psalm-baseline.xml index c7aecbc8b..22cc4833f 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -131,6 +131,9 @@ + + new Binary($data) + hash_update @@ -292,13 +295,12 @@ $this->options['typeMap'] $this->options['typeMap'] - + $cmdOptions['maxAwaitTimeMS'] $cmd[$option] $cmd['hint'] $cmd['readConcern'] $options[$option] - $options['writeConcern'] isDefault diff --git a/src/GridFS/WritableStream.php b/src/GridFS/WritableStream.php index 981ce5312..ff30927de 100644 --- a/src/GridFS/WritableStream.php +++ b/src/GridFS/WritableStream.php @@ -283,7 +283,7 @@ private function insertChunkFromBuffer(): void $chunk = [ 'files_id' => $this->file['_id'], 'n' => $this->chunkOffset, - 'data' => new Binary($data, Binary::TYPE_GENERIC), + 'data' => new Binary($data), ]; if (! $this->disableMD5 && $this->hashCtx) { diff --git a/tests/DocumentationExamplesTest.php b/tests/DocumentationExamplesTest.php index af336f19a..a49204c8b 100644 --- a/tests/DocumentationExamplesTest.php +++ b/tests/DocumentationExamplesTest.php @@ -1830,7 +1830,7 @@ public function testQueryableEncryption(): void * default to the same client. */ $clientEncryption = $client->createClientEncryption([ 'keyVaultNamespace' => 'keyvault.datakeys', - 'kmsProviders' => ['local' => ['key' => new Binary(base64_decode(ClientSideEncryptionSpecTest::LOCAL_MASTERKEY), 0)]], + 'kmsProviders' => ['local' => ['key' => new Binary(base64_decode(ClientSideEncryptionSpecTest::LOCAL_MASTERKEY))]], ]); // Create two data keys, one for each encrypted field @@ -1839,7 +1839,7 @@ public function testQueryableEncryption(): void $autoEncryptionOpts = [ 'keyVaultNamespace' => 'keyvault.datakeys', - 'kmsProviders' => ['local' => ['key' => new Binary(base64_decode(ClientSideEncryptionSpecTest::LOCAL_MASTERKEY), 0)]], + 'kmsProviders' => ['local' => ['key' => new Binary(base64_decode(ClientSideEncryptionSpecTest::LOCAL_MASTERKEY))]], 'encryptedFieldsMap' => [ $namespace => [ 'fields' => [ diff --git a/tests/GridFS/BucketFunctionalTest.php b/tests/GridFS/BucketFunctionalTest.php index 8e4f6518f..13f466475 100644 --- a/tests/GridFS/BucketFunctionalTest.php +++ b/tests/GridFS/BucketFunctionalTest.php @@ -170,7 +170,7 @@ public function testDownloadingFileWithUnexpectedChunkSize(): void $this->chunksCollection->updateOne( ['files_id' => $id, 'n' => 0], - ['$set' => ['data' => new Binary('fooba', Binary::TYPE_GENERIC)]] + ['$set' => ['data' => new Binary('fooba')]] ); $this->expectException(CorruptFileException::class); diff --git a/tests/GridFS/ReadableStreamFunctionalTest.php b/tests/GridFS/ReadableStreamFunctionalTest.php index beabb7569..95f21c840 100644 --- a/tests/GridFS/ReadableStreamFunctionalTest.php +++ b/tests/GridFS/ReadableStreamFunctionalTest.php @@ -34,13 +34,13 @@ public function setUp(): void ]); $this->chunksCollection->insertMany([ - ['_id' => 1, 'files_id' => 'length-0-with-empty-chunk', 'n' => 0, 'data' => new Binary('', Binary::TYPE_GENERIC)], - ['_id' => 2, 'files_id' => 'length-2', 'n' => 0, 'data' => new Binary('ab', Binary::TYPE_GENERIC)], - ['_id' => 3, 'files_id' => 'length-8', 'n' => 0, 'data' => new Binary('abcd', Binary::TYPE_GENERIC)], - ['_id' => 4, 'files_id' => 'length-8', 'n' => 1, 'data' => new Binary('efgh', Binary::TYPE_GENERIC)], - ['_id' => 5, 'files_id' => 'length-10', 'n' => 0, 'data' => new Binary('abcd', Binary::TYPE_GENERIC)], - ['_id' => 6, 'files_id' => 'length-10', 'n' => 1, 'data' => new Binary('efgh', Binary::TYPE_GENERIC)], - ['_id' => 7, 'files_id' => 'length-10', 'n' => 2, 'data' => new Binary('ij', Binary::TYPE_GENERIC)], + ['_id' => 1, 'files_id' => 'length-0-with-empty-chunk', 'n' => 0, 'data' => new Binary('')], + ['_id' => 2, 'files_id' => 'length-2', 'n' => 0, 'data' => new Binary('ab')], + ['_id' => 3, 'files_id' => 'length-8', 'n' => 0, 'data' => new Binary('abcd')], + ['_id' => 4, 'files_id' => 'length-8', 'n' => 1, 'data' => new Binary('efgh')], + ['_id' => 5, 'files_id' => 'length-10', 'n' => 0, 'data' => new Binary('abcd')], + ['_id' => 6, 'files_id' => 'length-10', 'n' => 1, 'data' => new Binary('efgh')], + ['_id' => 7, 'files_id' => 'length-10', 'n' => 2, 'data' => new Binary('ij')], ]); } @@ -161,7 +161,7 @@ public function testReadBytesWithUnexpectedChunkSize(): void { $this->chunksCollection->updateOne( ['files_id' => 'length-10', 'n' => 2], - ['$set' => ['data' => new Binary('i', Binary::TYPE_GENERIC)]] + ['$set' => ['data' => new Binary('i')]] ); $fileDocument = $this->collectionWrapper->findFileById('length-10'); diff --git a/tests/GridFS/StreamWrapperFunctionalTest.php b/tests/GridFS/StreamWrapperFunctionalTest.php index 792338d36..3c5e140bf 100644 --- a/tests/GridFS/StreamWrapperFunctionalTest.php +++ b/tests/GridFS/StreamWrapperFunctionalTest.php @@ -30,9 +30,9 @@ public function setUp(): void ]); $this->chunksCollection->insertMany([ - ['_id' => 1, 'files_id' => 'length-10', 'n' => 0, 'data' => new Binary('abcd', Binary::TYPE_GENERIC)], - ['_id' => 2, 'files_id' => 'length-10', 'n' => 1, 'data' => new Binary('efgh', Binary::TYPE_GENERIC)], - ['_id' => 3, 'files_id' => 'length-10', 'n' => 2, 'data' => new Binary('ij', Binary::TYPE_GENERIC)], + ['_id' => 1, 'files_id' => 'length-10', 'n' => 0, 'data' => new Binary('abcd')], + ['_id' => 2, 'files_id' => 'length-10', 'n' => 1, 'data' => new Binary('efgh')], + ['_id' => 3, 'files_id' => 'length-10', 'n' => 2, 'data' => new Binary('ij')], ]); } diff --git a/tests/Operation/CreateEncryptedCollectionFunctionalTest.php b/tests/Operation/CreateEncryptedCollectionFunctionalTest.php index b80258915..fe3d5fa22 100644 --- a/tests/Operation/CreateEncryptedCollectionFunctionalTest.php +++ b/tests/Operation/CreateEncryptedCollectionFunctionalTest.php @@ -50,7 +50,7 @@ public function setUp(): void $this->clientEncryption = $client->createClientEncryption([ 'keyVaultNamespace' => 'keyvault.datakeys', 'kmsProviders' => [ - 'local' => ['key' => new Binary(base64_decode(self::LOCAL_MASTERKEY), 0)], + 'local' => ['key' => new Binary(base64_decode(self::LOCAL_MASTERKEY))], ], ]); } diff --git a/tests/SpecTests/ClientSideEncryption/Prose21_AutomaticDataEncryptionKeysTest.php b/tests/SpecTests/ClientSideEncryption/Prose21_AutomaticDataEncryptionKeysTest.php index ea99ca1c2..aecdfeb38 100644 --- a/tests/SpecTests/ClientSideEncryption/Prose21_AutomaticDataEncryptionKeysTest.php +++ b/tests/SpecTests/ClientSideEncryption/Prose21_AutomaticDataEncryptionKeysTest.php @@ -51,7 +51,7 @@ public function setUp(): void 'keyVaultNamespace' => 'keyvault.datakeys', 'kmsProviders' => [ 'aws' => self::getAWSCredentials(), - 'local' => ['key' => new Binary(base64_decode(self::LOCAL_MASTERKEY), 0)], + 'local' => ['key' => new Binary(base64_decode(self::LOCAL_MASTERKEY))], ], ]); } diff --git a/tests/SpecTests/ClientSideEncryption/Prose22_RangeExplicitEncryptionTest.php b/tests/SpecTests/ClientSideEncryption/Prose22_RangeExplicitEncryptionTest.php index 46de1c49f..14c465981 100644 --- a/tests/SpecTests/ClientSideEncryption/Prose22_RangeExplicitEncryptionTest.php +++ b/tests/SpecTests/ClientSideEncryption/Prose22_RangeExplicitEncryptionTest.php @@ -53,12 +53,12 @@ public function setUp(): void $this->clientEncryption = $client->createClientEncryption([ 'keyVaultNamespace' => 'keyvault.datakeys', - 'kmsProviders' => ['local' => ['key' => new Binary(base64_decode(self::LOCAL_MASTERKEY), 0)]], + 'kmsProviders' => ['local' => ['key' => new Binary(base64_decode(self::LOCAL_MASTERKEY))]], ]); $autoEncryptionOpts = [ 'keyVaultNamespace' => 'keyvault.datakeys', - 'kmsProviders' => ['local' => ['key' => new Binary(base64_decode(self::LOCAL_MASTERKEY), 0)]], + 'kmsProviders' => ['local' => ['key' => new Binary(base64_decode(self::LOCAL_MASTERKEY))]], 'bypassQueryAnalysis' => true, ]; diff --git a/tests/SpecTests/ClientSideEncryptionSpecTest.php b/tests/SpecTests/ClientSideEncryptionSpecTest.php index 6d39a83e1..b2d866496 100644 --- a/tests/SpecTests/ClientSideEncryptionSpecTest.php +++ b/tests/SpecTests/ClientSideEncryptionSpecTest.php @@ -283,7 +283,7 @@ public function testDataKeyAndDoubleEncryption(string $providerName, $masterKey) 'aws' => Context::getAWSCredentials(), 'azure' => Context::getAzureCredentials(), 'gcp' => Context::getGCPCredentials(), - 'local' => ['key' => new Binary(base64_decode(self::LOCAL_MASTERKEY), 0)], + 'local' => ['key' => new Binary(base64_decode(self::LOCAL_MASTERKEY))], 'kmip' => ['endpoint' => Context::getKmipEndpoint()], ], 'tlsOptions' => [ @@ -421,7 +421,7 @@ public function testExternalKeyVault($withExternalKeyVault): void $encryptionOpts = [ 'keyVaultNamespace' => 'keyvault.datakeys', 'kmsProviders' => [ - 'local' => ['key' => new Binary(base64_decode(self::LOCAL_MASTERKEY), 0)], + 'local' => ['key' => new Binary(base64_decode(self::LOCAL_MASTERKEY))], ], ]; @@ -570,7 +570,7 @@ public function testBSONSizeLimitsAndBatchSplitting(Closure $test): void $autoEncryptionOpts = [ 'keyVaultNamespace' => 'keyvault.datakeys', 'kmsProviders' => [ - 'local' => ['key' => new Binary(base64_decode(self::LOCAL_MASTERKEY), 0)], + 'local' => ['key' => new Binary(base64_decode(self::LOCAL_MASTERKEY))], ], 'keyVaultClient' => $client, ]; @@ -599,7 +599,7 @@ public function testViewsAreProhibited(): void $autoEncryptionOpts = [ 'keyVaultNamespace' => 'keyvault.datakeys', 'kmsProviders' => [ - 'local' => ['key' => new Binary(base64_decode(self::LOCAL_MASTERKEY), 0)], + 'local' => ['key' => new Binary(base64_decode(self::LOCAL_MASTERKEY))], ], ]; @@ -648,7 +648,7 @@ public function testCorpus($schemaMap = true): void 'aws' => Context::getAWSCredentials(), 'azure' => Context::getAzureCredentials(), 'gcp' => Context::getGCPCredentials(), - 'local' => ['key' => new Binary(base64_decode(self::LOCAL_MASTERKEY), 0)], + 'local' => ['key' => new Binary(base64_decode(self::LOCAL_MASTERKEY))], 'kmip' => ['endpoint' => Context::getKmipEndpoint()], ], 'tlsOptions' => [ @@ -904,7 +904,7 @@ public function testBypassSpawningMongocryptdViaLoadingSharedLibrary(): void $autoEncryptionOpts = [ 'keyVaultNamespace' => 'keyvault.datakeys', 'kmsProviders' => [ - 'local' => ['key' => new Binary(base64_decode(self::LOCAL_MASTERKEY), 0)], + 'local' => ['key' => new Binary(base64_decode(self::LOCAL_MASTERKEY))], ], 'schemaMap' => [ 'db.coll' => $this->decodeJson(file_get_contents(__DIR__ . '/client-side-encryption/external/external-schema.json')), @@ -946,7 +946,7 @@ public function testBypassSpawningMongocryptdViaBypassSpawn(): void $autoEncryptionOpts = [ 'keyVaultNamespace' => 'keyvault.datakeys', 'kmsProviders' => [ - 'local' => ['key' => new Binary(base64_decode(self::LOCAL_MASTERKEY), 0)], + 'local' => ['key' => new Binary(base64_decode(self::LOCAL_MASTERKEY))], ], 'schemaMap' => [ 'db.coll' => $this->decodeJson(file_get_contents(__DIR__ . '/client-side-encryption/external/external-schema.json')), @@ -986,7 +986,7 @@ public function testBypassSpawningMongocryptdViaBypassAutoEncryption(): void $autoEncryptionOpts = [ 'keyVaultNamespace' => 'keyvault.datakeys', 'kmsProviders' => [ - 'local' => ['key' => new Binary(base64_decode(self::LOCAL_MASTERKEY), 0)], + 'local' => ['key' => new Binary(base64_decode(self::LOCAL_MASTERKEY))], ], 'bypassAutoEncryption' => true, 'extraOptions' => [ @@ -1020,7 +1020,7 @@ public function testBypassSpawningMongocryptdViaBypassQueryAnalysis(): void $autoEncryptionOpts = [ 'keyVaultNamespace' => 'keyvault.datakeys', 'kmsProviders' => [ - 'local' => ['key' => new Binary(base64_decode(self::LOCAL_MASTERKEY), 0)], + 'local' => ['key' => new Binary(base64_decode(self::LOCAL_MASTERKEY))], ], 'bypassQueryAnalysis' => true, 'extraOptions' => [ @@ -1350,12 +1350,12 @@ public function testExplicitEncryption(Closure $test): void $clientEncryption = new ClientEncryption([ 'keyVaultClient' => $keyVaultClient->getManager(), 'keyVaultNamespace' => 'keyvault.datakeys', - 'kmsProviders' => ['local' => ['key' => new Binary(base64_decode(self::LOCAL_MASTERKEY), 0)]], + 'kmsProviders' => ['local' => ['key' => new Binary(base64_decode(self::LOCAL_MASTERKEY))]], ]); $autoEncryptionOpts = [ 'keyVaultNamespace' => 'keyvault.datakeys', - 'kmsProviders' => ['local' => ['key' => new Binary(base64_decode(self::LOCAL_MASTERKEY), 0)]], + 'kmsProviders' => ['local' => ['key' => new Binary(base64_decode(self::LOCAL_MASTERKEY))]], 'bypassQueryAnalysis' => true, ]; @@ -1519,7 +1519,7 @@ public function testUniqueIndexOnKeyAltNames(Closure $test): void $clientEncryption = new ClientEncryption([ 'keyVaultClient' => $client->getManager(), 'keyVaultNamespace' => 'keyvault.datakeys', - 'kmsProviders' => ['local' => ['key' => new Binary(base64_decode(self::LOCAL_MASTERKEY), 0)]], + 'kmsProviders' => ['local' => ['key' => new Binary(base64_decode(self::LOCAL_MASTERKEY))]], ]); $clientEncryption->createDataKey('local', ['keyAltNames' => ['def']]); @@ -1598,7 +1598,7 @@ public function testDecryptionEvents(Closure $test): void $clientEncryption = new ClientEncryption([ 'keyVaultClient' => $setupClient->getManager(), 'keyVaultNamespace' => 'keyvault.datakeys', - 'kmsProviders' => ['local' => ['key' => new Binary(base64_decode(self::LOCAL_MASTERKEY), 0)]], + 'kmsProviders' => ['local' => ['key' => new Binary(base64_decode(self::LOCAL_MASTERKEY))]], ]); $keyId = $clientEncryption->createDataKey('local'); @@ -1613,7 +1613,7 @@ public function testDecryptionEvents(Closure $test): void $autoEncryptionOpts = [ 'keyVaultNamespace' => 'keyvault.datakeys', - 'kmsProviders' => ['local' => ['key' => new Binary(base64_decode(self::LOCAL_MASTERKEY), 0)]], + 'kmsProviders' => ['local' => ['key' => new Binary(base64_decode(self::LOCAL_MASTERKEY))]], ]; $encryptedClient = static::createTestClient(null, ['retryReads' => false], ['autoEncryption' => $autoEncryptionOpts]); @@ -1800,7 +1800,7 @@ public function testRewrapManyDataKey(string $srcProvider, string $dstProvider): 'azure' => Context::getAzureCredentials(), 'gcp' => Context::getGCPCredentials(), 'kmip' => ['endpoint' => Context::getKmipEndpoint()], - 'local' => ['key' => new Binary(base64_decode(self::LOCAL_MASTERKEY), 0)], + 'local' => ['key' => new Binary(base64_decode(self::LOCAL_MASTERKEY))], ], 'tlsOptions' => [ 'kmip' => Context::getKmsTlsOptions(), @@ -1900,7 +1900,7 @@ private function encryptCorpusValue(string $fieldName, stdClass $data, ClientEnc switch ($data->identifier) { case 'id': - $encryptionOptions['keyId'] = new Binary(base64_decode($keyId), 4); + $encryptionOptions['keyId'] = new Binary(base64_decode($keyId), Binary::TYPE_UUID); break; case 'altname': diff --git a/tests/SpecTests/DocumentsMatchConstraintTest.php b/tests/SpecTests/DocumentsMatchConstraintTest.php index c14f001c6..e71efc5a8 100644 --- a/tests/SpecTests/DocumentsMatchConstraintTest.php +++ b/tests/SpecTests/DocumentsMatchConstraintTest.php @@ -93,7 +93,7 @@ public function provideBSONTypes() 'string' => ['string', 'foo'], 'object' => ['object', new BSONDocument()], 'array' => ['array', ['foo']], - 'binData' => ['binData', new Binary('', 0)], + 'binData' => ['binData', new Binary('')], 'undefined' => ['undefined', $undefined], 'objectId' => ['objectId', new ObjectId()], 'bool' => ['bool', true], diff --git a/tests/UnifiedSpecTests/Constraint/IsBsonTypeTest.php b/tests/UnifiedSpecTests/Constraint/IsBsonTypeTest.php index d14b09e60..59b40f70d 100644 --- a/tests/UnifiedSpecTests/Constraint/IsBsonTypeTest.php +++ b/tests/UnifiedSpecTests/Constraint/IsBsonTypeTest.php @@ -51,7 +51,7 @@ public function provideTypes() // Note: additional tests in testTypeArray 'array(indexed array)' => ['array', ['foo']], 'array(BSONArray)' => ['array', new BSONArray()], - 'binData' => ['binData', new Binary('', 0)], + 'binData' => ['binData', new Binary('')], 'undefined' => ['undefined', $undefined], 'objectId' => ['objectId', new ObjectId()], 'bool' => ['bool', true],