File indexing completed on 2024-04-28 05:50:08
0001 /* 0002 * SPDX-License-Identifier: GPL-3.0-or-later 0003 * SPDX-FileCopyrightText: 2020 Johan Ouwerkerk <jm.ouwerkerk@gmail.com> 0004 */ 0005 #ifndef MODEL_INPUT_H 0006 #define MODEL_INPUT_H 0007 0008 #include "../account/account.h" 0009 #include "../validators/countervalidator.h" 0010 #include "../validators/datetimevalidator.h" 0011 0012 #include <QDateTime> 0013 #include <QObject> 0014 #include <QString> 0015 0016 #include <optional> 0017 0018 namespace model 0019 { 0020 class AccountInput : public QObject 0021 { 0022 Q_OBJECT 0023 Q_PROPERTY(model::AccountInput::TokenType type READ type WRITE setType NOTIFY typeChanged) 0024 Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged) 0025 Q_PROPERTY(QString issuer READ issuer WRITE setIssuer NOTIFY issuerChanged) 0026 Q_PROPERTY(QString secret READ secret WRITE setSecret NOTIFY secretChanged) 0027 Q_PROPERTY(uint tokenLength READ tokenLength WRITE setTokenLength NOTIFY tokenLengthChanged) 0028 Q_PROPERTY(uint timeStep READ timeStep WRITE setTimeStep NOTIFY timeStepChanged) 0029 Q_PROPERTY(model::AccountInput::TOTPAlgorithm algorithm READ algorithm WRITE setAlgorithm NOTIFY algorithmChanged) 0030 Q_PROPERTY(QString epoch READ epoch WRITE setEpoch NOTIFY epochChanged) 0031 Q_PROPERTY(bool checksum READ checksum WRITE setChecksum NOTIFY checksumChanged) 0032 Q_PROPERTY(QString counter READ counter NOTIFY counterChanged) 0033 Q_PROPERTY(uint truncationOffset READ truncationOffset NOTIFY truncationChanged) 0034 Q_PROPERTY(bool fixedTruncation READ fixedTruncation NOTIFY truncationChanged) 0035 public: 0036 enum TOTPAlgorithm { 0037 Sha1, Sha256, Sha512 0038 }; 0039 Q_ENUM(TOTPAlgorithm) 0040 enum TokenType { 0041 Hotp, Totp 0042 }; 0043 Q_ENUM(TokenType) 0044 AccountInput(QObject *parent = nullptr); 0045 void createNewAccount(accounts::AccountStorage *storage) const; 0046 Q_INVOKABLE void reset(void); 0047 public: 0048 TokenType type(void) const; 0049 void setType(model::AccountInput::TokenType type); 0050 QString name(void) const; 0051 void setName(const QString &name); 0052 QString issuer(void) const; 0053 void setIssuer(const QString &issuer); 0054 QString secret(void) const; 0055 void setSecret(const QString &secret); 0056 uint tokenLength(void) const; 0057 void setTokenLength(uint tokenLength); 0058 uint timeStep(void) const; 0059 void setTimeStep(uint timeStep); 0060 TOTPAlgorithm algorithm(void) const; 0061 void setAlgorithm(model::AccountInput::TOTPAlgorithm algorithm); 0062 QString epoch(void) const; 0063 void setEpoch(const QString &epoch); 0064 bool checksum(void) const; 0065 void setChecksum(bool checksum); 0066 QString counter(void) const; 0067 void setCounter(quint64 counter); 0068 Q_INVOKABLE void setCounter(const QString &counter, validators::UnsignedLongValidator *validator); 0069 uint truncationOffset(void) const; 0070 bool fixedTruncation(void) const; 0071 Q_INVOKABLE void setTruncationOffset(uint truncationOffset); 0072 Q_INVOKABLE void setDynamicTruncation(void); 0073 Q_SIGNALS: 0074 void typeChanged(void); 0075 void nameChanged(void); 0076 void issuerChanged(void); 0077 void secretChanged(void); 0078 void tokenLengthChanged(void); 0079 void timeStepChanged(void); 0080 void algorithmChanged(void); 0081 void epochChanged(void); 0082 void checksumChanged(void); 0083 void counterChanged(void); 0084 void truncationChanged(void); 0085 private: 0086 TokenType m_type; 0087 QString m_name; 0088 QString m_issuer; 0089 QString m_secret; 0090 uint m_tokenLength; 0091 uint m_timeStep; 0092 TOTPAlgorithm m_algorithm; 0093 QString m_epoch; 0094 QDateTime m_epochValue; 0095 bool m_checksum; 0096 QString m_counter; 0097 quint64 m_counterValue; 0098 std::optional<uint> m_truncation; 0099 }; 0100 } 0101 0102 #endif