/*
 * Copyright (C) 2023 Uniontech Software Technology Co., Ltd.
 *
 * Author:     gongheng<gongheng@uniontech.com>
 *
 * Maintainer: gongheng<gongheng@uniontech.com>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#ifndef TPMWORK_H
#define TPMWORK_H

#include <QObject>

class QLibrary;

class TPMWork : public QObject
{
    Q_OBJECT
public:
    explicit TPMWork(QObject *parent = nullptr);
    ~TPMWork();
    bool checkTPMAvailable();
    bool getRandom(int size, QString &output);
    bool isSupportAlgo(const QString &algoName);

public slots:
    void slotDoEncrypt(const QString hashAlgo, const QString keyAlgo, const QString keyPin, const QString password);
    void slotDoDecrypt(const QString &keyPin);

signals:
    void sigEncryptFinished(bool result);
    void sigDecryptFinished(bool reuslt, const QString &password);

private:
    bool initTpm2(const QString hashAlgo, const QString keyAlgo, const QString keyPin);

private:
    QLibrary *tpmLib { nullptr };
};

#endif // TPMWORK_H
