Commit 3be49778 authored by yiwenshao's avatar yiwenshao

able to decrypt

parent aa56f06e
......@@ -98,6 +98,56 @@ load_columns(std::vector<FieldMetaTrans> &fmts,std::string db,std::string table)
}
}
struct batch{
vector<string> field_names;
vector<int> field_types;
vector<int> field_lengths;
};
batch ggbt;
/*should choose the right decryption onion*/
static
std::shared_ptr<ReturnMeta> getReturnMeta(std::vector<FieldMeta*> fms,
std::vector<FieldMetaTrans> &tfds){
assert(fms.size()==tfds.size());
std::shared_ptr<ReturnMeta> myReturnMeta = std::make_shared<ReturnMeta>();
int pos=0;
//construct OLK
for(auto i=0u;i<tfds.size();i++){
//the order is DET,OPE,ASHE,AGG. other onions are not decryptable!!
int index = getDecryptionOnionIndex(tfds[i]);
if(index==-1) assert(0);
onion o = tfds[i].getChoosenOnionO()[index];
*glog<<"choosenDecryptionOnion: "<<TypeText<onion>::toText(o)<<"\n";
SECLEVEL l = tfds[i].getOriginalFieldMeta()->getOnionMeta(o)->getSecLevel();
FieldMeta *k = tfds[i].getOriginalFieldMeta();
OLK curOLK(o,l,k);
bool use_salt = false;
if(needsSalt(curOLK))
use_salt = true;
addToReturn(myReturnMeta.get(),pos++,curOLK,use_salt,k->getFieldName());
if(use_salt)
addSaltToReturn(myReturnMeta.get(),pos++);
//used to record choosen field lengths, onion names , and field types
ggbt.field_types.push_back(tfds[i].getChoosenFieldTypes()[index]);
ggbt.field_names.push_back(tfds[i].getChoosenOnionName()[index]);
ggbt.field_lengths.push_back(tfds[i].getChoosenFieldLengths()[index]);
if(use_salt){
ggbt.field_types.push_back(tfds[i].getSaltType());
ggbt.field_names.push_back(tfds[i].getSaltName());
ggbt.field_lengths.push_back(tfds[i].getSaltLength());
}
}
return myReturnMeta;
}
static ResType load_files_new(std::string db, std::string table){
timer t_load_files;
......@@ -114,19 +164,13 @@ static ResType load_files_new(std::string db, std::string table){
}
mf.show();
load_columns(fmts,db,table);
// initGfb(fmts,db,table);//load global columns
/*
std::shared_ptr<ReturnMeta> rm = getReturnMeta(fms,res);
*glog<<"getReturnMeta: "<<
std::to_string(t_load_files.lap()/1000000u)<<
"##"<<std::to_string(time(NULL))<<"\n";
std::shared_ptr<ReturnMeta> rm = getReturnMeta(fms,fmts);
UNUSED(rm);
vector<string> field_names = ggbt.field_names;
vector<int> field_types = ggbt.field_types;
vector<int> field_lengths = ggbt.field_lengths;
//why do we need this??
create_embedded_thd(0);
rawMySQLReturnValue resraw;
vector<vector<string>> res_field;
......@@ -158,18 +202,17 @@ static ResType load_files_new(std::string db, std::string table){
for(unsigned int i=0;i<field_types.size();++i){
resraw.fieldTypes.push_back(static_cast<enum_field_types>(field_types[i]));
}
ResType rawtorestype = rawMySQLReturnValue_to_ResType(false, &resraw);
UNUSED(rawtorestype);
auto finalresults = decryptResults(rawtorestype,*rm);
rawMySQLReturnValue MM;
ResTypeToRawMySQLReturnValue(MM,finalresults);
return finalresults;
*glog<<"transform: "<<
std::to_string(t_load_files.lap()/1000000u)<<
"##"<<std::to_string(time(NULL))<<"\n";
/*
auto finalresults = decryptResults(rawtorestype,*rm);
*glog<<"descryption: "<<
std::to_string(t_load_files.lap()/1000000u)<<
"##"<<std::to_string(time(NULL))<<"\n";
return finalresults;
*/
return ResType(false, 0, 0);
}
......
......@@ -132,6 +132,24 @@ itemNullVector(unsigned int count)
return out;
}
void
ResTypeToRawMySQLReturnValue(rawMySQLReturnValue& inraw,ResType& inres){
inraw.fieldNames = inres.names;
inraw.fieldTypes = inres.types;
for(auto &row : inres.rows){
std::vector<std::string> insertRow;
for(unsigned int i=0u;i<row.size();i++){
if(IS_NUM(inres.types[i])){
insertRow.push_back(std::to_string(row[i]->val_uint()));
}else{
insertRow.push_back(ItemToString(*row[i]));
}
}
inraw.rowValues.push_back(insertRow);
}
}
ResType rawMySQLReturnValue_to_ResType(bool isNULL,rawMySQLReturnValue *inRow,int in_last_insert_id){
std::vector<std::string> names;
std::vector<enum_field_types> types;
......
......@@ -270,4 +270,5 @@ void
loadFileNoEscapeLimitCount(std::string filename,
std::vector<std::string> &res,int limit);
void
ResTypeToRawMySQLReturnValue(rawMySQLReturnValue& inraw,ResType& inres);
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