mpwmanager.h 2.22 KB
Newer Older
Andrea Scarpino's avatar
Andrea Scarpino committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
/*
  The MIT License (MIT)

  Copyright (c) 2016 Andrea Scarpino <me@andreascarpino.it>

  Permission is hereby granted, free of charge, to any person obtaining a copy
  of this software and associated documentation files (the "Software"), to deal
  in the Software without restriction, including without limitation the rights
  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  copies of the Software, and to permit persons to whom the Software is
  furnished to do so, subject to the following conditions:

  The above copyright notice and this permission notice shall be included in all
  copies or substantial portions of the Software.

  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  SOFTWARE.
*/

#ifndef MPWMANAGER_H
#define MPWMANAGER_H

#include <QObject>

30 31 32 33 34
extern "C"
{
#include <mpw-algorithm.h>
}

Andrea Scarpino's avatar
Andrea Scarpino committed
35 36 37 38 39 40 41 42 43
class MPWManager : public QObject
{
    Q_OBJECT
public:
    enum PasswordType {
        Maximum, Long, Medium, Basic, Short, PIN, Name, Phrase
    };
    Q_ENUMS(PasswordType)

44 45 46 47 48
    enum AlgorithmVersion {
        V0, V1, V2, V3
    };
    Q_ENUMS(AlgorithmVersion)

Andrea Scarpino's avatar
Andrea Scarpino committed
49 50 51
    explicit MPWManager(QObject *parent = 0);
    virtual ~MPWManager();

52
    Q_INVOKABLE AlgorithmVersion getAlgorithmVersion() const;
Andrea Scarpino's avatar
Andrea Scarpino committed
53
    Q_INVOKABLE QString getName() const;
54 55 56 57
    Q_INVOKABLE void setAlgorithmVersion(AlgorithmVersion version);
    Q_INVOKABLE void setName(const QString &name);

    Q_INVOKABLE void generateMasterKey(const QString &name, const QString &password, AlgorithmVersion version);
Andrea Scarpino's avatar
Andrea Scarpino committed
58
    Q_INVOKABLE QString getPassword(const QString &site, PasswordType type, const uint counter) const;
Andrea Scarpino's avatar
Andrea Scarpino committed
59 60

private:
61 62 63
    MPAlgorithmVersion toMPAlgorithmVersion(AlgorithmVersion version) const;
    MPSiteType toMPSiteType(PasswordType type) const;

64
    QByteArray m_key;
Andrea Scarpino's avatar
Andrea Scarpino committed
65
    QString m_name;
66
    AlgorithmVersion m_algVersion;
Andrea Scarpino's avatar
Andrea Scarpino committed
67 68 69
};

#endif // MPWMANAGER_H