test column encryption unsupported types

This commit is contained in:
v-kaywon 2017-11-07 11:45:13 -08:00
parent ce23b38557
commit b695cc1655
4 changed files with 25 additions and 13 deletions

View file

@ -127,10 +127,11 @@ class ColumnMeta
{
public $dataType; //a string that includes the size of the type if necessary (e.g., decimal(10,5))
public $colName; //column name
public $encType; //randomized or deterministic; default is deterministic
public $options; //a string that is null by default (e.g. NOT NULL Identity (1,1) )
public $encType; //randomized or deterministic; default is deterministic
public $forceEncrypt; //force encryption on a datatype no supported by Column Encrypton
public function __construct($dataType, $colName = null, $options = null, $encType = "deterministic")
public function __construct($dataType, $colName = null, $options = null, $encType = "deterministic", $forceEncrypt = false)
{
if (is_null($colName)) {
$this->colName = getDefaultColName($dataType);
@ -138,8 +139,9 @@ class ColumnMeta
$this->colName = $colName;
}
$this->dataType = $dataType;
$this->encType = $encType;
$this->options = $options;
$this->encType = $encType;
$this->forceEncrypt = $forceEncrypt;
}
/**
* @return string column definition for creating a table
@ -150,7 +152,7 @@ class ColumnMeta
$append = " ";
// an identity column is not encrypted because a select query with identity column as the where clause is often run and the user want to have to bind parameter every time
if (isColEncrypted() && stripos($this->options, "identity") === false) {
if (isColEncrypted() && $this->isEncryptableType() && stripos($this->options, "identity") === false) {
$cekName = getCekName();
if (stripos($this->dataType, "char") !== false) {
$append .= "COLLATE Latin1_General_BIN2 ";
@ -161,6 +163,19 @@ class ColumnMeta
$colDef = "[" . $this->colName . "] " . $this->dataType . $append;
return $colDef;
}
/**
* @return bool if the datatype for this column is encryptable
*/
public function isEncryptableType()
{
$unsupportedTypes = array("money", "smallmoney", "image", "ntext", "text", "xml", "sql_variant");
if (in_array(strtolower($this->dataType), $unsupportedTypes) && !$this->forceEncrypt) {
return false;
} else {
return true;
}
}
}

View file

@ -17,7 +17,8 @@ try {
// create table
$tbname = getTableName();
$colMetaArr = array( new columnMeta($dataType, "c_det"), new columnMeta($dataType, "c_rand", null, "randomized"));
$colMetaArr = array(new columnMeta($dataType, "c_det", null, "deterministic", true),
new columnMeta($dataType, "c_rand", null, "randomized", true));
createTable($conn, $tbname, $colMetaArr);
// insert a row

View file

@ -17,7 +17,8 @@ try {
// create table
$tbname = getTableName();
$colMetaArr = array(new ColumnMeta($dataType, "c_det"), new ColumnMeta($dataType, "c_rand", null, "randomized"));
$colMetaArr = array(new ColumnMeta($dataType, "c_det", null, "deterministic", true),
new ColumnMeta($dataType, "c_rand", null, "randomized", true));
createTable($conn, $tbname, $colMetaArr);
// test each PDO::PARAM_ type

View file

@ -43,13 +43,8 @@ function fetchBoth($conn, $tbname)
// 8
$meta = $stmt->getColumnMeta(7);
if (isColEncrypted()) {
$xmlType = "nvarchar";
} else {
$xmlType = "xml";
}
if ($meta["sqlsrv:decl_type"] != $xmlType) {
echo "Wrong column metadata was retrieved for a $xmlType column.\n";
if ($meta["sqlsrv:decl_type"] != "xml") {
echo "Wrong column metadata was retrieved for a xml column.\n";
}
unset($meta["sqlsrv:decl_type"]);
var_dump($meta);