<commit_before>//
//  main.cpp
//  sophos
//
//  Created by <NAME> on 29/03/2016.
//  Copyright © 2016 <NAME>. All rights reserved.
//

#include <iostream>
#include <fstream>

#include "sophos_core.hpp"

using namespace sse::sophos;
using namespace std;

int main(int argc, const char * argv[]) {
    
    string client_sk_path = "tdp_sk.key";
    string client_master_key_path = "derivation_master.key";
    string server_pk_path = "tdp_pk.key";
    
    
    ifstream client_sk_in(client_sk_path.c_str());
    ifstream client_master_key_in(client_master_key_path.c_str());
    ifstream server_pk_in(server_pk_path.c_str());
    
    if((client_sk_in.good() != client_master_key_in.good()) || (client_sk_in.good() != server_pk_in.good()))
    {
        client_sk_in.close();
        client_master_key_in.close();
        server_pk_in.close();

        throw std::runtime_error("All streams are not in the same state");
    }
    
    if (client_sk_in.good() == true) {
        // the files exist
        cout << "Restart client and server" << endl;
        
        stringstream client_sk_buf, client_master_key_buf, server_pk_buf;

        client_sk_buf << client_sk_in.rdbuf();
        client_master_key_buf << client_master_key_in.rdbuf();
        server_pk_buf << server_pk_in.rdbuf();

        SophosClient client("client.sav", client_sk_buf.str(), client_master_key_buf.str());
        
        SophosServer server("server.dat", server_pk_buf.str());

        SearchRequest s_req;
        std::list<index_type> res;
        string key;

        key = "toto";
        s_req = client.search_request(key);
        res = server.search(s_req);
        
        cout << "Search " << key << ". Results: [";
        for(index_type i : res){
            cout << i << ", ";
        }
        cout << "]" << endl;

    }else{
        cout << "Create new client-server instances" << endl;
        
        SophosClient client("client.sav",1000);

        SophosServer server("server.dat", 1000, client.public_key());
        
        // write keys to files
        ofstream client_sk_out(client_sk_path.c_str());
        client_sk_out << client.private_key();
        client_sk_out.close();
        
        ofstream client_master_key_out(client_master_key_path.c_str());
        client_master_key_out << client.master_derivation_key();
        client_master_key_out.close();

        ofstream server_pk_out(server_pk_path.c_str());
        server_pk_out << server.public_key();
        server_pk_out.close();

        
        
        SearchRequest s_req;
        UpdateRequest u_req;
        std::list<index_type> res;
        string key;

        u_req = client.update_request("toto", 0);
        server.update(u_req);

    //    u_req = client.update_request("titi", 0);
    //    server.update(u_req);
        
        u_req = client.update_request("toto", 1);
        server.update(u_req);
        
    //    u_req = client.update_request("tata", 0);
    //    server.update(u_req);

        key = "toto";
        s_req = client.search_request(key);
        res = server.search(s_req);
        
        cout << "Search " << key << ". Results: [";
        for(index_type i : res){
            cout << i << ", ";
        }
        cout << "]" << endl;

    //    key = "titi";
    //    s_req = client.search_request(key);
    //    res = server.search(s_req);
    //    
    //    cout << "Search " << key << ". Results: [";
    //    for(index_type i : res){
    //        cout << i << ", ";
    //    }
    //    cout << "]" << endl;
    //
    //    key = "tata";
    //    s_req = client.search_request(key);
    //    res = server.search(s_req);
    //    
    //    cout << "Search " << key << ". Results: [";
    //    for(index_type i : res){
    //        cout << i << ", ";
    //    }
    //    cout << "]" << endl;

    }
    
    client_sk_in.close();
    client_master_key_in.close();
    server_pk_in.close();
    
    return 0;
}<commit_msg>Quick cleanup of the main.cpp file<commit_after>//
//  main.cpp
//  sophos
//
//  Created by <NAME> on 29/03/2016.
//  Copyright © 2016 <NAME>. All rights reserved.
//

#include <iostream>
#include <fstream>
#include <memory>

#include "sophos_core.hpp"

using namespace sse::sophos;
using namespace std;

int main(int argc, const char * argv[]) {
    
    string client_sk_path = "tdp_sk.key";
    string client_master_key_path = "derivation_master.key";
    string server_pk_path = "tdp_pk.key";
    
    
    ifstream client_sk_in(client_sk_path.c_str());
    ifstream client_master_key_in(client_master_key_path.c_str());
    ifstream server_pk_in(server_pk_path.c_str());
    
    unique_ptr<SophosClient> client;
    unique_ptr<SophosServer> server;
    
    SearchRequest s_req;
    UpdateRequest u_req;
    std::list<index_type> res;
    string key;

    if((client_sk_in.good() != client_master_key_in.good()) || (client_sk_in.good() != server_pk_in.good()))
    {
        client_sk_in.close();
        client_master_key_in.close();
        server_pk_in.close();

        throw std::runtime_error("All streams are not in the same state");
    }
    
    if (client_sk_in.good() == true) {
        // the files exist
        cout << "Restart client and server" << endl;
        
        stringstream client_sk_buf, client_master_key_buf, server_pk_buf;

        client_sk_buf << client_sk_in.rdbuf();
        client_master_key_buf << client_master_key_in.rdbuf();
        server_pk_buf << server_pk_in.rdbuf();

        client.reset(new  SophosClient("client.sav", client_sk_buf.str(), client_master_key_buf.str()));
        
        server.reset(new SophosServer("server.dat", server_pk_buf.str()));
        
        SearchRequest s_req;
        std::list<index_type> res;
        string key;

    }else{
        cout << "Create new client-server instances" << endl;
        
        client.reset(new SophosClient("client.sav",1000));

        server.reset(new SophosServer("server.dat", 1000, client->public_key()));
        
        // write keys to files
        ofstream client_sk_out(client_sk_path.c_str());
        client_sk_out << client->private_key();
        client_sk_out.close();
        
        ofstream client_master_key_out(client_master_key_path.c_str());
        client_master_key_out << client->master_derivation_key();
        client_master_key_out.close();

        ofstream server_pk_out(server_pk_path.c_str());
        server_pk_out << server->public_key();
        server_pk_out.close();

        u_req = client->update_request("toto", 0);
        server->update(u_req);
        
        u_req = client->update_request("titi", 0);
        server->update(u_req);
        
        u_req = client->update_request("toto", 1);
        server->update(u_req);
        
        u_req = client->update_request("tata", 0);
        server->update(u_req);
        

    }
    

    
    key = "toto";
    s_req = client->search_request(key);
    res = server->search(s_req);

    cout << "Search " << key << ". Results: [";
    for(index_type i : res){
        cout << i << ", ";
    }
    cout << "]" << endl;

    key = "titi";
    s_req = client->search_request(key);
    res = server->search(s_req);
    
    cout << "Search " << key << ". Results: [";
    for(index_type i : res){
        cout << i << ", ";
    }
    cout << "]" << endl;

    key = "tata";
    s_req = client->search_request(key);
    res = server->search(s_req);
    
    cout << "Search " << key << ". Results: [";
    for(index_type i : res){
        cout << i << ", ";
    }
    cout << "]" << endl;

    
    client_sk_in.close();
    client_master_key_in.close();
    server_pk_in.close();
    
    return 0;
}
{'fraction_non_alphanumeric': 0.14589308996088657, 'fraction_numerical': 0.00651890482398957, 'mean_word_length': 2.2600934976625586, 'pattern_counts': {'":': 0, '<': 156, '<?xml version=': 0, '>': 36, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '28607', 'n_tokens_mistral': 2631, 'n_tokens_neox': 2555, 'n_words': 450}