Commit 9ed387b1 authored by yiwenshao's avatar yiwenshao

able to encrypt and decrypt in layers

parent c8039eec
...@@ -56,20 +56,47 @@ static void init(){ ...@@ -56,20 +56,47 @@ static void init(){
globalConn = new Connect(ci.server, ci.user, ci.passwd, ci.port); globalConn = new Connect(ci.server, ci.user, ci.passwd, ci.port);
} }
static
Item *
encrypt_item_layers_raw(const Item &i, uint64_t IV, std::vector<std::unique_ptr<EncLayer> > &enc_layers) {
const Item *enc = &i;
Item *new_enc = NULL;
for (const auto &it : enc_layers) {
new_enc = it->encrypt(*enc, IV);
assert(new_enc);
enc = new_enc;
}
assert(new_enc && new_enc != &i);
return new_enc;
}
static Item *
decrypt_item_layers_raw(const Item &i, uint64_t IV, std::vector<std::unique_ptr<EncLayer> > &enc_layers) {
const Item *dec = &i;
Item *out_i = NULL;
for (auto it = enc_layers.rbegin(); it != enc_layers.rend(); ++it) {
out_i = (*it)->decrypt(*dec, IV);
assert(out_i);
dec = out_i;
}
assert(out_i && out_i != &i);
return out_i;
}
int int
main() { main() {
init(); init();
create_embedded_thd(0); create_embedded_thd(0);
Create_field *f = new Create_field; Create_field *f = new Create_field;
f->sql_type = MYSQL_TYPE_LONG; f->sql_type = MYSQL_TYPE_LONG;
std::unique_ptr<EncLayer> el(EncLayerFactory::encLayer(oDET,SECLEVEL::RND,*f,"HEHE")); std::unique_ptr<EncLayer> el(EncLayerFactory::encLayer(oDET,SECLEVEL::RND,*f,"HEHE"));
auto levels = CURRENT_NUM_LAYOUT[oDET]; auto levels = CURRENT_NUM_LAYOUT[oDET];
std::vector<std::unique_ptr<EncLayer> > layers; std::vector<std::unique_ptr<EncLayer> > layers;
const Create_field * newcf = f; const Create_field * newcf = f;
onion o = oDET; onion o = oDET;
for (auto l: levels) { for (auto l: levels) {
...@@ -80,8 +107,15 @@ main() { ...@@ -80,8 +107,15 @@ main() {
newcf = el->newCreateField(oldcf); newcf = el->newCreateField(oldcf);
layers.push_back(std::move(el)); layers.push_back(std::move(el));
} }
Item * in = NULL;
encrypt_item_layers_raw(*in,0,layers);
decrypt_item_layers_raw(*in,0,layers);
(void)el; (void)el;
(void)f; (void)f;
//Then we should encrypt and decrypt.
return 0; return 0;
} }
......
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