Skip to content

Commit

Permalink
Merge pull request #28 from dreamfactorysoftware/dev-encryption
Browse files Browse the repository at this point in the history
Add support for encrypted fields
  • Loading branch information
Anas authored Sep 12, 2023
2 parents 79abdb5 + b170e66 commit 54b1549
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 6 deletions.
20 changes: 20 additions & 0 deletions src/Enums/BinaryDataTypes.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

namespace DreamFactory\Core\MongoDb\Enums;

/**
* Binary data types for MongoDB
* https://www.mongodb.com/docs/manual/reference/bson-types/#binary-data
*/
class BinaryDataTypes
{
const GENERIC = 0;
const FUNCTION_DATA = 1;
const BINARY_OLD = 2;
const UUID_OLD = 3;
const UUID = 4;
const MD5 = 5;
const ENCRYPTED_BSON_VALUE = 6;
const COMPRESSED_TIME_SERIES_DATA = 7;
const CUSTOM_DATA = 128;
}
13 changes: 7 additions & 6 deletions src/Resources/Table.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use DreamFactory\Core\Exceptions\InternalServerErrorException;
use DreamFactory\Core\Exceptions\NotFoundException;
use DreamFactory\Core\Exceptions\RestException;
use DreamFactory\Core\MongoDb\Enums\BinaryDataTypes;
use DreamFactory\Core\MongoDb\Services\MongoDb;
use DreamFactory\Core\Database\Resources\BaseNoSqlDbTableResource;
use DreamFactory\Core\Utility\DataFormatter;
Expand Down Expand Up @@ -437,13 +438,13 @@ protected static function buildFilterArray($filter, $params = null)
}
}

return [$field => new Regex($value, '')];
return [$field => new Regex($value, 'i')];
} elseif (DbComparisonOperators::CONTAINS === $sqlOp) {
return [$field => new Regex($value, '')];
return [$field => new Regex($value, 'i')];
} elseif (DbComparisonOperators::STARTS_WITH === $sqlOp) {
return [$field => new Regex('^' . $value, '')];
return [$field => new Regex('^' . $value, 'i')];
} elseif (DbComparisonOperators::ENDS_WITH === $sqlOp) {
return [$field => new Regex($value . '$', '')];
return [$field => new Regex($value . '$', 'i')];
}
}

Expand Down Expand Up @@ -679,7 +680,7 @@ protected static function fromMongoObjects($record)
}
$data = $data->toDateTime();
$data = ['$date' => $data->format($cfgFormat)];
} elseif ($data instanceof Binary) {
} elseif ($data instanceof Binary && $data->getType() === BinaryDataTypes::GENERIC) {
$data = $data->getData();
}
}
Expand Down Expand Up @@ -1381,4 +1382,4 @@ protected function runQuery($table, $criteria, $extras)

return $data;
}
}
}

0 comments on commit 54b1549

Please sign in to comment.