Commit da991a28 authored by Casualet's avatar Casualet

add comments

parent b14ff9e7
......@@ -27,8 +27,10 @@ public:
private:
const bool is_salt;
//比如对于select 1+1, 这里的field_called就是"1+1"
//for select 1+1, the field_called value is "1+1", so is the feild is not salt, this is the plaintext name
//of the field.
const std::string field_called;
//if the field is not salt, olk.key should get the fieldmeta
const OLK olk; // if !olk.key, field is not encrypted
const int salt_pos; // position of salt of this field in
// the query results, or -1 if such
......
......@@ -120,9 +120,6 @@ public:
};
class HOMFactory : public LayerFactory {
public:
static std::unique_ptr<EncLayer>
......@@ -177,7 +174,6 @@ EncLayerFactory::encLayer(onion o, SECLEVEL sl, const Create_field &cf,
case SECLEVEL::PLAINVAL: {
return std::unique_ptr<EncLayer>(new PlainText());
}
default:{}
}
FAIL_TextMessageError("unknown or unimplemented security level");
......@@ -186,8 +182,7 @@ EncLayerFactory::encLayer(onion o, SECLEVEL sl, const Create_field &cf,
//recover from the database using lambda.
std::unique_ptr<EncLayer>
EncLayerFactory::deserializeLayer(unsigned int id,
const std::string &serial)
{
const std::string &serial){
assert(id);
const SerialLayer li = serial_unpack(serial);
......@@ -266,8 +261,7 @@ static Create_field*
integerCreateFieldHelper(const Create_field &f,
enum enum_field_types type,
const std::string &anonname = "",
CHARSET_INFO * const charset = NULL)
{
CHARSET_INFO * const charset = NULL){
return lowLevelcreateFieldHelper(f, 0, type, anonname, charset);
}
......@@ -749,24 +743,20 @@ public:
std::string doSerialize() const {return rawkey;}
DET_str(unsigned int id, const std::string &serial);
virtual SECLEVEL level() const {return SECLEVEL::DET;}
std::string name() const {return "DET_str";}
Create_field * newCreateField(const Create_field &cf,
const std::string &anonname = "")
const;
Item *encrypt(const Item &ptext, uint64_t IV) const;
Item *decrypt(const Item &ctext, uint64_t IV) const;
Item * decryptUDF(Item * const col, Item * const ivcol = NULL) const;
protected:
const std::string rawkey;
static const int key_bytes = 16;
static const bool do_pad = true;
const std::unique_ptr<const AES_KEY> enckey;
const std::unique_ptr<const AES_KEY> deckey;
};
......
......@@ -492,7 +492,6 @@ main() {
std::getline(std::cin,curQuery);
std::unique_ptr<SchemaInfo> schema = myLoadSchemaInfo();
processSchemaInfo(*schema);
continue;
}
std::cout<<GREEN_BEGIN<<"curQuery: "<<
......
......@@ -107,7 +107,7 @@ class InsertHandler : public DMLHandler {
std::vector<FieldMeta *> fmVec;
std::vector<Item *> implicit_defaults;
//对于insert, 有可能出现指定field list的情况.
//For insert, we can choose to specify field list or omit it.
if (lex->field_list.head()) {
auto it = List_iterator<Item>(lex->field_list);
List<Item> newList;
......
......@@ -198,6 +198,7 @@ ResType MygetResTypeFromLuaTable(bool isNULL,rawReturnValue *inRow = NULL,int in
std::vector<std::string> names;
std::vector<enum_field_types> types;
std::vector<std::vector<Item *> > rows;
//return NULL restype
if(isNULL){
return ResType(true,0,0,std::move(names),
......@@ -209,7 +210,6 @@ ResType MygetResTypeFromLuaTable(bool isNULL,rawReturnValue *inRow = NULL,int in
for(auto inTypes:inRow->fieldTypes){
types.push_back(static_cast<enum_field_types>(inTypes));
}
for(auto inRows:inRow->rowValues) {
std::vector<Item *> curTempRow = itemNullVector(types.size());
for(int i=0;i< (int)(inRows.size());i++){
......@@ -332,14 +332,17 @@ static std::unique_ptr<SchemaInfo> myLoadSchemaInfo() {
static void
addToReturn(ReturnMeta *const rm, int pos, const OLK &constr,
bool has_salt, const std::string &name) {
const bool test = static_cast<unsigned int>(pos) == rm->rfmeta.size();
TEST_TextMessageError(test, "ReturnMeta has badly ordered"
" ReturnFields!");
const int salt_pos = has_salt ? pos + 1 : -1;
std::pair<int, ReturnField>
pair(pos, ReturnField(false, name, constr, salt_pos));
rm->rfmeta.insert(pair);
}
......@@ -379,14 +382,20 @@ decrypt_item_layers(const Item &i, const FieldMeta *const fm, onion o,
return out_i;
}
/*
structure of return field.
map<int,returnField>, int is the index of names
returnField, represent a field, if the field is not salt, then fieldCalled is the plaintex name
*/
static
ResType decryptResults(const ResType &dbres, const ReturnMeta &rmeta) {
ResType decryptResults(const ResType &dbres, const ReturnMeta &rmeta) {
//num of rows
const unsigned int rows = dbres.rows.size();
//num of names, to be decrypted
const unsigned int cols = dbres.names.size();
std::vector<std::string> dec_names;
for (auto it = dbres.names.begin();
it != dbres.names.end(); it++) {
for (auto it = dbres.names.begin();it != dbres.names.end(); it++){
const unsigned int index = it - dbres.names.begin();
//fetch rfmeta based on index
const ReturnField &rf = rmeta.rfmeta.at(index);
......@@ -397,12 +406,16 @@ ResType decryptResults(const ResType &dbres, const ReturnMeta &rmeta) {
}
}
const unsigned int real_cols = dec_names.size();
std::vector<std::vector<Item *> > dec_rows(rows);
//real cols depends on plain text names.
for (unsigned int i = 0; i < rows; i++) {
dec_rows[i] = std::vector<Item *>(real_cols);
}
//
unsigned int col_index = 0;
for (unsigned int c = 0; c < cols; c++) {
......@@ -410,14 +423,16 @@ ResType decryptResults(const ResType &dbres, const ReturnMeta &rmeta) {
if (rf.getIsSalt()) {
continue;
}
//the key is in fieldMeta
FieldMeta *const fm = rf.getOLK().key;
for (unsigned int r = 0; r < rows; r++) {
//
if (!fm || dbres.rows[r][c]->is_null()) {
dec_rows[r][col_index] = dbres.rows[r][c];
} else {
uint64_t salt = 0;
const int salt_pos = rf.getSaltPosition();
//read salt from remote datab for descrypting.
......@@ -427,10 +442,11 @@ ResType decryptResults(const ResType &dbres, const ReturnMeta &rmeta) {
assert_s(!salt_item->null_value, "salt item is null");
salt = salt_item->value;
}
//peel onion.
//specify fieldMeta, onion, and salt should be able to decrpyt
//peel onion
dec_rows[r][col_index] =
decrypt_item_layers(*dbres.rows[r][c],
fm, rf.getOLK().o, salt);
decrypt_item_layers(*dbres.rows[r][c],fm,rf.getOLK().o,salt);
}
}
col_index++;
......@@ -442,22 +458,9 @@ ResType decryptResults(const ResType &dbres, const ReturnMeta &rmeta) {
std::move(dec_rows));
}
/*static void split(const std::string &s, char delim, std::vector<std::string> &elems) {
std::stringstream ss;
ss.str(s);
std::string item;
while (std::getline(ss, item, delim)) {
elems.push_back(item);
}
}
static std::vector<std::string> split(const std::string &s, char delim) {
std::vector<std::string> elems;
split(s, delim, elems);
return elems;
}*/
//get returnMeta
//get returnMeta
//for each filed, we have a fieldmeta. we can chosse one onion under that field to construct a return meta.
//in fact, a returnmeta can contain many fields.
static
std::shared_ptr<ReturnMeta> getReturnMeta(std::vector<FieldMeta*> fms, std::vector<transField> &tfds){
assert(fms.size()==tfds.size());
......@@ -467,7 +470,7 @@ std::shared_ptr<ReturnMeta> getReturnMeta(std::vector<FieldMeta*> fms, std::vect
for(auto i=0u;i<tfds.size();i++){
OLK curOLK(tfds[i].onions[tfds[i].onionIndex],
tfds[i].originalOm[tfds[i].onionIndex]->getSecLevel(),tfds[i].originalFm);
addToReturn(myReturnMeta.get(),pos++,curOLK,true,tfds[i].originalFm->getFieldName());
addToReturn(myReturnMeta.get(),pos++,curOLK,true,tfds[i].originalFm->getFieldName());
addSaltToReturn(myReturnMeta.get(),pos++);
}
return myReturnMeta;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment