git.fiddlerwoaroof.com
dual_control_tool.cc
7d075ab4
 /* Copyright (C) CJ Affiliate
  *
  * You may use, distribute and modify this code under  the
  * terms of the  GNU General Public License  version 2  or
  * later.
  *
  * You should have received a copy of the license with this
  * file. If not, you will find a copy in the "LICENSE" file
  * at https://github.com/cjdev/dual-control.
  */
 
e21fc4bc
 #include <string>
 #include <iostream>
 
66796de1
 #include "installer.h"
f2a91ef8
 #include "generator.h"
 #include "sys_stdlib.h"
 #include "user.h"
 #include "sys_unistd.h"
 #include "sys_pwd.h"
9b03a29b
 #include "sys_time.h"
f2a91ef8
 #include "token.h"
d87655b0
 #include "system.h"
f2a91ef8
 #include "sys_fstream.h"
1ffe9b79
 #include "random_source.h"
f2a91ef8
 
23c0bd4d
 namespace
 {
 class system init_system()
 {
     stdlib stdlib (stdlib::get());
     sys_time time (sys_time::get());
     class system system (stdlib, time);
     return system;
 }
c7bdd0eb
 
23c0bd4d
 installer init_installer()
 {
     fstreams fstreams (fstreams::create());
     pwd pwd (pwd::create());
     unistd unistd (unistd::create());
     stdlib stdlib (stdlib::get());
6a23c017
     sys_time time (sys_time::get());
9b03a29b
     int code_digits = 6;
e57144d3
     totp_generator generator = totp_generator (time, code_digits);
a120158c
     random_source rand (random_source::create (fstreams));
b6eb15ba
     directory directory (directory::create (unistd, pwd));
     tokens tokens (tokens::create (fstreams, generator, rand));
8c62e61c
     installer installer (installer::create (tokens, unistd, directory,
                                             generator));
f2a91ef8
 
23c0bd4d
     return installer;
 }
f2a91ef8
 }
e21fc4bc
 
7d075ab4
 int main (int argc, char *argv[])
 {
23c0bd4d
     class system system (init_system());
     installer tool (init_installer());
c7bdd0eb
     auto generated_key_and_sample_token = tool.install_key();
4a6aca25
     std::cout << "         Key: " << generated_key_and_sample_token.first
               << std::endl
               << "Sample Token: " << generated_key_and_sample_token.second
               << std::endl
               << "Run again to get another token from the same key."
               << std::endl;
e21fc4bc
 }
a120158c