aboutsummaryrefslogtreecommitdiff
path: root/src/keyring.h
blob: 81d97fc3914f1a9e7f330b4794eef25303a257bf (plain)
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#pragma once

#include <QAbstractTableModel>
#include <QFont>
#include <QString>

#include "ext_packet.h"

// The sole reason I use a class here is because Qt demands it. At least, that's
// my impression after reading the documentation.
class KeyringModel : public QAbstractTableModel
{
  Q_OBJECT
public:
  explicit KeyringModel(QObject *parent = nullptr);
  int rowCount(const QModelIndex &parent = QModelIndex()) const override;
  int columnCount(const QModelIndex &parent = QModelIndex()) const override;
  QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
  QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;

  void load_keys(void);
  static constexpr int KeyIDRole = 0x0100;

private:
  struct KeyInfo
  {
    QByteArray id;
    QString name;
    QString bytes;
  };

  QVector<KeyInfo> m_keys;
};

enum class ResponseResult
{
  success,
  invalid_password,
  inaccessible_keyring,
  corrupted_entry,
  unsupported_version,
  derivation_failed,
  decryption_failed,
  bad_curve_point,
};

int keyring_initialize(void);
int generate_key(QStringView name, const QByteArray &password);
void delete_key(const QByteArray &key_id);
ResponseResult unlock_and_auth(QByteArrayView key_id, QByteArrayView password, QByteArrayView ephemeral_key, QByteArrayView username, AuthResponse &out);