git.fiddlerwoaroof.com
token.h
7684972a
 /* 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.
  */
 
7699d7ec
 #ifndef _TOKEN_H
 #define _TOKEN_H
b5e563ba
 
f757e35b
 #include <string>
 #include <memory>
af3a4cd4
 #include <functional>
b5e563ba
 
f757e35b
 #include "user.h"
215ea751
 #include "sys_fstream.h"
194e6869
 #include "generator.h"
b6eb15ba
 #include "random_source.h"
f757e35b
 
e064ffa9
 class tokens_ifc
cdf7fd74
 {
 public:
af3a4cd4
     using token_generator = std::function<std::string()>;
e064ffa9
     virtual ~tokens_ifc() {}
af3a4cd4
     virtual std::string token (const user &user) const
b65518d3
     {
b5e563ba
         return "";
3a7bcdbe
     }
a120158c
     virtual std::string generate_key() const
     {
b6eb15ba
         return "";
     }
8c62e61c
     virtual std::string ensure_key (const user &user) const
     {
         return "";
b6eb15ba
     }
decf9568
     virtual void save (const user &user, const std::string &token) const {}
9af49688
 };
3a7bcdbe
 
e064ffa9
 class tokens
b65518d3
 {
0e218820
 public:
e064ffa9
     typedef std::shared_ptr<tokens_ifc> delegate;
0e218820
 private:
     delegate delegate_;
 public:
e064ffa9
     tokens (delegate delegate) :
b65518d3
         delegate_ (delegate) {}
e064ffa9
     tokens() : tokens (
             delegate (new tokens_ifc)) {}
d4fb1155
     std::string generate_key () const
b6eb15ba
     {
         return delegate_->generate_key ();
     }
8c62e61c
     std::string ensure_key (const user &user) const
     {
         return delegate_->ensure_key (user);
3f7d4dd6
     }
af3a4cd4
     std::string token (const user &user) const
0e218820
     {
         return delegate_->token (user);
     }
decf9568
     void save (const user &user, const std::string &token) const
d10906ee
     {
decf9568
         return delegate_->save (user, token);
af3a4cd4
     }
8c62e61c
     static tokens create (const fstreams &fstreams,
b6eb15ba
                           const totp_generator &generator,
                           const random_source &rand);
3a7bcdbe
 };
 
7699d7ec
 #endif
a120158c