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. */ |
55563eab | #ifndef GENERATOR_H_ #define GENERATOR_H_ #include <string> #include <functional> |
46cb80e7 | #include <sstream> #include <iomanip> |
cff139be | #include <cmath> |
9b03a29b | #include <ctime> |
c1080d50 | #include <iostream> |
9b03a29b | |
46cb80e7 | #include "sys_stdlib.h" |
9b03a29b | #include "sys_time.h" |
c1e18905 | #include "typealiases.h" |
55563eab | |
9b03a29b | int ipow (int base, int exp); time_t time_step (const time_t time, const int step); |
55563eab | |
9b03a29b | class token_generator_ifc |
23c0bd4d | { |
9b03a29b | public: |
40fd6c82 | virtual std::string generate_token (const octet_vector &key) const = 0; |
9b03a29b | }; |
23c0bd4d | |
6ab21073 | class totp_generator |
7d075ab4 | { |
c1080d50 | public: |
6ab21073 | using delegate = std::shared_ptr<token_generator_ifc>; |
75b15a68 | |
c1080d50 | private: |
6ab21073 | delegate delegate_; |
c1080d50 | public: |
40fd6c82 | std::string generate_token (const octet_vector &key) const |
c1080d50 | { return delegate_->generate_token (key); } |
6ab21073 | |
d0d6ce9f | totp_generator (delegate delegate_) : |
c1080d50 | delegate_ (delegate_) |
d0d6ce9f | {} |
47f1fe7f | |
2e93eae5 | totp_generator (const sys_time clock, |
6ab21073 | const int code_digits); |
9b03a29b | }; |
55563eab | #endif |
0d8b9a17 |