From c41fef25aceddc2b97de792e0120054bbf5a43c1 Mon Sep 17 00:00:00 2001 From: Timm Friebe Date: Wed, 1 Oct 2025 21:40:40 +0200 Subject: [PATCH] Add support for encrypted values Step 1 for full queryable encryption, see #18 --- src/main/php/com/mongodb/Encrypted.class.php | 16 ++++++++++++++++ src/main/php/com/mongodb/io/BSON.class.php | 5 ++++- .../php/com/mongodb/unittest/BSONTest.class.php | 3 ++- 3 files changed, 22 insertions(+), 2 deletions(-) create mode 100755 src/main/php/com/mongodb/Encrypted.class.php diff --git a/src/main/php/com/mongodb/Encrypted.class.php b/src/main/php/com/mongodb/Encrypted.class.php new file mode 100755 index 0000000..247723a --- /dev/null +++ b/src/main/php/com/mongodb/Encrypted.class.php @@ -0,0 +1,16 @@ +ciphertext= (string)$ciphertext; + } + + /** @return int */ + public function length() { return strlen($this->ciphertext); } + + /** @return string */ + public function ciphertext() { return $this->ciphertext; } + +} \ No newline at end of file diff --git a/src/main/php/com/mongodb/io/BSON.class.php b/src/main/php/com/mongodb/io/BSON.class.php index ff5147a..9e78b65 100755 --- a/src/main/php/com/mongodb/io/BSON.class.php +++ b/src/main/php/com/mongodb/io/BSON.class.php @@ -1,7 +1,7 @@ length(), 6).$value->ciphertext(); } else if ($value instanceof Traversable || $value instanceof StdClass) { return "\x03".$name."\x00".$this->sections($value); } else if (is_string($value)) { @@ -132,6 +134,7 @@ public function value($name, $bytes, &$offset) { switch ($binary['subtype']) { case 0: case 2: return $value; case 3: case 4: return new UUID($value); + case 6: return new Encrypted($value); default: throw new FormatException('Cannot handle binary subtype '.$binary['subtype']); } } else if ("\x07" === $kind) { // ObjectId diff --git a/src/test/php/com/mongodb/unittest/BSONTest.class.php b/src/test/php/com/mongodb/unittest/BSONTest.class.php index 9d881e0..461b9eb 100755 --- a/src/test/php/com/mongodb/unittest/BSONTest.class.php +++ b/src/test/php/com/mongodb/unittest/BSONTest.class.php @@ -1,7 +1,7 @@